Guest User

Untitled

a guest
Apr 12th, 2023
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.36 KB | None | 0 0
  1. <?php
  2. /**
  3. * ../../ext/pok4/shop/ext.php
  4. *
  5. * @package default
  6. */
  7. namespace ext\pok4;
  8. use \PDO;
  9. use \ArrayIterator;
  10. if (count(get_included_files()) == 1) exit("Direct access not permitted."); //Don't edit
  11. require_once('ext/pok4/shop/stripe/init.php'); //stripe api library
  12.  
  13. //Your Extension Script
  14. class shop extends \App\Controllers\BaseController {
  15.  
  16.  
  17. public function __construct() {
  18. parent::__construct();
  19.  
  20.  
  21. /*EPAY API*/
  22. #DEMO: https://demo.epay.bg/
  23. #LIVE: https://www.epay.bg/
  24. $this->submit_url = 'https://demo.epay.bg/';
  25. # XXX Secret word with which merchant make CHECKSUM on the ENCODED packet
  26. $this->epay_secret = 'QHW3EPHF0AXEWBR0C7ZJVV658XUDRH0FXOB5FYZCN81B3U1IUSS7R61M7M1X1GFI';
  27. $this->epay_client = 'D188604865'; //Client ID
  28. /*END EPAY API*/
  29.  
  30. /*FB Comments API*/
  31. $this->fb_comments_enable = true; //set to false/true to off/on the comments
  32. $this->fb_appid = "157924284418157";
  33.  
  34. /*STRIPE API credentials*/
  35. $this->stripe_api_key = "pk_test_51Muxv1CWj0Ml57h8hw2j0f9OKaHgQMaeYFwZqxwt5k80W4CbAobIU1wfVrahEh6vnhcthyn29i74u4O8nQ6FjDs900CEUdJy2d";
  36. $this->stripe_secret_key = "sk_test_51Muxv1CWj0Ml57h86e3s20ahaNkrunwTb0bmf23Ja58BJSXVYUQpdCJrqHpxBQ39d36TggapEaRb9GIV7hWvJBcy00gcnXQwCg";
  37. }
  38.  
  39.  
  40. /*for total price calculation*/
  41. public function compute_multi($v1, $v2){
  42. return $v1*$v2;
  43. }
  44.  
  45. /*For EasyPay api*/
  46. public function hmac($algo,$data,$passwd){
  47. /* md5 and sha1 only */
  48. $algo=strtolower($algo);
  49. $p=array('md5'=>'H32','sha1'=>'H40');
  50. if(strlen($passwd)>64) $passwd=pack($p[$algo],$algo($passwd));
  51. if(strlen($passwd)<64) $passwd=str_pad($passwd,64,chr(0));
  52.  
  53. $ipad=substr($passwd,0,64) ^ str_repeat(chr(0x36),64);
  54. $opad=substr($passwd,0,64) ^ str_repeat(chr(0x5C),64);
  55.  
  56. return($algo($opad.pack($p[$algo],$algo($ipad.$data))));
  57. }
  58.  
  59.  
  60. public function ajax() {
  61.  
  62. //stripe api
  63. if(str_contains($_SERVER['REQUEST_URI'],'?stripe=1')) {
  64. // Set API key (secret)
  65. $stripe = new \Stripe\StripeClient($this->stripe_secret_key);
  66.  
  67. $response = array(
  68. 'status' => 0,
  69. 'error' => array(
  70. 'message' => 'Invalid Request!'
  71. )
  72. );
  73.  
  74. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  75. $input = file_get_contents('php://input');
  76. $request = json_decode($input);
  77. }
  78.  
  79. if (json_last_error() !== JSON_ERROR_NONE) {
  80. http_response_code(400);
  81. echo json_encode($response);
  82. exit;
  83. }
  84.  
  85. if(!empty($request->createCheckoutSession)){
  86.  
  87. //main things about products
  88. $get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$this->user_id."'");
  89. $arr = [];
  90. $arr2 = []; //holds price
  91. $arr3 = []; //holds quantity
  92. $price_type = "";//globalize
  93. while($row = $get->fetch(PDO::FETCH_ASSOC)) {
  94. $arr[] = $row['product_id'];
  95.  
  96. $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']."'");
  97. $row2 = $get_prod->fetch(PDO::FETCH_ASSOC);
  98. if($row2['product_promo_price'] > 0) {
  99. $arr2[] = $row2['product_promo_price'];
  100. } else {
  101. $arr2[] = $row2['product_price'];
  102. }
  103. $arr3[] = $row['product_quantity'];
  104. $price_type = $row2['product_price_type'];
  105. }
  106. $string = "";//globalize
  107. foreach($arr as $v) {
  108. $string .= "$v,";
  109. }
  110.  
  111. $total_price = array_sum(array_map("self::compute_multi", $arr2, $arr3));
  112. $product_ids = rtrim($string, ',');
  113.  
  114. // Convert product price to cent
  115. $stripeAmount = round($total_price*100, 2);
  116.  
  117. // Create new Checkout Session for the order
  118. try {
  119. $checkout_session = $stripe->checkout->sessions->create([
  120. 'line_items' => [[
  121. 'price_data' => [
  122. 'product_data' => [
  123. 'name' => 'Products IDS:('.$product_ids.')', //name of product
  124. 'metadata' => [
  125. 'pro_id' => ''.$product_ids.'' //product ids
  126. ]
  127. ],
  128. 'unit_amount' => $stripeAmount, //price amount
  129. 'currency' => ''.$price_type.'', //price type
  130. ],
  131. 'quantity' => 1
  132. ]],
  133. 'mode' => 'payment',
  134. 'success_url' => url().'/ajax/ext/pok4/shop?schecker=1&session_id={CHECKOUT_SESSION_ID}&user_id='.$this->user_id.'',
  135. 'cancel_url' => url().'/pages/cart?stripe_cancel',
  136. ]);
  137. } catch(Exception $e) {
  138. $api_error = $e->getMessage();
  139. }
  140.  
  141. if(empty($api_error) && $checkout_session){
  142. $response = array(
  143. 'status' => 1,
  144. 'message' => 'Checkout Session created successfully!',
  145. 'sessionId' => $checkout_session->id
  146. );
  147. }else{
  148. $response = array(
  149. 'status' => 0,
  150. 'error' => array(
  151. 'message' => 'Checkout Session creation failed! '.$api_error
  152. )
  153. );
  154. }
  155. } ;
  156. // Return response
  157. echo json_encode($response);
  158. return;
  159.  
  160. }
  161.  
  162. if(str_contains($_SERVER['REQUEST_URI'],'?schecker=1&session_id')) {
  163.  
  164. $payment_id = $statusMsg = '';
  165. $status = 'error';
  166.  
  167. // Check whether stripe checkout session is not empty
  168. if(!empty($_GET['session_id'])){
  169. $session_id = $_GET['session_id'];
  170. // Set API key
  171. $stripe = new \Stripe\StripeClient($this->stripe_secret_key);
  172.  
  173. // Fetch the Checkout Session to display the JSON result on the success page
  174. try {
  175. $checkout_session = $stripe->checkout->sessions->retrieve($session_id);
  176. } catch(Exception $e) {
  177. $api_error = $e->getMessage();
  178. }
  179.  
  180. if(empty($api_error) && $checkout_session){
  181. // Retrieve the details of a PaymentIntent
  182. try {
  183. $paymentIntent = $stripe->paymentIntents->retrieve($checkout_session->payment_intent);
  184. } catch (\Stripe\Exception\ApiErrorException $e) {
  185. $api_error = $e->getMessage();
  186. }
  187.  
  188. if(empty($api_error) && $paymentIntent){
  189. // Check whether the payment was successful
  190. if(!empty($paymentIntent) && $paymentIntent->status == 'succeeded'){
  191. $user_id = (int)$_GET['user_id'];
  192. $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");
  193.  
  194. //remove all products from basket when everything is ok
  195. $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
  196.  
  197. //location reload (header)
  198. header("Refresh:0; url=".url()."/pages/cart?stripe_succ");
  199. }else{
  200. $statusMsg = "Transaction has been failed!";
  201. }
  202. }else{
  203. $statusMsg = "Unable to fetch the transaction details! $api_error";
  204. }
  205. }else{
  206. $statusMsg = "Invalid Transaction! $api_error";
  207. }
  208. }else{
  209. $statusMsg = "Invalid Request!";
  210. }
  211. return;
  212. }
  213. //end stripe api
  214.  
  215.  
  216. //extension ajax calls
  217. if(is_ajax()) {
  218.  
  219. //set solved status
  220. if(isset($_POST['status_set']) && $this->is_admin) {
  221. $order_id = (int)$_POST['order_id'];
  222.  
  223. //get products ids by order id
  224. $get = $this->db->query("SELECT product_ids,pay_status FROM ".$this->argos_db_prefix."shop_pending_orders WHERE id='".$order_id."'");
  225. $row = $get->fetch(PDO::FETCH_ASSOC);
  226. $product_id = $row['product_ids'];
  227. $pay_status = $row['pay_status'];
  228. if($pay_status == 'Solved') {
  229. echo $this->lang['ext_shop_already_solved'];
  230. return;
  231. }
  232.  
  233. $strArr = explode(',', $product_id);
  234.  
  235. foreach ($strArr as $e) {
  236. $keyValue = explode('=>', $e);
  237. $product_id_s = $keyValue[0];
  238. $quantity = $keyValue[1];
  239. $this->db->query("UPDATE ".$this->argos_db_prefix."shop SET product_availability=product_availability-".$quantity." WHERE id='".$product_id_s."'");
  240. $this->db->query("UPDATE ".$this->argos_db_prefix."shop SET product_buy_count=product_buy_count+".$quantity." WHERE id='".$product_id_s."'");
  241. }
  242.  
  243. $this->db->query("UPDATE ".$this->argos_db_prefix."shop_pending_orders SET pay_status='Solved' WHERE id='".$order_id."'");
  244.  
  245. echo $this->lang['ext_shop_success'];
  246. return;
  247. }
  248.  
  249. //remove product from basket
  250. if(isset($_POST['removepid'])) {
  251. $userid = $this->user_id;
  252. $pid = (int)$_POST['productid'];
  253. $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$userid."' AND product_id='".$pid."'");
  254. return;
  255. }
  256.  
  257.  
  258. //form 1 (standart delivery - couriers)
  259. if(isset($_POST['form_1'])) {
  260. $phone = $_POST['your_phone'];
  261. $address = $_POST['delivery_address'];
  262. $name = $_POST['your_name'];
  263. $pay_status = 'Not payed';
  264. $method = $this->lang['ext_shop_delivery_method'];
  265. $user_id = $this->user_id;
  266.  
  267. //get products in basket
  268. $get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
  269. $arr = [];
  270. while($row = $get->fetch(PDO::FETCH_ASSOC)) {
  271. $arr[] = $row['product_id']. '=>'.$row['product_quantity'];
  272.  
  273. $get_prod = $this->db->query("SELECT product_price,product_promo_price FROM ".$this->argos_db_prefix."shop WHERE id='".$row['product_id']."'");
  274. $row2 = $get_prod->fetch(PDO::FETCH_ASSOC);
  275.  
  276. if($row2['product_promo_price'] > 0) {
  277. $arr2[] = $row2['product_promo_price'];
  278. } else {
  279. $arr2[] = $row2['product_price'];
  280. }
  281. $arr3[] = $row['product_quantity'];
  282. }
  283.  
  284. $total_price = array_sum(array_map("self::compute_multi", $arr2, $arr3));
  285.  
  286. $string = "";//globalize
  287. foreach($arr as $v) {
  288. $string .= "$v,";
  289. }
  290. $product_ids = rtrim($string, ',');
  291. $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(?,?,?,?,?,?,?,?,?)");
  292. $go->bindParam(1, $product_ids, PDO::PARAM_STR);
  293. $go->bindParam(2, $user_id, PDO::PARAM_STR);
  294. $go->bindParam(3, $address, PDO::PARAM_STR);
  295. $go->bindParam(4, $phone, PDO::PARAM_STR);
  296. $go->bindParam(5, $method, PDO::PARAM_STR);
  297. $go->bindParam(6, $pay_status, PDO::PARAM_STR);
  298. $go->bindParam(7, $name, PDO::PARAM_STR);
  299. $go->bindParam(8, time(),PDO::PARAM_STR);
  300. $go->bindParam(9, $total_price,PDO::PARAM_STR);
  301. $go->execute();
  302.  
  303. //remove all products from basket
  304. $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
  305.  
  306.  
  307. echo $this->lang['ext_shop_submit_succ'];
  308. return;
  309. }
  310.  
  311. //form 2 (standart delivery - couriers) / payed with current balance
  312. if(isset($_POST['form_2'])) {
  313. $phone = $_POST['your_phone'];
  314. $address = $_POST['delivery_address'];
  315. $name = $_POST['your_name'];
  316. $pay_status = 'Payed';
  317. $method = $this->lang['ext_shop_delivery_method_f2'];
  318. $user_id = $this->user_id;
  319.  
  320. //check if user have money to pay
  321. $check = $this->db->query("SELECT price FROM `".$this->forum_db."`.".$this->forum_db_prefix."_users where user_id='".$user_id."'");
  322. $row = $check->fetch(PDO::FETCH_ASSOC);
  323. $curr_balance = $row['price']; //phpbb3 column from users table
  324.  
  325. //get products in basket
  326. $get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
  327. $arr = [];
  328. $arr2 = []; //holds price
  329. $arr3 = []; //holds quantity
  330. while($row = $get->fetch(PDO::FETCH_ASSOC)) {
  331. $arr[] = $row['product_id']. '=>'.$row['product_quantity'];
  332.  
  333. $get_prod = $this->db->query("SELECT product_price,product_promo_price FROM ".$this->argos_db_prefix."shop WHERE id='".$row['product_id']."'");
  334. $row2 = $get_prod->fetch(PDO::FETCH_ASSOC);
  335.  
  336. if($row2['product_promo_price'] > 0) {
  337. $arr2[] = $row2['product_promo_price'];
  338. } else {
  339. $arr2[] = $row2['product_price'];
  340. }
  341. $arr3[] = $row['product_quantity'];
  342. }
  343. $string = "";//globalize
  344. foreach($arr as $v) {
  345. $string .= "$v,";
  346. }
  347.  
  348. $total_price = array_sum(array_map("self::compute_multi", $arr2, $arr3));
  349. if($curr_balance < $total_price) {
  350.  
  351. echo ''.$this->lang['ext_shop_you_dont_have'].' ('.$total_price.')';
  352. return;
  353. }
  354.  
  355. //remove price from user
  356. $check = $this->db->query("UPDATE `".$this->forum_db."`.".$this->forum_db_prefix."_users set price=price-$total_price where user_id='".$user_id."'");
  357.  
  358. $product_ids = rtrim($string, ',');
  359. $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(?,?,?,?,?,?,?,?,?)");
  360. $go->bindParam(1, $product_ids, PDO::PARAM_STR);
  361. $go->bindParam(2, $user_id, PDO::PARAM_STR);
  362. $go->bindParam(3, $address, PDO::PARAM_STR);
  363. $go->bindParam(4, $phone, PDO::PARAM_STR);
  364. $go->bindParam(5, $method, PDO::PARAM_STR);
  365. $go->bindParam(6, $pay_status, PDO::PARAM_STR);
  366. $go->bindParam(7, $name, PDO::PARAM_STR);
  367. $go->bindParam(8, time(),PDO::PARAM_STR);
  368. $go->bindParam(9, $total_price,PDO::PARAM_STR);
  369. $go->execute();
  370.  
  371. //remove all products from basket
  372. $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
  373.  
  374.  
  375. echo $this->lang['ext_shop_submit_succ'];
  376. return;
  377. }
  378.  
  379. //form 3 (standart delivery - couriers) / payed with epay
  380. if(isset($_POST['form_3'])) {
  381. $phone = $_POST['your_phone'];
  382. $address = $_POST['delivery_address'];
  383. $name = $_POST['your_name'];
  384. $pay_status = 'Not payed';
  385. $this->epay_invoice = mt_rand(10000, 10000000); // # XXX Invoice (facture number)
  386. $method = $this->lang['ext_shop_delivery_method_f3']." (".$this->epay_invoice.")";
  387. $user_id = $this->user_id;
  388.  
  389.  
  390. //get products in basket
  391. $get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
  392. $arr = [];
  393. $arr2 = []; //holds price
  394. $arr3 = []; //holds quantity
  395. while($row = $get->fetch(PDO::FETCH_ASSOC)) {
  396. $arr[] = $row['product_id']. '=>'.$row['product_quantity'];
  397.  
  398. $get_prod = $this->db->query("SELECT product_price,product_promo_price FROM ".$this->argos_db_prefix."shop WHERE id='".$row['product_id']."'");
  399. $row2 = $get_prod->fetch(PDO::FETCH_ASSOC);
  400. if($row2['product_promo_price'] > 0) {
  401. $arr2[] = $row2['product_promo_price'];
  402. } else {
  403. $arr2[] = $row2['product_price'];
  404. }
  405. $arr3[] = $row['product_quantity'];
  406. }
  407. $string = "";//globalize
  408. foreach($arr as $v) {
  409. $string .= "$v,";
  410. }
  411.  
  412. $total_price = array_sum(array_map("self::compute_multi", $arr2, $arr3));
  413.  
  414.  
  415. $product_ids = rtrim($string, ',');
  416. $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(?,?,?,?,?,?,?,?,?)");
  417. $go->bindParam(1, $product_ids, PDO::PARAM_STR);
  418. $go->bindParam(2, $user_id, PDO::PARAM_STR);
  419. $go->bindParam(3, $address, PDO::PARAM_STR);
  420. $go->bindParam(4, $phone, PDO::PARAM_STR);
  421. $go->bindParam(5, $method, PDO::PARAM_STR);
  422. $go->bindParam(6, $pay_status, PDO::PARAM_STR);
  423. $go->bindParam(7, $name, PDO::PARAM_STR);
  424. $go->bindParam(8, time(),PDO::PARAM_STR);
  425. $go->bindParam(9, $total_price,PDO::PARAM_STR);
  426. $go->execute();
  427.  
  428. //remove all products from basket
  429. $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
  430.  
  431.  
  432. /*EPAY API*/
  433. $this->exp_date = date('d.m.Y', strtotime('+1 day',time())); # XXX Expiration date (1 day)
  434. $this->descr = 'payment for product IDS: '.$product_ids.' (total price: '.$total_price.')';# XXX Description
  435. $this->URL_REDIRECT = url()."/pages/cart?easyp_success"; //redirect if success
  436. $this->CANCEL_URL = url()."/pages/cart?easyp_cancel"; //redirect if is cancel
  437.  
  438. $this->epay_data = <<<DATA
  439. MIN={$this->epay_client}
  440. INVOICE={$this->epay_invoice}
  441. AMOUNT={$total_price}
  442. EXP_TIME={$this->exp_date}
  443. DESCR={$this->descr}
  444. DATA;
  445. $this->ENCODED = base64_encode($this->epay_data);
  446. $this->CHECKSUM = $this->hmac('sha1', $this->ENCODED, $this->epay_secret); # XXX SHA-1 algorithm REQUIRED
  447. /*EPAY API*/
  448.  
  449. echo $this->lang['ext_shop_submit_succ'].'<br/>
  450. '.$this->lang['ext_shop_you_can_pay'].'<b>'.$this->epay_invoice.'</b> '.$this->lang['ext_shop_future'].')<br/>
  451. <form action="'.$this->submit_url.'" method="POST" target="_blank">
  452. <input type=hidden name="PAGE" value="paylogin">
  453. <input type=hidden name="ENCODED" value="'.$this->ENCODED.'">
  454. <input type=hidden name="CHECKSUM" value="'.$this->CHECKSUM.'">
  455. <input type=hidden name="URL_OK" value="'.$this->URL_REDIRECT.'">
  456. <input type=hidden name="URL_CANCEL" value="'.$this->CANCEL_URL.'">
  457. <INPUT type=image name="submit" src="ext/pok4/shop/template/img/logo-easypay-sm.svg" style="width: 50px;height:50px"/>
  458. </form>
  459. ';
  460. return;
  461. }
  462.  
  463. //form 4 (standart delivery - couriers) / payed with stripe
  464. if(isset($_POST['form_4'])) {
  465. $phone = $_POST['your_phone'];
  466. $address = $_POST['delivery_address'];
  467. $name = $_POST['your_name'];
  468. $pay_status = 'Not payed';
  469. $method = $this->lang['ext_shop_delivery_method_f4'];
  470. $user_id = $this->user_id;
  471.  
  472.  
  473. //get products in basket
  474. $get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
  475. $arr = [];
  476. $arr2 = []; //holds price
  477. $arr3 = []; //holds quantity
  478. while($row = $get->fetch(PDO::FETCH_ASSOC)) {
  479. $arr[] = $row['product_id']. '=>'.$row['product_quantity'];
  480.  
  481. $get_prod = $this->db->query("SELECT product_price,product_promo_price FROM ".$this->argos_db_prefix."shop WHERE id='".$row['product_id']."'");
  482. $row2 = $get_prod->fetch(PDO::FETCH_ASSOC);
  483. if($row2['product_promo_price'] > 0) {
  484. $arr2[] = $row2['product_promo_price'];
  485. } else {
  486. $arr2[] = $row2['product_price'];
  487. }
  488. $arr3[] = $row['product_quantity'];
  489. }
  490. $string = "";//globalize
  491. foreach($arr as $v) {
  492. $string .= "$v,";
  493. }
  494.  
  495. $total_price = array_sum(array_map("self::compute_multi", $arr2, $arr3));
  496.  
  497.  
  498. $product_ids = rtrim($string, ',');
  499. $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(?,?,?,?,?,?,?,?,?)");
  500. $go->bindParam(1, $product_ids, PDO::PARAM_STR);
  501. $go->bindParam(2, $user_id, PDO::PARAM_STR);
  502. $go->bindParam(3, $address, PDO::PARAM_STR);
  503. $go->bindParam(4, $phone, PDO::PARAM_STR);
  504. $go->bindParam(5, $method, PDO::PARAM_STR);
  505. $go->bindParam(6, $pay_status, PDO::PARAM_STR);
  506. $go->bindParam(7, $name, PDO::PARAM_STR);
  507. $go->bindParam(8, time(),PDO::PARAM_STR);
  508. $go->bindParam(9, $total_price,PDO::PARAM_STR);
  509. $go->execute();
  510.  
  511. echo $this->lang['ext_shop_submit_succ'].'<br/>
  512. '.$this->lang['ext_shop_you_can_pay2'].':<br/>
  513.  
  514. <div id="paymentResponse" class="hidden"></div>
  515. <button class="stripe-button" id="payButton">
  516. <div class="spinner hidden" id="spinner"></div>
  517. <div id="buttonText" style="background:url(ext/pok4/shop/template/img/stripe.svg) no-repeat;width: 50px;height:50px;">&nbsp;</div>
  518. </button>';
  519.  
  520. echo $this->m->render(file_get_contents("ext/pok4/shop/template/stripe.js"),[
  521. 'api_key'=>$this->stripe_api_key,
  522. 'c_base_url'=>url(),
  523. ]);
  524. return;
  525. }
  526.  
  527. //item quantity
  528. if(isset($_POST['set_quantity'])) {
  529. $item_quantity = $_POST['quantity'];
  530. $pid = (int)$_POST['product_id'];
  531.  
  532. //get availability
  533. $get = $this->db->query("SELECT product_availability FROM ".$this->argos_db_prefix."shop WHERE id='".$pid."'");
  534. $row = $get->fetch(PDO::FETCH_ASSOC);
  535.  
  536. //get current quantity
  537. $get2 = $this->db->query("SELECT product_quantity FROM ".$this->argos_db_prefix."shop_cart WHERE product_id='".$pid."'");
  538. $row2 = $get2->fetch(PDO::FETCH_ASSOC);
  539.  
  540. //check
  541. if($row['product_availability'] < $row2['product_quantity']) {
  542. return;
  543. }
  544.  
  545. if($item_quantity == '+1') {
  546. $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."'");
  547. } else {
  548. $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."'");
  549. }
  550.  
  551. //return current quantity
  552. $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."'");
  553. $row = $go->fetch(PDO::FETCH_ASSOC);
  554. if($row['product_quantity'] < 1) {
  555.  
  556. if($row['product_promo_price'] > 0) {
  557. echo json_encode(array('product_quantity' => 1,'product_price'=>$row['product_promo_price']));
  558. } else {
  559. echo json_encode(array('product_quantity' => 1,'product_price'=>$row['product_price']));
  560. }
  561. $this->db->query("UPDATE ".$this->argos_db_prefix."shop_cart SET product_quantity=1 WHERE product_id='".$pid."' AND user_id='".$this->user_id."'");
  562. return;
  563. }
  564.  
  565. if($row['product_promo_price'] > 0) {
  566. echo json_encode(array('product_quantity' => $row['product_quantity'],'product_price'=>$row['product_promo_price']));
  567. } else {
  568. echo json_encode(array('product_quantity' => $row['product_quantity'],'product_price'=>$row['product_price']));
  569. }
  570. return;
  571. }
  572.  
  573. //vote / rating system
  574. if(isset($_POST['vote'])) {
  575. $user_ip = $_SERVER['REMOTE_ADDR'];
  576.  
  577. $pid = (int)$_POST['productid'];
  578.  
  579. //check if user is voted
  580. $go = $this->db->query("SELECT user_ip FROM ".$this->argos_db_prefix."shop_rating WHERE product_id='".$pid."' AND user_ip='".$user_ip."'");
  581. if($go->rowCount() > 0) {
  582. echo $this->lang['ext_shop_already_voted'];
  583. return;
  584. }
  585.  
  586. $vote_type_now = $_POST['vote_type_now'];
  587. if($vote_type_now == "-1") {
  588. $this->db->query("UPDATE ".$this->argos_db_prefix."shop set product_rating = product_rating-1 WHERE id='".$pid."'");
  589. } else {
  590. $this->db->query("UPDATE ".$this->argos_db_prefix."shop set product_rating = product_rating+1 WHERE id='".$pid."'");
  591. }
  592.  
  593. //add user ip to db for already vote check
  594. $this->db->query("INSERT INTO ".$this->argos_db_prefix."shop_rating (product_id,user_ip) VALUES('".$pid."','".$user_ip."')");
  595.  
  596. //get current vote
  597. $go = $this->db->query("SELECT product_rating FROM ".$this->argos_db_prefix."shop WHERE id='".$pid."'");
  598. $row = $go->fetch(PDO::FETCH_ASSOC);
  599. echo $row['product_rating'];
  600.  
  601. return;
  602. }
  603.  
  604. //add to basket
  605. if(isset($_POST['addtobasket'])) {
  606.  
  607. if($this->is_anonymous) {
  608. echo $this->lang['ext_shop_please_login'];
  609. return;
  610. }
  611.  
  612. $pid = (int)$_POST['productid'];
  613. $user_id = $this->user_id;
  614.  
  615. //check availability
  616. $check = $this->db->query("SELECT product_availability FROM ".$this->argos_db_prefix."shop WHERE id='".$pid."'");
  617. $row = $check->fetch(PDO::FETCH_ASSOC);
  618. if($row['product_availability'] == 0) {
  619. echo $this->lang['ext_shop_not_in_stock'];
  620. return;
  621. }
  622.  
  623. //check if already exists
  624. $go = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."' AND product_id='".$pid."'");
  625. if($go->rowCount() > 0) {
  626. $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."'");
  627. } else {
  628. $this->db->query("INSERT INTO ".$this->argos_db_prefix."shop_cart (user_id,product_id,product_quantity) VALUES('".$user_id."','".$pid."','1')");
  629. }
  630.  
  631. echo $this->lang['ext_shop_added_to_basket'];
  632. return;
  633.  
  634. }
  635.  
  636. //delete product
  637. if(isset($_POST['delete_product_id'])) {
  638. $id = (int)$_POST['delete_product_id'];
  639.  
  640. //get product images
  641. $img = $this->db->query("SELECT product_images FROM ".$this->argos_db_prefix."shop WHERE id='".$id."'");
  642. $row = $img->fetch(PDO::FETCH_ASSOC);
  643. $imgs = $row['product_images'];
  644. $img_exp = explode(",",$imgs);
  645. foreach($img_exp as $v){
  646. //delete imgs
  647. unlink('ext/pok4/shop/product_images/'.$v);
  648. }
  649. $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop WHERE id='".$id."'");
  650. echo $this->lang['ext_shop_deleted'];
  651. return;
  652. }
  653.  
  654. //product edit
  655. if(isset($_POST['edit_form'])) {
  656. $id = (int)$_POST['product_id'];
  657. $product_title = $_POST['product_title'];
  658. $product_price = $_POST['product_price'];
  659. $product_promo_price = $_POST['product_promo_price'];
  660. $product_price_type = $_POST['product_price_type'];
  661. $product_explain = $_POST['product_explain'];
  662. $product_availability = $_POST['product_availability'];
  663.  
  664. //update db
  665. $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."'");
  666. $go->bindParam(1, $product_title, PDO::PARAM_STR);
  667. $go->bindParam(2, $product_price, PDO::PARAM_STR);
  668. $go->bindParam(3, $product_promo_price, PDO::PARAM_STR);
  669. $go->bindParam(4, $product_price_type, PDO::PARAM_STR);
  670. $go->bindParam(5, $product_explain, PDO::PARAM_STR);
  671. $go->bindParam(6, $product_availability, PDO::PARAM_STR);
  672. $go->execute();
  673. echo 'Success!';
  674. return;
  675. }
  676.  
  677. //delete cat
  678. if(isset($_POST['cat_id'])) {
  679. $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cats WHERE id='".$_POST['cat_id']."'");
  680. return;
  681. }
  682.  
  683. //submit new product
  684. 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'])) {
  685.  
  686. $arr_files = "";
  687. foreach($_FILES['file']['tmp_name'] as $key => $tmp_name)
  688. {
  689. if(empty($_FILES['file']['tmp_name'][$key])) {
  690. continue;
  691. }
  692.  
  693. $file_data = getimagesize($_FILES['file']['tmp_name'][$key]);
  694. if (is_array($file_data) && strpos($file_data['mime'], 'image') !== false) {
  695. $file_name = $key.$_FILES['file']['name'][$key];
  696. $file_size =$_FILES['file']['size'][$key];
  697. $file_tmp =$_FILES['file']['tmp_name'][$key];
  698. $file_type=$_FILES['file']['type'][$key];
  699. $arr_files .= time().$file_name.",";
  700. if(str_contains($file_name, ",")) {
  701. echo $this->lang['ext_shop_cannot_contain'];
  702. return;
  703. }
  704. move_uploaded_file($file_tmp,"ext/pok4/shop/product_images/".time().$file_name);
  705. }
  706. }
  707.  
  708. //add product to db
  709. $string = rtrim($arr_files,',');
  710. $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',?)");
  711. $go->bindParam(1, $_POST['product_title'], PDO::PARAM_STR);
  712. $go->bindParam(2, $_POST['product_price'], PDO::PARAM_STR);
  713. $go->bindParam(3, $_POST['product_promo_price'], PDO::PARAM_STR);
  714. $go->bindParam(4, $_POST['product_explain'], PDO::PARAM_STR);
  715. $go->bindParam(5, $_POST['product_cat'], PDO::PARAM_STR);
  716. $go->bindParam(6, $string, PDO::PARAM_STR);
  717. $go->bindParam(7, $_POST['product_availability'], PDO::PARAM_STR);
  718. $go->execute();
  719.  
  720. echo $this->lang['ext_shop_success'];
  721. return;
  722. } else {
  723. echo $this->lang['ext_shop_missing_input'];
  724. }
  725.  
  726. }
  727. }
  728.  
  729.  
  730.  
  731. public function admin_form() {
  732. if (strpos($_SERVER['REQUEST_URI'], 'apage=shop_config&add_cat=1') !== false) {
  733. return $this->add_cat();
  734. }
  735.  
  736. if (strpos($_SERVER['REQUEST_URI'], 'apage=shop_config&add_product=1') !== false) {
  737. return $this->add_product();
  738. }
  739.  
  740. if (strpos($_SERVER['REQUEST_URI'], 'apage=shop_config&product_list=1') !== false) {
  741. return $this->product_list();
  742. }
  743.  
  744. if (strpos($_SERVER['REQUEST_URI'], 'apage=shop_config&queue_list=1') !== false) {
  745. return $this->queue_list();
  746. }
  747.  
  748. if (strpos($_SERVER['REQUEST_URI'], 'apage=shop_config') !== false) {
  749.  
  750. return $this->m->render(file_get_contents("ext/pok4/shop/template/shop_admin.html"),[
  751. 'current_url'=>url().$_SERVER['REQUEST_URI'],
  752. //lang definitions
  753. 'ext_shop_admin_expl'=>$this->lang['ext_shop_admin_expl'],
  754. 'ext_shop_add_category'=>$this->lang['ext_shop_add_category'],
  755. 'ext_shop_add_product'=>$this->lang['ext_shop_add_product'],
  756. 'ext_shop_product_list'=>$this->lang['ext_shop_product_list'],
  757. 'ext_shop_queue_list'=>$this->lang['ext_shop_queue_list'],
  758. ]);
  759. }
  760.  
  761. }
  762.  
  763.  
  764. public function queue_list() { //ACP
  765.  
  766. $results = $this->db->query("SELECT COUNT(`id`) FROM ".$this->argos_db_prefix."shop_pending_orders order by id DESC")->fetchColumn();
  767. if($results > 0) {
  768. $pagination = pagination($results, [
  769. 'get_vars' => [
  770. 'apage' => $_GET['apage'].'&queue_list=1',
  771. ],
  772. 'per_page' => 15, //how many results per page
  773. 'per_side' => 3,
  774. 'get_name' => 'page'
  775. ]);
  776. } else {
  777. //reset this variables to 0, to prevent errors
  778. $pagination['limit']['first'] = 0;
  779. $pagination['limit']['second'] = 0;
  780. }
  781. $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']}");
  782. $all_orders = []; //globalize
  783. if ($get_results->rowCount() > 0) {
  784. $order_appear = true; //we found results
  785. while ($row=$get_results->fetch(PDO::FETCH_ASSOC)) {
  786. $product_ids = $row['product_ids'];
  787. $order_date = date("d.m.Y, H:i",$row['date']);
  788. $user_id = $row['user_id'];
  789. $order_id = $row['id'];
  790.  
  791. //get username by userid
  792. $get_name = $this->db->query("SELECT username FROM `".$this->forum_db."`.".$this->forum_db_prefix."_users where user_id='".$user_id."'");
  793. $row2=$get_name->fetch(PDO::FETCH_ASSOC);
  794. $username = $row2['username'];
  795.  
  796. //other things
  797. $status = $row['pay_status'];
  798. $phone = $row['phone'];
  799. $address = $row['address'];
  800. $method = $row['method_for_pay'];
  801. $name = $row['full_name'];
  802. $total_price = $row['total_price'];
  803.  
  804. $status_color = "black";//globalize
  805. if($status =='Solved') {
  806. $status_color = "green";
  807. }
  808.  
  809.  
  810. $strArr = explode(',', $product_ids);
  811. $string ="";//globalize
  812. foreach ($strArr as $e) {
  813.  
  814. //re-format the details about products ids and quantity
  815. $keyValue = explode('=>', $e);
  816. $string .= '<a target="_blank" href="' .url().'/pages/shop/?view_item='. $keyValue[0] . '">' . $keyValue[0] . '</a> => '.$keyValue[1].' '.$this->lang['ext_shop_quantity'].',';
  817.  
  818. }
  819. $products_renew = rtrim($string,',');
  820.  
  821. $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];
  822. }
  823. } else {
  824. $order_appear = false; //we not found results
  825. }
  826.  
  827. return $this->m->render(file_get_contents("ext/pok4/shop/template/queue_list_admin.html"), [
  828. //variables
  829. 'all_orders'=> new ArrayIterator($all_orders),
  830. 'ext_shop_pagination'=>($order_appear) ? $pagination['output'] : '',
  831.  
  832. //lang definitions
  833. 'ext_shop_no_results_2'=>$this->lang['ext_shop_no_results_2'],
  834. 'ext_shop_if_you'=>$this->lang['ext_shop_if_you'],
  835. 'ext_shop_are_you'=>$this->lang['ext_shop_are_you'],
  836. 'ext_shop_fullname'=>$this->lang['ext_shop_fullname'],
  837. 'ext_shop_total_price'=>$this->lang['ext_shop_total_price'],
  838. 'ext_shop_user'=>$this->lang['ext_shop_user'],
  839. 'ext_shop_just_date'=>$this->lang['ext_shop_just_date'],
  840. 'ext_shop_status'=>$this->lang['ext_shop_status'],
  841. 'ext_shop_set'=>$this->lang['ext_shop_set'],
  842. 'ext_shop_view_details'=>$this->lang['ext_shop_view_details'],
  843. 'ext_shop_canceled'=>$this->lang['ext_shop_canceled'],
  844. 'ext_shop_mark_as'=>$this->lang['ext_shop_mark_as'],
  845. 'ext_shop_address'=>$this->lang['ext_shop_address'],
  846. 'ext_shop_phone'=>$this->lang['ext_shop_phone'],
  847. 'ext_shop_method'=>$this->lang['ext_shop_method'],
  848. 'ext_shop_just_products'=>$this->lang['ext_shop_just_products'],
  849.  
  850. ]);
  851. }
  852.  
  853. public function add_cat() { //ACP
  854.  
  855. //get all active cats
  856. $dbh = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cats");
  857. if($dbh->rowCount() > 0) {
  858. $cats = "";//globalize
  859. while($row = $dbh->fetch(PDO::FETCH_ASSOC)) {
  860. $cats .= "<a href='#' class='delete_cat' data-catid='".$row['id']."'>".$row['product_cat']." [DELETE]</a><br/>";
  861. }
  862. } else {
  863. $cats = $this->lang['ext_shop_no_cats'];
  864. }
  865.  
  866. return $this->m->render(file_get_contents("ext/pok4/shop/template/add_cat_admin.html"),[
  867. 'all_shop_cats'=>$cats,
  868.  
  869. //lang definitions
  870. 'ext_shop_submit'=>$this->lang['ext_shop_submit'],
  871. 'ext_shop_product_cat_name'=>$this->lang['ext_shop_product_cat_name'],
  872. 'ext_shop_current_cats'=>$this->lang['ext_shop_current_cats'],
  873. ]).$this->submit_new_cat();
  874. }
  875.  
  876. public function submit_new_cat() { //ACP
  877. //submit new cat
  878. if(isset($_POST['submit_product'])) {
  879.  
  880. $cat_name = $_POST['cat_name'];
  881. $go = $this->db->prepare("INSERT INTO ".$this->argos_db_prefix."shop_cats (product_cat) VALUES(?)");
  882. $go->bindParam(1, $cat_name, PDO::PARAM_STR);
  883. $go->execute();
  884. return '<div class="alert alert-success">'.$this->lang['ext_shop_success'].'!</div>';
  885. }
  886. }
  887.  
  888. public function add_product() { //ACP
  889.  
  890. //get all active cats
  891. $dbh = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cats");
  892. if($dbh->rowCount() > 0) {
  893. $cats = "";//globalize
  894. while($row = $dbh->fetch(PDO::FETCH_ASSOC)) {
  895. $cats .= "<option value='".$row['product_cat']."'>".$row['product_cat']."</option>";
  896. }
  897. } else {
  898. $cats = "<option disabled>".$this->lang['ext_shop_no_cats']."</option>";
  899. }
  900. return $this->m->render(file_get_contents("ext/pok4/shop/template/add_product_admin.html"),[
  901. 'all_active_cats'=>$cats,
  902. //lang definitions
  903. 'ext_shop_price_type'=>$this->lang['ext_shop_price_type'],
  904. 'ext_shop_product_cat'=>$this->lang['ext_shop_product_cat'],
  905. 'ext_shop_product_price'=>$this->lang['ext_shop_product_price'],
  906. 'ext_shop_availability'=>$this->lang['ext_shop_availability'],
  907. 'ext_shop_promo_p_price'=>$this->lang['ext_shop_promo_p_price'],
  908. 'ext_shop_submit'=>$this->lang['ext_shop_submit'],
  909. ]);
  910. }
  911.  
  912. public function product_list() { //ACP
  913. //get all products with pagination
  914. $results = $this->db->query("SELECT COUNT(`id`) FROM ".$this->argos_db_prefix."shop order by product_date DESC")->fetchColumn();
  915. if($results > 0) {
  916. $pagination = pagination($results, [
  917. 'get_vars' => [
  918. 'apage' => $_GET['apage'].'&product_list=1',
  919. ],
  920. 'per_page' => 15, //how many results per page
  921. 'per_side' => 3,
  922. 'get_name' => 'page'
  923. ]);
  924. } else {
  925. //reset this variables to 0, to prevent errors
  926. $pagination['limit']['first'] = 0;
  927. $pagination['limit']['second'] = 0;
  928. }
  929. $get_results = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop order by product_date DESC LIMIT {$pagination['limit']['first']}, {$pagination['limit']['second']}");
  930. $all_products = []; //globalize
  931. if ($get_results->rowCount() > 0) {
  932. $product_appear = true; //we found results
  933. while ($row=$get_results->fetch(PDO::FETCH_ASSOC)) {
  934. $product_title = $row['product_title'];
  935. $product_date = date("d.m.Y, H:i",$row['product_date']);
  936. $product_id = $row['id'];
  937. $product_price = $row['product_price'];
  938. $product_explain = $row["product_explain"];
  939. $product_price_type = $row['product_price_type'];
  940. $product_promo_price = $row['product_promo_price'];
  941. if($product_promo_price > 0) {
  942. $product_is_promo = true;
  943. } else {
  944. $product_is_promo = false;
  945. }
  946.  
  947. //get images
  948. $product_images = $row['product_images'];
  949. $product_availability = $row['product_availability'];
  950. $all_imgs = explode(",",$product_images);
  951. $print_imgs = "";//globalize
  952. foreach($all_imgs as $v) {
  953. $print_imgs .= "<img style='display:inline-block;width:160px;height:160px;' src='".url()."/ext/pok4/shop/product_images/$v' alt=''/>";
  954. }
  955. $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];
  956. }
  957. } else {
  958. $product_appear = false; //we not found results
  959. }
  960.  
  961. return $this->m->render(file_get_contents("ext/pok4/shop/template/product_list_admin.html"), [
  962. //variables
  963. 'all_products'=> new ArrayIterator($all_products),
  964. 'ext_shop_pagination'=>($product_appear) ? $pagination['output'] : '',
  965.  
  966. //lang definitions
  967. 'ext_shop_product_title'=>$this->lang['ext_shop_product_title'],
  968. 'ext_shop_product_price'=>$this->lang['ext_shop_product_price'],
  969. 'ext_shop_price_type'=>$this->lang['ext_shop_price_type'],
  970. 'ext_shop_product_date'=>$this->lang['ext_shop_product_date'],
  971. 'ext_shop_promo_price'=>$this->lang['ext_shop_promo_price'],
  972. 'ext_shop_descr'=>$this->lang['ext_shop_descr'],
  973. 'ext_shop_availability'=>$this->lang['ext_shop_availability'],
  974. 'ext_shop_product_images'=>$this->lang['ext_shop_product_images'],
  975. 'ext_shop_close'=>$this->lang['ext_shop_close'],
  976. 'ext_shop_submit'=>$this->lang['ext_shop_submit'],
  977. 'ext_shop_no_results_2'=>$this->lang['ext_shop_no_results_2'],
  978. ]);
  979. }
  980.  
  981. public function js_acp() {
  982. return $this->m->render(file_get_contents("ext/pok4/shop/template/js_admin.js"));
  983. }
  984.  
  985. public function custom_page() {
  986.  
  987. //ORDER BY numeric
  988. $order_by = "";//globalize
  989. if(isset($_COOKIE['argos_shop_order'])) {
  990. switch($_COOKIE['argos_shop_order']) {
  991. case 'price_desc': {
  992. $order_by = "product_price DESC";
  993. break;
  994. }
  995. case 'price_asc': {
  996. $order_by = "product_price ASC";
  997. break;
  998. }
  999. case 'rating_desc': {
  1000. $order_by = "product_rating DESC";
  1001. break;
  1002. }
  1003. case 'rating_asc': {
  1004. $order_by = "product_rating ASC";
  1005. break;
  1006. }
  1007. case 'buy_desc': {
  1008. $order_by = "product_buy_count DESC";
  1009. break;
  1010. }
  1011. case 'buy_asc': {
  1012. $order_by = "product_buy_count ASC";
  1013. break;
  1014. }
  1015. case 'viewc_desc': {
  1016. $order_by = "product_view_count DESC";
  1017. break;
  1018. }
  1019. case 'view_asc': {
  1020. $order_by = "product_view_count ASC";
  1021. break;
  1022. }
  1023. }
  1024. } else {
  1025. $order_by = "product_date DESC";
  1026. }
  1027.  
  1028. //order by cat (game)
  1029. $where = "";//globalize
  1030. if(isset($_COOKIE['argos_shop_order2'])) {
  1031. $where = "WHERE product_cat='". filter_var(truncate_chars($_COOKIE['argos_shop_order2'],25,''), FILTER_SANITIZE_STRING)."'";
  1032. }
  1033. if(empty($_COOKIE['argos_shop_order2'])) {
  1034. $where ="";
  1035. }
  1036.  
  1037. $results = $this->db->query("SELECT COUNT(`id`) FROM ".$this->argos_db_prefix."shop $where order by $order_by")->fetchColumn();
  1038. if($results > 0) {
  1039. $pagination = pagination($results, [
  1040. 'per_page' => 15, //how many results per page
  1041. 'per_side' => 3,
  1042. 'get_name' => 'page'
  1043. ]);
  1044. } else {
  1045. //reset this variables to 0, to prevent errors
  1046. $pagination['limit']['first'] = 0;
  1047. $pagination['limit']['second'] = 0;
  1048. }
  1049. $get_results = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop $where order by $order_by LIMIT {$pagination['limit']['first']}, {$pagination['limit']['second']}");
  1050. $all_products = []; //globalize
  1051. if ($get_results->rowCount() > 0) {
  1052. $product_appear = true; //we found results
  1053. while ($row=$get_results->fetch(PDO::FETCH_ASSOC)) {
  1054. $product_title = $row['product_title'];
  1055. $product_id = $row['id'];
  1056. $product_price = $row['product_price'];
  1057. $product_price_type = $row['product_price_type'];
  1058. $product_promo_price = $row['product_promo_price'];
  1059. if($product_promo_price > 0) {
  1060. $product_is_promo = true;
  1061. } else {
  1062. $product_is_promo = false;
  1063. }
  1064.  
  1065. //get first img
  1066. $product_images = $row['product_images'];
  1067. $all_imgs = explode(",",$product_images);
  1068. $first_img = $all_imgs[0];
  1069. $product_cat = $row['product_cat'];
  1070. $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];
  1071. }
  1072. } else {
  1073. $product_appear = false; //we not found results
  1074. }
  1075.  
  1076. //get available categories
  1077. $cats = "";//globalize
  1078. $cats_get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cats");
  1079. if($cats_get->rowCount() > 0) {
  1080. while ($row=$cats_get->fetch(PDO::FETCH_ASSOC)) {
  1081. $cats .= "<option value='".$row['product_cat']."'>".$row['product_cat']."</option>";
  1082. }
  1083. }
  1084.  
  1085. //product view
  1086. if(isset($_GET['view_item'])) {
  1087. return $this->product_view();
  1088.  
  1089. } else { //product list view
  1090. //print everything to shop_list.html
  1091. return $this->m->render(file_get_contents("ext/pok4/shop/template/shop_list.html"),[
  1092. //variables
  1093. 'all_products'=> new ArrayIterator($all_products),
  1094. 'ext_shop_pagination'=>($product_appear) ? $pagination['output'] : '',
  1095. 'not_view_product'=>!isset($_GET['view_item']),
  1096. 'sort_by_cat'=>$cats,
  1097.  
  1098. //lang definitions
  1099. 'ext_shop_select_option'=>$this->lang['ext_shop_select_option'],
  1100. 'ext_shop_view'=>$this->lang['ext_shop_view'],
  1101. 'ext_shop_no_results'=>$this->lang['ext_shop_no_results'],
  1102. 'ext_shop_price_asc'=>$this->lang['ext_shop_price_asc'],
  1103. 'ext_shop_price_desc'=>$this->lang['ext_shop_price_desc'],
  1104. 'ext_shop_rating_asc'=>$this->lang['ext_shop_rating_asc'],
  1105. 'ext_shop_rating_desc'=>$this->lang['ext_shop_rating_desc'],
  1106. 'ext_shop_buyc_asc'=>$this->lang['ext_shop_buyc_asc'],
  1107. 'ext_shop_buyc_desc'=>$this->lang['ext_shop_buyc_desc'],
  1108. 'ext_shop_viewc_asc'=>$this->lang['ext_shop_viewc_asc'],
  1109. 'ext_shop_viewc_desc'=>$this->lang['ext_shop_viewc_desc'],
  1110. 'ext_shop_sort_by1'=>$this->lang['ext_shop_sort_by1'],
  1111. 'ext_shop_sort_by2'=>$this->lang['ext_shop_sort_by2'],
  1112. ]);
  1113. }
  1114. }
  1115.  
  1116. public function product_view() {
  1117.  
  1118. $product_id = (int)$_GET['view_item'];
  1119.  
  1120. //update view count
  1121. $this->db->query("UPDATE ".$this->argos_db_prefix."shop SET product_view_count=product_view_count+1 WHERE id='".$product_id."'");
  1122.  
  1123. //proceed
  1124. $get_results = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop WHERE id='".$product_id."'");
  1125. $is_items_found = "";
  1126. if ($get_results->rowCount() > 0) {
  1127. $is_items_found = true;
  1128. $row=$get_results->fetch(PDO::FETCH_ASSOC);
  1129.  
  1130. $product_title = $row['product_title'] ?? '';
  1131. $product_id = $row['id'] ?? '';
  1132. $product_price = $row['product_price'] ?? '';
  1133. $product_price_type = $row['product_price_type'] ?? '';
  1134. $product_promo_price = $row['product_promo_price'] ?? '';
  1135. $product_rating = $row['product_rating'] ?? 0;
  1136. $product_buy_count = $row['product_buy_count'] ?? 0;
  1137. $product_availability = $row['product_availability'];
  1138. $product_view_count = $row['product_view_count'] ?? 0;
  1139. if($product_promo_price > 0) {
  1140. $product_is_promo = true;
  1141. } else {
  1142. $product_is_promo = false;
  1143. }
  1144.  
  1145. $product_explain = $row['product_explain'] ?? '';
  1146. $product_images = $row['product_images'] ?? '';
  1147. $product_imgs_arr = explode(",",$product_images);
  1148. $arr_img_products = "";//globalize
  1149. foreach ($product_imgs_arr as $v) {
  1150. $arr_img_products .= "<div><img src='ext/pok4/shop/product_images/$v' data-lightbox='lightbox_imgs' style='width:100%;height:160px;' alt=''/></div>";
  1151. }
  1152.  
  1153. } else {
  1154. $is_items_found = false;
  1155. }
  1156. return $this->m->render(file_get_contents("ext/pok4/shop/template/product_view.html"),[
  1157. 'is_items_found'=>$is_items_found,
  1158. 'product_title'=>$product_title,
  1159. 'product_id'=>$product_id,
  1160. 'product_price'=>$product_price,
  1161. 'product_price_type'=>$product_price_type,
  1162. 'product_promo_price'=>$product_promo_price,
  1163. 'product_explain'=>$product_explain,
  1164. 'product_images'=>$arr_img_products,
  1165. 'product_is_promo'=>$product_is_promo,
  1166. 'product_rating'=>$product_rating,
  1167. 'product_buy_count'=>$product_buy_count,
  1168. 'product_availability'=>$product_availability,
  1169. 'product_view_count'=>$product_view_count,
  1170. 'fb_app_id'=>$this->fb_appid,
  1171. 'fb_comm_enable'=>$this->fb_comments_enable,
  1172. 'c_base_url'=>url(),
  1173.  
  1174. //lang definitions
  1175. 'ext_shop_descr'=>$this->lang['ext_shop_descr'],
  1176. 'ext_shop_details'=>$this->lang['ext_shop_details'],
  1177. 'ext_shop_buy_count'=>$this->lang['ext_shop_buy_count'],
  1178. 'ext_shop_view_count'=>$this->lang['ext_shop_view_count'],
  1179. 'ext_shop_availability'=>$this->lang['ext_shop_availability'],
  1180. 'ext_shop_rating'=>$this->lang['ext_shop_rating'],
  1181. 'ext_shop_price'=>$this->lang['ext_shop_price'],
  1182. 'ext_shop_add_to_cart'=>$this->lang['ext_shop_add_to_cart'],
  1183. 'ext_shop_view_basket'=>$this->lang['ext_shop_view_basket'],
  1184. 'ext_shop_item_not_found'=>$this->lang['ext_shop_item_not_found'],
  1185. ]);
  1186.  
  1187. }
  1188.  
  1189. public function js_front() {
  1190. return $this->m->render(file_get_contents("ext/pok4/shop/template/js_front.js")); //shop
  1191. }
  1192.  
  1193. public function js_front2() {
  1194. return $this->m->render(file_get_contents("ext/pok4/shop/template/js_front2.js"),[
  1195. 'ext_shop_js_explain1'=>$this->lang['ext_shop_js_explain1'],
  1196. 'ext_shop_js_explain2'=>$this->lang['ext_shop_js_explain2'],
  1197. ]); //shop_cart
  1198. }
  1199.  
  1200.  
  1201. public function custom_page2() {
  1202.  
  1203. //get all products
  1204. $user_id = $this->user_id;
  1205. $all_products = []; //globalize
  1206. $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."'");
  1207. if($get_all->rowCount() > 0) {
  1208. while ($row=$get_all->fetch(PDO::FETCH_ASSOC)) {
  1209. $product_title = $row['product_title'];
  1210. $product_quantity = $row['product_quantity'] ?? 1;
  1211. $product_price = $row['product_price'] * $product_quantity;
  1212. $product_promo_price = $row['product_promo_price'];
  1213. if(!empty($product_promo_price) OR $product_promo_price > 0) {
  1214. $product_price = $row['product_promo_price'] * $product_quantity;
  1215. }
  1216. $product_price_type = $row['product_price_type'];
  1217. if($product_price_type =='BGN') {
  1218. $flag = '<img src="https://flagcdn.com/16x12/bg.png" alt="flag"/>';
  1219. } else {
  1220. $flag = '<img src="https://flagcdn.com/16x12/eu.png" alt="flag"/>';
  1221. }
  1222. $pid = $row['product_id'];
  1223. $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];
  1224. }
  1225. }
  1226.  
  1227. //get user balance
  1228. $get = $this->db->query("SELECT price FROM `".$this->forum_db."`.".$this->forum_db_prefix."_users where user_id='".$user_id."'");
  1229. $row2=$get->fetch(PDO::FETCH_ASSOC);
  1230.  
  1231. return $this->m->render(file_get_contents("ext/pok4/shop/template/shopping_cart.html"),[
  1232. 'all_products'=> new ArrayIterator($all_products),
  1233. 'no_products'=>empty($all_products) ? $this->lang['ext_shop_no_results_2'] : '',
  1234. 'c_base_url'=>url(),
  1235. 'current_balance'=>$row2['price'],
  1236.  
  1237. //lang definitions
  1238. 'ext_shop_product_title'=>$this->lang['ext_shop_product_title'],
  1239. 'ext_shop_product_price'=>$this->lang['ext_shop_product_price'],
  1240. 'ext_shop_price_type'=>$this->lang['ext_shop_price_type'],
  1241. 'ext_shop_product_qty'=>$this->lang['ext_shop_product_qty'],
  1242. 'ext_shop_remove'=>$this->lang['ext_shop_remove'],
  1243. 'ext_shop_total_price'=>$this->lang['ext_shop_total_price'],
  1244. 'ext_shop_goto'=>$this->lang['ext_shop_goto'],
  1245. 'ext_shop_order'=>$this->lang['ext_shop_order'],
  1246. 'ext_shop_choose_method'=>$this->lang['ext_shop_choose_method'],
  1247. 'ext_shop_choose_option'=>$this->lang['ext_shop_choose_option'],
  1248. 'ext_shop_on_delivery'=>$this->lang['ext_shop_on_delivery'],
  1249. 'ext_shop_on_curr_balance'=>$this->lang['ext_shop_on_curr_balance'],
  1250. 'ext_shop_curr_balance'=>$this->lang['ext_shop_curr_balance'],
  1251. 'ext_shop_with'=>$this->lang['ext_shop_with'],
  1252. 'ext_shop_fullname'=>$this->lang['ext_shop_fullname'],
  1253. 'ext_shop_delivery_explain'=>$this->lang['ext_shop_delivery_explain'],
  1254. 'ext_shop_your_phone'=>$this->lang['ext_shop_your_phone'],
  1255. 'ext_shop_submit'=>$this->lang['ext_shop_submit'],
  1256. 'ext_shop_now'=>$this->lang['ext_shop_now'],
  1257. ]);
  1258. }
  1259.  
  1260. public function load() {
  1261.  
  1262. if (strpos($_SERVER['REQUEST_URI'], '/pages/shop') !== false) {
  1263. $this->dispatcher->emit('core_event_inside_custom_w_menu', [$this->custom_page()]);
  1264. $this->dispatcher->emit('core_event_head_append', ['<link rel="stylesheet" href="ext/pok4/shop/template/css.css">']);
  1265. $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>']);
  1266. $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>']);
  1267. $this->dispatcher->emit('core_event_head_append', ['<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css">']);
  1268. $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">']);
  1269. $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">']);
  1270. $this->dispatcher->emit('core_event_inside_head_ready_front', [$this->js_front()]);
  1271. }
  1272.  
  1273. if (strpos($_SERVER['REQUEST_URI'], '/pages/cart') !== false) {
  1274. $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>']);
  1275. $this->dispatcher->emit('core_event_inside_custom_w_menu', [$this->custom_page2()]);
  1276. $this->dispatcher->emit('core_event_inside_head_ready_front', [$this->js_front2()]);
  1277. $this->dispatcher->emit('core_event_head_append', ['<script src="https://js.stripe.com/v3/"></script>']);
  1278. }
  1279.  
  1280. //admin area
  1281. $this->dispatcher->emit('core_admin_event_custom_pages_ext', [$this->admin_form()]);
  1282. $this->dispatcher->emit('core_admin_event_ext_pages', ['<li><a href="custom_pages_ext.php?apage=shop_config">Shop Configuration</a></li>']);
  1283. $this->dispatcher->emit('core_admin_event_inside_script_tag', [$this->js_acp()]);
  1284.  
  1285. }
  1286.  
  1287.  
  1288. };
  1289.  
  1290.  
  1291. $load_ext = new shop;
  1292. $load_ext->load();
  1293.  
Add Comment
Please, Sign In to add comment