PageRenderTime 69ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/content/ajax/_stats_load.php

https://gitlab.com/Etern4l/BitcoinDice
PHP | 238 lines | 207 code | 25 blank | 6 comment | 32 complexity | f5f3ec3db29d4f32267392c77acd0741 MD5 | raw file
  1. <?php
  2. /*
  3. * © BitcoinDice
  4. */
  5. header('X-Frame-Options: DENY');
  6. if (empty($_GET['con'])) exit();
  7. $included=true;
  8. include '../../inc/db-conf.php';
  9. include '../../inc/functions.php';
  10. $settings=mysql_fetch_array(mysql_query("SELECT * FROM `system` LIMIT 1"));
  11. $content='';
  12. switch ($_GET['con']) {
  13. case 'my_bets':
  14. if (empty($_GET['_unique']) || mysql_num_rows(mysql_query("SELECT `id` FROM `players` WHERE `hash`='".prot($_GET['_unique'])."' LIMIT 1"))==0) exit();
  15. $player=mysql_fetch_array(mysql_query("SELECT * FROM `players` WHERE `hash`='".prot($_GET['_unique'])."' LIMIT 1"));
  16. $my_bets=mysql_query("SELECT * FROM `bets` WHERE `player`=$player[id] ORDER BY `time` DESC LIMIT 30");
  17. if (mysql_num_rows($my_bets)==0) $content.='<br><br><br><i>You haven\'t bet yet.</i>';
  18. else {
  19. $content.='<table id="bets_st_table">';
  20. $content.='<tr>';
  21. $content.='<th>BET ID</th>';
  22. $content.='<th>PLAYER</th>';
  23. $content.='<th>TIME</th>';
  24. $content.='<th>BET</th>';
  25. $content.='<th>MULTIPLIER</th>';
  26. $content.='<th>TARGET</th>';
  27. $content.='<th>ROLL</th>';
  28. $content.='<th>PROFIT</th>';
  29. $content.='</tr>';
  30. $suda=0;
  31. while ($my_bet=mysql_fetch_array($my_bets)) {
  32. $content.=($suda==0)?'<tr>':'<tr class="suda">';
  33. $username=mysql_fetch_array(mysql_query("SELECT `alias` FROM `players` WHERE `id`=$my_bet[player] LIMIT 1"));
  34. $chance['under']=floor((1/($my_bet['multiplier']/100)*((100-$settings['house_edge'])/100))*100)/100;
  35. $chance['over']=100-$chance['under'];
  36. $target=($my_bet['under_over']==0)?'<'.sprintf("%.2f",$chance['under']):'>'.sprintf("%.2f",$chance['over']);
  37. $profit=-$my_bet['bet_amount'];
  38. $profit_class='lose';
  39. $plusko=($my_bet['bet_amount']==0)?'-':'';
  40. if ($my_bet['win_lose']==1) {
  41. $profit+=$my_bet['bet_amount']*$my_bet['multiplier'];
  42. $profit_class='win';
  43. $plusko='+';
  44. }
  45. $content.='<td class="betId first">'.$my_bet['id'].'</td>';
  46. $content.='<td>'.$username['alias'].'</td>';
  47. $content.='<td>'.date('H:i:s',strtotime($my_bet['time'])).'</td>';
  48. $content.='<td>'.sprintf("%.8f",$my_bet['bet_amount']).'</td>';
  49. $content.='<td>'.sprintf("%.2f",$my_bet['multiplier']).'</td>';
  50. $content.='<td>'.$target.'</td>';
  51. $content.='<td>'.sprintf("%.2f",$my_bet['result']).'</td>';
  52. $content.='<td class="'.$profit_class.' right last">'.$plusko.sprintf("%.8f",floor($profit*100000000)/100000000).'</td>';
  53. $content.='</tr>';
  54. $suda=($suda==0)?1:0;
  55. }
  56. $content.='</table>';
  57. }
  58. break;
  59. case 'all_bets':
  60. $all_bets=mysql_query("SELECT * FROM `bets` WHERE `bet_amount`!=0 ORDER BY `time` DESC LIMIT 30");
  61. if (mysql_num_rows($all_bets)==0) $content.='<br><br><br><i>No one has bet yet.</i>';
  62. else {
  63. $content.='<table id="bets_st_table">';
  64. $content.='<tr>';
  65. $content.='<th>BET ID</th>';
  66. $content.='<th>PLAYER</th>';
  67. $content.='<th>TIME</th>';
  68. $content.='<th>BET</th>';
  69. $content.='<th>MULTIPLIER</th>';
  70. $content.='<th>TARGET</th>';
  71. $content.='<th>ROLL</th>';
  72. $content.='<th>PROFIT</th>';
  73. $content.='</tr>';
  74. $suda=0;
  75. while ($all_bet=mysql_fetch_array($all_bets)) {
  76. $content.=($suda==0)?'<tr>':'<tr class="suda">';
  77. if (mysql_num_rows(mysql_query("SELECT `id` FROM `players` WHERE `id`=$all_bet[player] LIMIT 1"))!=0)
  78. $username=mysql_fetch_array(mysql_query("SELECT `alias` FROM `players` WHERE `id`=$all_bet[player] LIMIT 1"));
  79. else $username['alias']='[unknown]';
  80. $chance['under']=floor((1/($all_bet['multiplier']/100)*((100-$settings['house_edge'])/100))*100)/100;
  81. $chance['over']=100-$chance['under'];
  82. $target=($all_bet['under_over']==0)?'<'.sprintf("%.2f",$chance['under']):'>'.sprintf("%.2f",$chance['over']);
  83. $profit=-$all_bet['bet_amount'];
  84. $profit_class='lose';
  85. $plusko=($all_bet['bet_amount']==0)?'-':'';
  86. if ($all_bet['win_lose']==1) {
  87. $profit+=$all_bet['bet_amount']*$all_bet['multiplier'];
  88. $profit_class='win';
  89. $plusko='+';
  90. }
  91. $content.='<td class="betId first">'.$all_bet['id'].'</td>';
  92. $content.='<td>'.$username['alias'].'</td>';
  93. $content.='<td>'.date('H:i:s',strtotime($all_bet['time'])).'</td>';
  94. $content.='<td>'.sprintf("%.8f",$all_bet['bet_amount']).'</td>';
  95. $content.='<td>'.sprintf("%.2f",$all_bet['multiplier']).'</td>';
  96. $content.='<td>'.$target.'</td>';
  97. $content.='<td>'.sprintf("%.2f",$all_bet['result']).'</td>';
  98. $content.='<td class="'.$profit_class.' right last">'.$plusko.sprintf("%.8f",floor($profit*100000000)/100000000).'</td>';
  99. $content.='</tr>';
  100. $suda=($suda==0)?1:0;
  101. }
  102. $content.='</table>';
  103. }
  104. break;
  105. case 'news':
  106. $content.='<br><br><br>';
  107. $query=mysql_query("SELECT * FROM `news` ORDER BY `time` DESC");
  108. while ($row=mysql_fetch_array($query)) {
  109. $content.='<div class="news_single">';
  110. $content.=str_replace('[I]','<i>',str_replace('[/I]','</i>',str_replace('[BR]','<br>',str_replace('[/B]','</b>',str_replace('[B]','<b>',$row['content']))))).'<br><span class="news_single_time">'.$row['time'].'</span>';
  111. $content.='</div>';
  112. }
  113. if (mysql_num_rows($query)==0) $content.='<i>No news available.</i>';
  114. break;
  115. case 'giveaway':
  116. if ($settings['giveaway']!=1) {
  117. $content.='<br><br><br><i>Giveaway is not supported now.</i>';
  118. }
  119. else {
  120. if (empty($_GET['_unique']) || mysql_num_rows(mysql_query("SELECT `id` FROM `players` WHERE `hash`='".prot($_GET['_unique'])."' LIMIT 1"))==0) exit();
  121. $player=mysql_fetch_array(mysql_query("SELECT * FROM `players` WHERE `hash`='".prot($_GET['_unique'])."' LIMIT 1"));
  122. if ($player['balance']!=0) {
  123. $content.='<br><br><br>Sorry, your balance must be <b>0</b> to claim the '.$settings['currency'].' bonus.';
  124. }
  125. else {
  126. $content.='<br><br><br>You can claim the '.$settings['currency'].' bonus now:<br><br>';
  127. $content.='<big><big><b>'.$settings['giveaway_amount'].'</b> '.$settings['currency_sign'].'</big></big><br><br>';
  128. $content.='<table><tr><td valign="top" style="padding: 4px 0;">Enter text from image:</td><td valign="top"><input type="text" id="captchatext" maxlength="4" style="width: 140px; padding: 4px; text-transform: uppercase;"><br><img src="./content/captcha/genImage.php" style="position: relative; top: 4px;"></img></td><td valign="top"><button onclick="javascript:claim($(\'#captchatext\').val());return false;" style="padding: 4px;">Claim</button></td></tr></table>';
  129. }
  130. }
  131. break;
  132. case 'stats':
  133. if (empty($_GET['_unique']) || mysql_num_rows(mysql_query("SELECT `id` FROM `players` WHERE `hash`='".prot($_GET['_unique'])."' LIMIT 1"))==0) exit();
  134. $player=mysql_fetch_array(mysql_query("SELECT * FROM `players` WHERE `hash`='".prot($_GET['_unique'])."' LIMIT 1"));
  135. $content.='<br><br><br>';
  136. $content.='<div class="stats_">';
  137. $content.='<table width="100%">';
  138. $content.='<tr><th>Your Stats</th><th class="center"><img src="./content/images/diceStats.png"></th><th>Global Stats</th></tr>';
  139. $content.='<tr><td>'.$player['t_bets'].'</td><td class="center">NUMBER OF BETS</td><td>'.$settings['t_bets'].'</td></tr>';
  140. $content.='<tr><td>'.$player['t_wagered'].'</td><td class="center">TOTAL WAGERED</td><td>'.$settings['t_wagered'].'</td></tr>';
  141. $content.='<tr><td>'.$player['t_profit'].'</td><td class="center">TOTAL PROFIT</td><td>'.$settings['t_player_profit'].'</td></tr>';
  142. $content.='<tr class="wins"><td>'.$player['t_wins'].'</td><td class="center">WINS</td><td>'.$settings['t_wins'].'</td></tr>';
  143. $content.='<tr class="losses"><td>'.($player['t_bets']-$player['t_wins']).'</td><td class="center">LOSSES</td><td>'.($settings['t_bets']-$settings['t_wins']).'</td></tr>';
  144. $content.='<tr class="wl"><td>'.sprintf("%.3f",$player['t_wins']/($player['t_bets']-$player['t_wins'])).'</td><td class="center">W/L RATIO</td><td>'.sprintf("%.3f",$settings['t_wins']/($settings['t_bets']-$settings['t_wins'])).'</td></tr>';
  145. $content.='</table>';
  146. $content.='</div>';
  147. break;
  148. case 'chat':
  149. if ($settings['chat_enable']!=1) {
  150. $content.='<br><br><br><i>Chat is not supported now.</i>';
  151. }
  152. else {
  153. $content.='<br><br><br><input type="text" id="composeTxt"><button onclick="javascript:compose($(\'#composeTxt\').val());return false;" id="composeBtn">Send</button>';
  154. $content.='<div id="chatWindow"></div>';
  155. $content.='<script type="text/javascript">';
  156. $content.='initializeRefreshingFrameChat();';
  157. $content.='$("#composeTxt").keypress(function(e) { if (e.which==13) compose($("#composeTxt").val()); });';
  158. $content.='$("#composeTxt").qtip({content:{text:\'Press enter to send\'},style:{classes:\'qtip-bootstrap qtip-shadow\'},position:{my:\'bottom left\',at:\'top left\'}});';
  159. $content.='</script>';
  160. }
  161. break;
  162. case 'high_rollers':
  163. $all_bets=mysql_query("SELECT *,(`bet_amount`*`multiplier`) AS `profit_on_win` FROM `bets` WHERE `bet_amount`!=0 AND `win_lose`=1 ORDER BY `profit_on_win` DESC LIMIT 30");
  164. if (mysql_num_rows($all_bets)==0) $content.='<br><br><br><i>No one has bet yet.</i>';
  165. else {
  166. $content.='<table id="bets_st_table">';
  167. $content.='<tr>';
  168. $content.='<th>BET ID</th>';
  169. $content.='<th>PLAYER</th>';
  170. $content.='<th>TIME</th>';
  171. $content.='<th>BET</th>';
  172. $content.='<th>MULTIPLIER</th>';
  173. $content.='<th>TARGET</th>';
  174. $content.='<th>ROLL</th>';
  175. $content.='<th>PROFIT</th>';
  176. $content.='</tr>';
  177. $suda=0;
  178. while ($all_bet=mysql_fetch_array($all_bets)) {
  179. $content.=($suda==0)?'<tr>':'<tr class="suda">';
  180. if (mysql_num_rows(mysql_query("SELECT `id` FROM `players` WHERE `id`=$all_bet[player] LIMIT 1"))!=0)
  181. $username=mysql_fetch_array(mysql_query("SELECT `alias` FROM `players` WHERE `id`=$all_bet[player] LIMIT 1"));
  182. else $username['alias']='[unknown]';
  183. $chance['under']=floor((1/($all_bet['multiplier']/100)*((100-$settings['house_edge'])/100))*100)/100;
  184. $chance['over']=100-$chance['under'];
  185. $target=($all_bet['under_over']==0)?'<'.sprintf("%.2f",$chance['under']):'>'.sprintf("%.2f",$chance['over']);
  186. $profit=-$all_bet['bet_amount'];
  187. $profit_class='lose';
  188. $plusko=($all_bet['bet_amount']==0)?'-':'';
  189. if ($all_bet['win_lose']==1) {
  190. $profit+=$all_bet['bet_amount']*$all_bet['multiplier'];
  191. $profit_class='win';
  192. $plusko='+';
  193. }
  194. $content.='<td class="betId first">'.$all_bet['id'].'</td>';
  195. $content.='<td>'.$username['alias'].'</td>';
  196. $content.='<td>'.date('H:i:s',strtotime($all_bet['time'])).'</td>';
  197. $content.='<td>'.sprintf("%.8f",$all_bet['bet_amount']).'</td>';
  198. $content.='<td>'.sprintf("%.2f",$all_bet['multiplier']).'</td>';
  199. $content.='<td>'.$target.'</td>';
  200. $content.='<td>'.sprintf("%.2f",$all_bet['result']).'</td>';
  201. $content.='<td class="'.$profit_class.' right last">'.$plusko.sprintf("%.8f",floor($profit*100000000)/100000000).'</td>';
  202. $content.='</tr>';
  203. $suda=($suda==0)?1:0;
  204. }
  205. $content.='</table>';
  206. }
  207. break;
  208. }
  209. echo json_encode(array('content'=>$content));
  210. ?>