cart.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <?php
  2. function saveOrderToDb($user_id,$service_id,$home_name,$ip,$max_players,$qty,$invoice_duration,$price,$remote_control_password,$ftp_password,$cart_id,$home_id = "0",$extended = "0"){
  3. global $db;
  4. $fields['user_id'] = $user_id;
  5. $fields['service_id'] = $service_id;
  6. $fields['home_name'] = $home_name;
  7. $fields['ip'] = $ip;
  8. $fields['max_players'] = $max_players;
  9. $fields['qty'] = $qty;
  10. $fields['invoice_duration'] = $invoice_duration;
  11. $fields['price'] = $price;
  12. $fields['remote_control_password'] = $remote_control_password;
  13. $fields['ftp_password'] = $ftp_password;
  14. $fields['cart_id'] = $cart_id;
  15. $fields['home_id'] = $home_id;
  16. $fields['extended'] = $extended;
  17. return $db->resultInsertId( 'billing_orders', $fields );
  18. }
  19. function assignOrdersToCart($user_id,$tax_amount,$currency){
  20. global $db;
  21. $fields['user_id'] = $user_id;
  22. $fields['paid'] = '0';
  23. $fields['tax_amount'] = $tax_amount;
  24. $fields['currency'] = $currency;
  25. return $db->resultInsertId( 'billing_carts', $fields );
  26. }
  27. function exec_ogp_module()
  28. {
  29. error_reporting(E_ALL);
  30. global $db,$view,$settings;
  31. $user_id = $_SESSION['user_id'];
  32. if( isset( $_POST["buy"] ) or isset( $_POST["pay_paypal"] ) or isset( $_POST["pay_paygol"] ) or isset( $_POST["pay_skrill"] ) or isset( $_POST["pay_robokassa"] ) )
  33. {
  34. if( isset( $_SESSION['CART'] ) )
  35. {
  36. $orders = $_SESSION['CART'];
  37. // Fill The Cart on DB
  38. $cart_id = assignOrdersToCart($user_id,$settings['tax_amount'],$settings['currency']);
  39. foreach($orders as $order)
  40. {
  41. $service_id = $order['service_id'];
  42. $home_name = $order['home_name'];
  43. $ip = $order['ip'];
  44. $max_players = $order['max_players'];
  45. $qty = $order['qty'];
  46. $invoice_duration = $order['invoice_duration'];
  47. $price = $order['price'];
  48. $remote_control_password = $order['remote_control_password'];
  49. $ftp_password = $order['ftp_password'];
  50. //Save order to DB
  51. saveOrderToDb($user_id,$service_id,$home_name,$ip,$max_players,$qty,$invoice_duration,$price,$remote_control_password,$ftp_password,$cart_id);
  52. }
  53. // Remove Cart From Session
  54. unset($_SESSION['CART']);
  55. }
  56. else
  57. {
  58. $cart_id = $_POST['cart_id'];
  59. }
  60. if ( !empty( $cart_id ) and isset( $_POST["pay_paypal"] ) and $settings['paypal'] == "1" )
  61. {
  62. echo '<meta http-equiv="refresh" content="0;url=home.php?m=simple-billing&p=paypal&cart_id='.$cart_id.'" >';
  63. }
  64. elseif ( !empty( $cart_id ) and isset( $_POST["pay_paygol"] ) and $settings['paygol'] == "1" )
  65. {
  66. echo '<meta http-equiv="refresh" content="0;url=home.php?m=simple-billing&p=paygol&cart_id='.$cart_id.'" >';
  67. }
  68. elseif ( !empty( $cart_id ) and isset( $_POST["pay_skrill"] ) and $settings['skrill'] == "1" )
  69. {
  70. echo '<meta http-equiv="refresh" content="0;url=home.php?m=simple-billing&p=skrill&cart_id='.$cart_id.'" >';
  71. }
  72. elseif ( !empty( $cart_id ) and isset( $_POST["pay_robokassa"] ) and $settings['robokassa'] == "1" )
  73. {
  74. echo '<meta http-equiv="refresh" content="0;url=home.php?m=simple-billing&p=robokassa&cart_id='.$cart_id.'" >';
  75. }
  76. }
  77. if( isset( $_POST["extend"] ) or isset( $_POST["extend_and_pay_paypal"] ) or isset( $_POST["extend_and_pay_paygol"] ) or isset( $_POST["extend_and_pay_skrill"] ) or isset( $_POST["extend_and_pay_robokassa"] ) )
  78. {
  79. $orders = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXbilling_orders WHERE order_id=".$_POST['order_id']);
  80. // Fill The Cart on DB
  81. $cart_id = assignOrdersToCart($user_id,$settings['tax_amount'],$settings['currency']);
  82. foreach($orders as $order)
  83. {
  84. $service_id = $order['service_id'];
  85. $home_name = $order['home_name'];
  86. $ip = $order['ip'];
  87. $max_players = $order['max_players'];
  88. $qty = $_POST['qty'];
  89. $invoice_duration = $_POST['invoice_duration'];
  90. $remote_control_password = $order['remote_control_password'];
  91. $ftp_password = $order['ftp_password'];
  92. $home_id = $order['home_id'];
  93. $services = $db->resultQuery( "SELECT *
  94. FROM OGP_DB_PREFIXbilling_services
  95. WHERE service_id=".$service_id );
  96. $service = $services[0];
  97. //Calculating Price
  98. switch ($_POST['invoice_duration'])
  99. {
  100. case "hour":
  101. $price_slot = $service['price_hourly'];
  102. break;
  103. case "month":
  104. $price_slot = $service['price_monthly'];
  105. break;
  106. case "year":
  107. $price_slot = $service['price_year']*12;
  108. break;
  109. }
  110. $price = $max_players*$price_slot*$_POST['qty'];
  111. //Save order to DB
  112. $order_id = saveOrderToDb($user_id,$service_id,$home_name,$ip,$max_players,$qty,$invoice_duration,$price,$remote_control_password,$ftp_password,$cart_id,$home_id,"1");
  113. //Change the old order expiration to -2 so it can not be extended, since there is a new order managing the same game home.
  114. $db->query( "UPDATE OGP_DB_PREFIXbilling_orders
  115. SET end_date=-2
  116. WHERE order_id=".$_POST['order_id']);
  117. }
  118. if ( !empty( $cart_id ) and isset( $_POST["extend_and_pay_paypal"] ) and $settings['paypal'] == "1" )
  119. {
  120. echo '<meta http-equiv="refresh" content="0;url=home.php?m=simple-billing&p=paypal&cart_id='.$cart_id.'" >';
  121. }
  122. elseif ( !empty( $cart_id ) and isset( $_POST["extend_and_pay_paygol"] ) and $settings['paygol'] == "1" )
  123. {
  124. echo '<meta http-equiv="refresh" content="0;url=home.php?m=simple-billing&p=paygol&cart_id='.$cart_id.'" >';
  125. }
  126. elseif ( !empty( $cart_id ) and isset( $_POST["extend_and_pay_skrill"] ) and $settings['skrill'] == "1" )
  127. {
  128. echo '<meta http-equiv="refresh" content="0;url=home.php?m=simple-billing&p=skrill&cart_id='.$cart_id.'" >';
  129. }
  130. elseif ( !empty( $cart_id ) and isset( $_POST["extend_and_pay_robokassa"] ) and $settings['robokassa'] == "1" )
  131. {
  132. echo '<meta http-equiv="refresh" content="0;url=home.php?m=simple-billing&p=robokassa&cart_id='.$cart_id.'" >';
  133. }
  134. }
  135. if(isset($_POST['remove']))
  136. {
  137. $cart_id = $_POST['cart_id'];
  138. if( isset( $_SESSION['CART'][$cart_id] ) )
  139. {
  140. unset($_SESSION['CART'][$cart_id]);
  141. }
  142. $order_id = $_POST['order_id'];
  143. $db->query( "DELETE FROM OGP_DB_PREFIXbilling_orders WHERE order_id=".$order_id );
  144. $orders_in_cart = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXbilling_orders WHERE cart_id=".$cart_id );
  145. if( !$orders_in_cart )
  146. {
  147. $db->query( "DELETE FROM OGP_DB_PREFIXbilling_carts WHERE cart_id=".$cart_id );
  148. }
  149. }
  150. ?>
  151. <style>
  152. h4 {
  153. width:250px;
  154. height:25px;
  155. background:#f5f5f5;
  156. border-top-style:solid;
  157. border-top-color:#afafaf;
  158. border-top-width:1px;
  159. border-style: solid;
  160. border-color: #CFCFCF;
  161. border-width: 1px;
  162. padding-top:8px;
  163. text-align: center;
  164. font-family:"Trebuchet MS";
  165. }
  166. </style>
  167. <h2><?php print_lang("your_cart");?></h2>
  168. <?php
  169. if( isset($_SESSION['CART']) and !empty($_SESSION['CART']) )
  170. {
  171. $carts[0] = $_SESSION['CART'];
  172. }
  173. $user_carts = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXbilling_carts WHERE user_id=".$user_id );
  174. if( $user_carts >=1 )
  175. {
  176. foreach ( $user_carts as $user_cart )
  177. {
  178. $cart_id = $user_cart['cart_id'];
  179. $carts[$cart_id] = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXbilling_carts AS cart JOIN
  180. OGP_DB_PREFIXbilling_orders AS orders
  181. ON orders.cart_id=cart.cart_id
  182. WHERE cart.cart_id=".$cart_id );
  183. }
  184. }
  185. if( empty( $carts ) )
  186. {
  187. print_failure( get_lang('there_are_no_orders_in_cart') );
  188. ?>
  189. <a href="?m=simple-billing&p=shop"><?php print_lang('back'); ?></a>
  190. <?php
  191. return;
  192. }
  193. foreach ( $carts as $orders )
  194. {
  195. if( !empty( $orders ) )
  196. {
  197. ?>
  198. <center>
  199. <table style="width:95%;text-align:center;" class="center">
  200. <tr>
  201. <th>
  202. CART ID</th>
  203. <th>
  204. <?php print_lang("order_desc");?></th>
  205. <th>
  206. <?php print_lang("price");?>
  207. </th>
  208. <?php
  209. if(isset($orders[0]['paid']) and $orders[0]['paid'] == 3)
  210. {
  211. ?>
  212. <th>
  213. <?php print_lang('expiration_date');?>
  214. </th>
  215. <th>
  216. <?php print_lang('removal_date');?>
  217. </th>
  218. <?php
  219. }
  220. ?>
  221. <th>
  222. </th>
  223. </tr>
  224. <?php
  225. $subtotal = 0;
  226. foreach($orders as $order)
  227. {
  228. if ( $order['qty'] > 1 )
  229. $order['invoice_duration'] = $order['invoice_duration']."s";
  230. $subtotal += $order['price'];
  231. ?>
  232. <tr class="tr">
  233. <td>
  234. <?php
  235. echo "<b>".$order['cart_id']."</b>";
  236. ?>
  237. </td>
  238. <td>
  239. <?php
  240. echo "<b>".$order['home_name']."</b> [".$order['qty']." ".get_lang($order['invoice_duration']).", ".$order['max_players']." ".get_lang('slots')."]";
  241. ?>
  242. </td>
  243. <td>
  244. <?php
  245. echo $order['price'].$order['currency'];
  246. ?>
  247. </td>
  248. <?php
  249. if($order['paid'] == 0)
  250. {
  251. ?>
  252. <td>
  253. <form method="post" action="">
  254. <input type="hidden" name="cart_id" value="<?php echo $order['cart_id'];?>">
  255. <input type="hidden" name="order_id" value="<?php echo @$order['order_id'];?>">
  256. <input type="submit" name="remove" value="<?php print_lang("remove_from_cart");?>">
  257. </form>
  258. </td><?php
  259. }
  260. elseif($order['paid'] == 3)
  261. {
  262. $warning_end_date = $order['end_date'] < date('YmdHi') ? "<b style='color:red;'>".get_lang('expired')."</b>" : "";
  263. $warning_finish_date = $order['finish_date'] < date('YmdHi') ? "<b style='color:red;'>".get_lang('removed')."</b>" : "";
  264. $warning_finish_date = ($order['end_date'] == '-2' and $order['finish_date'] != '-2') ? "&nbsp;<b style='color:green;'>".get_lang('extended')."</b>":$warning_finish_date;
  265. $end_date = new DateTime($order['end_date']);
  266. $formated_end_date = ($order['end_date'] != '-1' and $order['end_date'] != '-2') ? $end_date->format('d/m/Y H:i') : "";
  267. $finish_date = new DateTime($order['finish_date']);
  268. $formated_finish_date = $order['finish_date'] != '-2' ? $finish_date->format('d/m/Y H:i') : "";
  269. ?>
  270. <td>
  271. <?php echo "$formated_end_date$warning_end_date";?>
  272. </td>
  273. <td>
  274. <?php echo "$formated_finish_date$warning_finish_date";?>
  275. </td>
  276. <?php
  277. }
  278. if( isset( $order['end_date'] ) and $order['end_date'] == "-1" )
  279. {
  280. ?>
  281. <td>
  282. <form method="post" action="">
  283. <input type="hidden" name="cart_id" value="<?php echo $order['cart_id'];?>">
  284. <input type="hidden" name="order_id" value="<?php echo $order['order_id'];?>">
  285. <select name="qty">
  286. <?php
  287. $qty=1;
  288. while($qty<=12)
  289. {
  290. echo "<option value='$qty'>$qty</option>";
  291. $qty++;
  292. }
  293. ?>
  294. </select>
  295. <select name="invoice_duration">
  296. <?php
  297. if( $settings['hourly'] == 1) echo '<option value="hour">'.get_lang('hours').'</option>';
  298. if( $settings['monthly'] == 1) echo '<option value="month">'.get_lang('months').'</option>';
  299. if( $settings['annually'] == 1) echo '<option value="year">'.get_lang('years').'</option>';
  300. ?>
  301. </select>
  302. <input type="submit" name="extend" value="<?php print_lang("extend");?>">
  303. <?php
  304. if($settings['paypal'] == "1")
  305. echo '<input name="extend_and_pay_paypal" type="submit" value="'.get_lang("extend")." ".get_lang("and")." ".get_lang_f("pay_from", get_lang('paypal')).'">';
  306. if($settings['paygol'] == "1")
  307. echo '<input name="extend_and_pay_paygol" type="submit" value="'.get_lang("extend")." ".get_lang("and")." ".get_lang_f("pay_from", get_lang('paygol')).'">';
  308. if($settings['skrill'] == "1")
  309. echo '<input name="extend_and_pay_skrill" type="submit" value="'.get_lang("extend")." ".get_lang("and")." ".get_lang_f("pay_from", get_lang('skrill')).'">';
  310. if($settings['robokassa'] == "1")
  311. echo '<input name="extend_and_pay_robokassa" type="submit" value="'.get_lang("extend")." ".get_lang("and")." ".get_lang_f("pay_from", get_lang('robokassa')).'">';
  312. ?>
  313. </form>
  314. </td><?php
  315. }
  316. ?>
  317. </tr><?php
  318. }
  319. ?>
  320. </table>
  321. <table style="width:95%;text-align:left;" class="center">
  322. <tr>
  323. <td>
  324. <?php print_lang("subtotal");?></td>
  325. <td>
  326. <?php
  327. echo $subtotal.$order['currency'];?>
  328. </td>
  329. </tr>
  330. <tr>
  331. <td>
  332. <?php print_lang("tax");?></td>
  333. <td>
  334. <?php echo $order['tax_amount'];?>%
  335. </td>
  336. </tr>
  337. <tr>
  338. <td>
  339. <?php print_lang("total");?>
  340. </td>
  341. <td>
  342. <?php
  343. $total = $subtotal+($order['tax_amount']/100*$subtotal);
  344. echo number_format( $total , 2 ).$order['currency'];
  345. ?>
  346. </td>
  347. <td>
  348. <?php
  349. if($order['paid'] == 1)
  350. {
  351. ?>
  352. <form method="post" action="home.php?m=simple-billing&p=create_servers">
  353. <input type="hidden" name="cart_id" value="<?php echo $order['cart_id'];?>">
  354. <?php
  355. if($order['extended'] == "1")
  356. {
  357. ?>
  358. <input name="enable_server" type="submit" value="<?php print_lang("enable_server");?>">
  359. <?php
  360. }
  361. else
  362. {
  363. ?>
  364. <input name="create_server" type="submit" value="<?php print_lang("create_server");?>">
  365. <?php
  366. }
  367. ?>
  368. </form>
  369. <?php
  370. }
  371. elseif($order['paid'] == 2)
  372. {
  373. echo get_lang_f("payment_is_pending_of_approval");
  374. }
  375. elseif($order['paid'] == 3)
  376. {
  377. ?>
  378. <form method="post" action="?m=simple-billing&p=bill">
  379. <input type="hidden" name="cart_id" value="<?php echo $order['cart_id'];?>">
  380. <input name="paid" type="submit" value="<?php print_lang("see_invoice");?>">
  381. </form>
  382. <?php
  383. }
  384. else
  385. {
  386. ?>
  387. <form method="post" action="">
  388. <input type="hidden" name="cart_id" value="<?php echo $order['cart_id'];?>">
  389. <input name="buy" type="submit" value="<?php print_lang("buy");?>">
  390. <?php
  391. if($settings['paypal'] == "1")
  392. echo '<input name="pay_paypal" type="submit" value="'.get_lang_f("pay_from", get_lang('paypal')).'">';
  393. if($settings['paygol'] == "1")
  394. echo '<input name="pay_paygol" type="submit" value="'.get_lang_f("pay_from", get_lang('paygol')).'">';
  395. if($settings['skrill'] == "1")
  396. echo '<input name="pay_skrill" type="submit" value="'.get_lang_f("pay_from", get_lang('skrill')).'">';
  397. if($settings['robokassa'] == "1")
  398. echo '<input name="pay_robokassa" type="submit" value="'.get_lang_f("pay_from", get_lang('robokassa')).'">';
  399. ?>
  400. </form>
  401. <?php
  402. }
  403. ?>
  404. </form>
  405. </td>
  406. </tr>
  407. </table>
  408. </center>
  409. <?php
  410. }
  411. }
  412. ?>
  413. <a href="?m=simple-billing&p=shop"><?php print_lang('back'); ?></a>
  414. <?php
  415. }
  416. ?>