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;
  27. $settings = $db->getSettings();
  28. //This must be add to re-connection with database.
  29. require('includes/config.inc.php');
  30. /*
  31. The service id should also be cast to an int,
  32. or checked if it's numeric before used in the WHERE clause... otherwise an SQL error is possible currently.
  33. If it's not an int (or if it's 0 after casting) redirect to the shop page.
  34. */
  35. $service_id = intval($_REQUEST['service_id']);
  36. if ($service_id <= 0){
  37. $view->refresh("home.php?m=simple-billing&p=buy");
  38. return;
  39. }
  40. // Query for Selected service info.
  41. $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;
  42. $result_service = $db->resultQuery($qry_service);
  43. $row_service = $result_service[0];
  44. //Compiling info about invoice to create an invoice order.
  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(isset($service_id)) $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. global $view;
  103. if( isset( $_POST["add_to_cart"] ) )
  104. {
  105. if( isset( $_SESSION['CART'] ) )
  106. {
  107. $i = count( $_SESSION['CART'] );
  108. $i++;
  109. }
  110. else
  111. {
  112. $i = 0;
  113. }
  114. $_SESSION['CART'][$i] = array( "cart_id" => $i,
  115. "service_id" => $service_id,
  116. "home_name" => $home_name,
  117. "ip" => $ip_id,
  118. "max_players" => $max_players,
  119. "qty" => $qty,
  120. "invoice_duration" => $invoice_duration,
  121. "price" => $price,
  122. "remote_control_password" => $remote_control_password,
  123. "ftp_password" => $ftp_password,
  124. "tax_amount" => $tax_amount,
  125. "currency" => $currency,
  126. "paid" => 0);
  127. echo '<meta http-equiv="refresh" content="0;url=?m=simple-billing&amp;p=cart">';
  128. }
  129. }
  130. ?>