add_to_cart.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2017 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. function exec_ogp_module()
  25. {
  26. global $db ,$view;
  27. $settings = $db->getSettings();
  28. //The service id should also be cast to an int.
  29. $service_id = intval($_REQUEST['service_id']);
  30. // Query for Selected service info.
  31. $qry_service = "SELECT DISTINCT service_id, home_cfg_id, mod_cfg_id, service_name, remote_server_id, slot_max_qty, slot_min_qty, price_hourly, price_monthly, price_year, description, img_url FROM OGP_DB_PREFIXbilling_services WHERE service_id=".$service_id;
  32. $result_service = $db->resultQuery($qry_service);
  33. $row_service = $result_service[0];
  34. //Compiling info about invoice to create an invoice order.
  35. /*
  36. Check if it's numeric before used in the WHERE clause... otherwise an SQL error is possible currently.
  37. If it's not an int (or if it's 0 after casting and or not vaild service) redirect to the shop page.
  38. */
  39. if ($service_id <= 0 || $result_service === false){
  40. $view->refresh("home.php?m=simple-billing&p=shop");
  41. return;
  42. }
  43. // remote server value
  44. $remote_server_id = $row_service['remote_server_id'];
  45. // request ogp user to create a home path.
  46. $r_server = $db->getRemoteServer($remote_server_id);
  47. $ogp_user = $r_server['ogp_user'];
  48. // request the user name and the game name to generate a game home name.
  49. $home_name = $_POST['home_name'];
  50. //Calculating Price
  51. if ($_POST['invoice_duration'] == "hour")
  52. {
  53. $price_slot=$row_service['price_hourly'];
  54. }
  55. elseif ($_POST['invoice_duration'] == "month")
  56. {
  57. $price_slot=$row_service['price_monthly'];
  58. }
  59. elseif ($_POST['invoice_duration'] == "year")
  60. {
  61. $price_slot=$row_service['price_year']*12;
  62. }
  63. else
  64. {
  65. $price_slot=$row_service['price_monthly'];
  66. }
  67. //Game Server Values
  68. $ip_id = $_POST['ip_id'];
  69. $ip = $db->getIpById($ip_id);
  70. $max_players = $_POST['max_players'];
  71. $qty = $_POST['qty'];
  72. $invoice_duration = $_POST['invoice_duration'];
  73. $user_id = $_SESSION['user_id'];
  74. $remote_control_password = $_POST['remote_control_password'];
  75. $ftp_password = $_POST['ftp_password'];
  76. $tax_amount = $settings['tax_amount'];
  77. $currency = $settings['currency'];
  78. /*
  79. Cast $_REQUEST['service_id'] to an int and then check if its value is higher than 0 before using it in the WHERE clause.
  80. Checking if it's higher than 0 because if it's a non-numeric value, after casting it to an int it'll be 0.
  81. */
  82. if($service_id !== 0) $where_service_id = " WHERE service_id=".$service_id; else $where_service_id = "";
  83. $qry_services = "SELECT * FROM OGP_DB_PREFIXbilling_services".$where_service_id;
  84. $services = $db->resultQuery($qry_services);
  85. foreach ($services as $key => $row) {
  86. if($max_players < $row['slot_min_qty'] || $qty < 1){
  87. $max_players = $row['slot_min_qty'];
  88. $qty = 1;
  89. }
  90. /*
  91. An extra check added for the inverse: check max_players against slot_max_qty.
  92. It would be good to do in the event someone is only selling a max of 16 slots per server.
  93. */
  94. elseif ($max_players > $row['slot_max_qty'])
  95. {
  96. $max_players = $row['slot_max_qty'];
  97. }
  98. }
  99. $price = $max_players*$price_slot*$qty;
  100. if( isset( $_POST["add_to_cart"] ) )
  101. {
  102. if( isset( $_SESSION['CART'] ) )
  103. {
  104. $i = count( $_SESSION['CART'] );
  105. $i++;
  106. }
  107. else
  108. {
  109. $i = 0;
  110. }
  111. $_SESSION['CART'][$i] = array( "cart_id" => $i,
  112. "service_id" => $service_id,
  113. "home_name" => $home_name,
  114. "ip" => $ip_id,
  115. "max_players" => $max_players,
  116. "qty" => $qty,
  117. "invoice_duration" => $invoice_duration,
  118. "price" => $price,
  119. "remote_control_password" => $remote_control_password,
  120. "ftp_password" => $ftp_password,
  121. "tax_amount" => $tax_amount,
  122. "currency" => $currency,
  123. "paid" => 0);
  124. echo '<meta http-equiv="refresh" content="0;url=?m=simple-billing&amp;p=cart">';
  125. }
  126. }
  127. ?>