add_to_cart.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2010 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. //This must be add to re-connection with database.
  29. require('includes/config.inc.php');
  30. //The service id should also be cast to an int.
  31. $service_id = intval($_REQUEST['service_id']);
  32. // Query for Selected service info.
  33. $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 ".$table_prefix."billing_services WHERE service_id=".$service_id;
  34. $result_service = $db->resultQuery($qry_service);
  35. $row_service = $result_service[0];
  36. //Compiling info about invoice to create an invoice order.
  37. /*
  38. Check if it's numeric before used in the WHERE clause... otherwise an SQL error is possible currently.
  39. If it's not an int (or if it's 0 after casting and or not vaild service) redirect to the shop page.
  40. */
  41. if ($service_id <= 0 || $result_service === false){
  42. $view->refresh("home.php?m=simple-billing&p=shop");
  43. return;
  44. }
  45. // remote server value
  46. $remote_server_id = $row_service['remote_server_id'];
  47. // request ogp user to create a home path.
  48. $r_server = $db->getRemoteServer($remote_server_id);
  49. $ogp_user = $r_server['ogp_user'];
  50. // request the user name and the game name to generate a game home name.
  51. $home_name = $_POST['home_name'];
  52. //Calculating Price
  53. if ($_POST['invoice_duration'] == "hour")
  54. {
  55. $price_slot=$row_service['price_hourly'];
  56. }
  57. elseif ($_POST['invoice_duration'] == "month")
  58. {
  59. $price_slot=$row_service['price_monthly'];
  60. }
  61. elseif ($_POST['invoice_duration'] == "year")
  62. {
  63. $price_slot=$row_service['price_year']*12;
  64. }
  65. else
  66. {
  67. $price_slot=$row_service['price_monthly'];
  68. }
  69. //Game Server Values
  70. $ip_id = $_POST['ip_id'];
  71. $ip = $db->getIpById($ip_id);
  72. $max_players = $_POST['max_players'];
  73. $qty = $_POST['qty'];
  74. $invoice_duration = $_POST['invoice_duration'];
  75. $user_id = $_SESSION['user_id'];
  76. $remote_control_password = $_POST['remote_control_password'];
  77. $ftp_password = $_POST['ftp_password'];
  78. $tax_amount = $settings['tax_amount'];
  79. $currency = $settings['currency'];
  80. /*
  81. Cast $_REQUEST['service_id'] to an int and then check if its value is higher than 0 before using it in the WHERE clause.
  82. 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.
  83. */
  84. if($service_id !== 0) $where_service_id = " WHERE service_id=".$service_id; else $where_service_id = "";
  85. $qry_services = "SELECT * FROM OGP_DB_PREFIXbilling_services".$where_service_id;
  86. $services = $db->resultQuery($qry_services);
  87. foreach ($services as $key => $row) {
  88. if($max_players < $row['slot_min_qty'] || $qty < 1){
  89. $max_players = $row['slot_min_qty'];
  90. $qty = 1;
  91. }
  92. /*
  93. An extra check added for the inverse: check max_players against slot_max_qty.
  94. It would be good to do in the event someone is only selling a max of 16 slots per server.
  95. */
  96. elseif ($max_players > $row['slot_max_qty'])
  97. {
  98. $max_players = $row['slot_max_qty'];
  99. }
  100. }
  101. $price = $max_players*$price_slot*$qty;
  102. if( isset( $_POST["add_to_cart"] ) )
  103. {
  104. if( isset( $_SESSION['CART'] ) )
  105. {
  106. $i = count( $_SESSION['CART'] );
  107. $i++;
  108. }
  109. else
  110. {
  111. $i = 0;
  112. }
  113. $_SESSION['CART'][$i] = array( "cart_id" => $i,
  114. "service_id" => $service_id,
  115. "home_name" => $home_name,
  116. "ip" => $ip_id,
  117. "max_players" => $max_players,
  118. "qty" => $qty,
  119. "invoice_duration" => $invoice_duration,
  120. "price" => $price,
  121. "remote_control_password" => $remote_control_password,
  122. "ftp_password" => $ftp_password,
  123. "tax_amount" => $tax_amount,
  124. "currency" => $currency,
  125. "paid" => 0);
  126. echo '<meta http-equiv="refresh" content="0;url=?m=simple-billing&amp;p=cart">';
  127. }
  128. }
  129. ?>