Файл: gamele.ru/includes/locations/faters/tavern/tavern1.php
Строк: 555
<?php
$build = mysql_fetch_assoc(mysql_query("SELECT * FROM `locations` WHERE `id` = '".$pers['loc']."'"));
echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<HEAD>
<META Http-Equiv="Content-Type" Content="text/html; charset=windows-1251">
<META Http-Equiv="Cache-Control" Content="No-Cache">
<META Http-Equiv="Pragma" Content="No-Cache">
<META Http-Equiv="Expires" Content="0">
<LINK href="/css/frame.css" rel="STYLESHEET" type="text/css">
<LINK href="/css/stl.css" rel="STYLESHEET" type="text/css">
<!--[if lt IE 7]>
<![endif]-->
<SCRIPT src="/js/building_v03.js"></SCRIPT>
<SCRIPT src="/js/ajax.js"></SCRIPT>
<SCRIPT src="/js/signs.js"></SCRIPT>
<SCRIPT src="/js/hpmp.js"></SCRIPT>
<SCRIPT src="/js/t_v01.js"></SCRIPT>
<SCRIPT src="/js/hospi_v01.js"></SCRIPT>
<SCRIPT src="/js/FormUp_v01.js"></SCRIPT>
</HEAD>
<BODY>
<SCRIPT language="JavaScript">
var inshp = ['.InsHP().'];
var vcode = [[1,"'.vCode().'"],[1,"'.vCode().'"],[1,"'.vCode().'"]];
var build = ["'.$pers['login'].'",'.$pers['level'].','.$pers['sklon'].',"'.$pers['clan_gif'].'","'.$pers['clan'].'","'.$pers['clan_d'].'",'.$build['but'].',"main","'.$build['disbut'].'","'.$build['textid'].'",0,0,"'.(($build['quest'])?vCode():'').'"];
view_hospi();
</SCRIPT>
</BODY>
</HTML>';
?>
<table cellpadding=0 cellspacing=0 border=0 align=center width=760>
<tr><td><div align=center><img src=http://image.gamele.ru/1x1.gif width=1 height=10><br><img src="http://image.gamele.ru/gameplay/taverna/loto_day.jpg" width=760 height=255 border=0><br><img src=http://image.gamele.ru/1x1.gif width=1 height=1></div></td></tr>
<tr><td bgcolor=#e0e0e0 valign=top>
<table cellpadding=3 cellspacing=1 border=0 width=100% height=100%>
<tr><td bgcolor=#ffffff colspan="2"><br><div align=center><table cols=3 rows=2 border=0 width=100% class=freetxt><tr><td colspan=3 align=center><b>Лотерея 5 из 30</b><br><table cols=5 border=0 width=100% class=freetxt><tr><td align=center>
</table>
<script>
window.addEvent('domready', function() {
SqueezeBox.initialize({
size: {x: 350, y: 400},
ajaxOptions: {
method: 'get'
}
});
$$('a.boxed').each(function(el) {
el.addEvent('click', function(e) {
new Event(e).stop();
SqueezeBox.fromElement(el);
});
});
$$('.panel-toggler').each(function(el) {
var target = el.getLast().setStyle('display', 'none');
el.getFirst().addEvent('click', function() {
target.style.display = (target.style.display == 'none') ? '' : 'none';
});
});
});
</script>
<?php
class Lottery{
function get_this_user_id(){
// определеить id пользователя
global $pers;
return $pers['id'];
}
function buy($txt = ''){
// списать сумму билета
global $pers;
if ($pers['nv'] < 100) {
$this->mess = 'Не хватает денег<BR>';
} else {
mysql_query("update user set nv = nv - 100 where id = '".mysql_real_escape_string($pers['id'])."';");
mysql_query("INSERT INTO `invent` (`ItemName`,`img`,`protype`,`pl_id`,`dolg`,`price`,`i_param`,`i_need`,`letter`,`death`) VALUES ('Лотерейный билет','loto.gif','1230','".mysql_real_escape_string($pers['id'])."','1','100','2@1','71|72','".mysql_real_escape_string($txt)."','".(time()+86400*7)."');");
}
}
function pay_for_5($summ){
// оплата если 5 из 5 угадано
global $pers;
mysql_query("update user set nv = nv + '".mysql_real_escape_string($summ)."' where id = '".mysql_real_escape_string($pers['id'])."';");
}
function pay_for_4($summ){
// оплата если 4 из 5 угадано
global $pers;
mysql_query("update user set nv = nv + '".mysql_real_escape_string($summ)."' where id = '".mysql_real_escape_string($pers['id'])."';");
}
function pay_for_3($summ){
// оплата если 3 из 5 угадано
global $pers;
mysql_query("update user set nv = nv + '".mysql_real_escape_string($summ)."' where id = '".mysql_real_escape_string($pers['id'])."';");
}
function pay_for_klan($summ){
// 10% клану
// хуй
global $pers;
mysql_query("update user set nv = nv + '".mysql_real_escape_string($summ)."' where id = 7014;");
}
function buy_ticket($selected_str){
$selected_str = substr($selected_str,0,strlen($selected_str)-1);
$selected_array = explode(',',$selected_str);
sort($selected_array);
$id_user = $this->get_this_user_id();
if ($selected_array > 5){
$sql_ins_cheat = "insert into lottery_cheaters(`id_user`,`values`,`date`) values('".mysql_real_escape_string($id_user)."','".mysql_real_escape_string($selected_str)."','".date('Y-m-d H:i:s')."')";
mysql_query($sql_ins_cheat);
}
for($i=0;$i<5;$i++){
$values .= $selected_array[$i].',';
}
$sql = "select id from lottery where end='0'";
$res = mysql_query($sql);
while($result_lottery = mysql_fetch_assoc($res)){
$id_lottery = $result_lottery['id'];
}
$this->buy("Тираж № ".$id_lottery."<BR>Выбраные номера: ".$values);
if($this->mess != null) {
return "<font color=red><B>".$this->mess."</font></b>";
}
echo "<font color=red><B>Билет куплен.<BR></font></b>";
$date = date('Y-m-d H:i:s');
$sql = "insert into lottery_log(`id_user`,`values`,`date`,`id_lottery`) values('".mysql_real_escape_string($id_user)."','".mysql_real_escape_string($values)."','".mysql_real_escape_string($date)."','".mysql_real_escape_string($id_lottery)."')";
$res = mysql_query($sql);
$jackpot = 0;
$sql = "select * from `lottery` where end=0 limit 1";
$res = mysql_query($sql);
while($result = mysql_fetch_assoc($res)){
$id = $result['id'];
$jackpot = $result['jackpot'];
$fond = $result['fond'];
}
$fond += 10.0;
$sql = "update lottery set fond='".mysql_real_escape_string($fond)."' where id='".mysql_real_escape_string($id)."' ";
mysql_query($sql);
}
function get_result(){
$array = range(1,30);
shuffle($array);
for($i=0;$i<5;$i++){
$result[] = $array[$i];
}
return $result;
}
function get_count($win_combination,$pers_combination){
$pers_array = explode(',',$pers_combination);
$count = 0;
for($i=0;$i<5;$i++){
if (strpos(",".$win_combination,",".$pers_array[$i].",") !== FALSE){
$count ++; //echo substr($win_combination,$z,1)." ";
}
}
return $count;
}
function get_win_combination(){
$win_combination = $this->get_result();
for($i=0;$i<5;$i++){
$win_combination_str .= $win_combination[$i].',';
}
$sql = "select id,jackpot,fond from lottery where end='0'";
$res = mysql_query($sql);
while($result = mysql_fetch_assoc($res)){
$id_lottery = $result['id'];
$jackpot = $result['jackpot'];
$fond = $result['fond'];
}
$sql = "insert into lottery_win_combination(`values`,`date`,`id_lottery`) values('".mysql_real_escape_string($win_combination_str)."','".date('Y-m-d H:i:s')."','".mysql_real_escape_string($id_lottery)."') ";
mysql_query($sql);
$people_5 = 0;
$people_4 = 0;
$people_3 = 0;
$sql = "select * from lottery_log where id_lottery='".mysql_real_escape_string($id_lottery)."' ";
$res = mysql_query($sql);
while($result = mysql_fetch_assoc($res)){
$count = $this->get_count($win_combination_str,$result['values']);
if ($count == 5){
$people_5 ++;
}
if ($count == 4){
$people_4 ++;
}
if ($count == 3){
$people_3 ++;
}
}
$klan_pay = $fond*0.05;
$this->pay_for_klan($klan_pay);
$fond = $fond - $klan_pay;
if ($people_5 > 0 ){
$summ_5 = ($jackpot+($fond*0.3))/$people_5;
$jackpot = 0;
}
else{
$summ_5 = ($fond*0.8);
$jackpot += $fond*0.8;
}
if ($people_4 > 0){
$summ_4 = ($fond*0.8)/$people_4;
}
else{
$summ_4 = ($fond*0.8);
$jackpot += $fond*0.8;
}
if ($people_3 > 0){
$summ_3 = ($fond*1.2)/$people_3;
} else{
$summ_3 = $fond*1.2;
$jackpot += $fond*1.2;
}
$sql_upd = "update lottery set end='1' , fond='".mysql_real_escape_string($fond)."' , summ_5='".mysql_real_escape_string($summ_5)."' , summ_4='".mysql_real_escape_string($summ_4)."' , summ_3='".mysql_real_escape_string($summ_3)."' , count_5='".mysql_real_escape_string($people_5)."' , count_4='".mysql_real_escape_string($people_4)."' , count_3='".mysql_real_escape_string($people_3)."' where id='".mysql_real_escape_string($id_lottery)."'";
mysql_query($sql_upd);
$sql_ins = "insert into lottery(`date`,`jackpot`,`fond`,`end`,`summ_5`,`summ_4`,`summ_3`,`count_5`,`count_4`,`count_3`) values('".date('Y-m-d H:i:s',strtotime("+1 week"))."','".mysql_real_escape_string($jackpot)."','0','0','0','0','0','0','0','0')";
mysql_query($sql_ins);
}
function check($id_lottery){
$id_user = $this->get_this_user_id();
//$sql_comb = "select values from lottery_win_combination where id_lottery='".$id_lottery."'";
if ($id_lottery < 1) {
$sql_comb = "select * from lottery where end=1 order by id DESC LIMIT 1;";
$res_comb = mysql_fetch_array(mysql_query($sql_comb));
$id_lottery = $res_comb['id'];
}
$sql_comb = "select * from lottery_win_combination where id_lottery='".mysql_real_escape_string($id_lottery)."'";
$res_comb = mysql_query($sql_comb);
while($result_comb = mysql_fetch_assoc($res_comb)){
$win_combination_str = $result_comb['values'];
}
$sql_summ = "select * from lottery where id='".mysql_real_escape_string($id_lottery)."'";
$res_summ = mysql_query($sql_summ);
while($result_summ = mysql_fetch_assoc($res_summ)){
$summ_5 = $result_summ['summ_5'];
$summ_4 = $result_summ['summ_4'];
$summ_3 = $result_summ['summ_3'];
$jackpot = $result_summ['jackpot'];
}
$sql = "select * from lottery_log where id_lottery='".mysql_real_escape_string($id_lottery)."' and id_user='".mysql_real_escape_string($id_user)."' and send='0' ";
$res = mysql_query($sql);
while($result = mysql_fetch_assoc($res)){
$count = $this->get_count($win_combination_str,$result['values']);
if ($count == 5){
$this->pay_for_5($jackpot);
echo "Билет <B>№ ".$result['id']."</B> выиграл <b>".$jackpot." ER</b> Выбраные номера: ".$result['values']."<BR>";
$zz = 1;
}
if ($count == 4){
$this->pay_for_4($summ_4);
echo "Билет <B>№ ".$result['id']."</B> выиграл <b>".$summ_4." ER</b> Выбраные номера: ".$result['values']."<BR>";
$zz = 1;
}
if ($count == 3){
$this->pay_for_3($summ_3);
echo "Билет <B>№ ".$result['id']."</B> выиграл <b>".$summ_3." ER</b> Выбраные номера: ".$result['values']."<BR>";
$zz = 1;
}
$sql_upd = "update lottery_log set send='1' where id='".mysql_real_escape_string($result['id'])."'";
mysql_query($sql_upd);
}
if (!$zz) {
echo "<font color=red><B>Нет выигрышных билетов</b></font><BR>";
}
}
function view_results($id_lottery = 0){
$str = '';
if ($id_lottery > 0) {
$sql = "select * from lottery where id='".$id_lottery."' and end=1;";
}
else {
$sql = "select * from lottery where end=1 order by id DESC LIMIT 1;";
}
$res = mysql_query($sql);
while ($result = mysql_fetch_assoc($res)){
$id_lottery = $result['id'];
$date = $result['date'];
$jackpot = $result['jackpot'];
$fond = $result['fond'];
$summ_5 = $result['summ_5'];
$summ_4 = $result['summ_4'];
$summ_3 = $result['summ_3'];
$count_5 = $result['count_5'];
$count_4 = $result['count_4'];
$count_3 = $result['count_3'];
}
$summ = $summ_5 + $summ_4 + $summ_3;
$count = $count_5 + $count_4 + $count_3;
$sql_combination = "select * from lottery_win_combination where id_lottery='".mysql_real_escape_string($id_lottery)."'";
$res_combination = mysql_query($sql_combination);
while($result_combination = mysql_fetch_assoc($res_combination)){
$combination = $result_combination['values'];
}
$sql = "select * from lottery_log where id_lottery='".mysql_real_escape_string($id_lottery)."'";
$res = mysql_query($sql);
$allbillets = mysql_num_rows($res);
$str .= '<form method="post" style="margin:0px;"><h4> Итоги тиража номер <input type="text" value="'.$id_lottery.'" size=4 name="tiraj"><input type=submit class=dd value="посмотреть"></h4></form>';
if (!$date) {
return $str.'Лотерея не проводилась.';
}
$str .= 'Тираж номер: <B>'.$id_lottery.'</B> <br />
Дата: <span class=date>'.$date.'</span> <br />
Призовой фонд: <b>'.$fond.' ER</b> <br />
Джекпот: <b>'.$jackpot.' ER</b> <br />
Всего было продано билетов: <B>'.$allbillets.'</B><br />
Выпала комбинация : <span style="FONT-WEIGHT: bold; FONT-SIZE: 12pt; COLOR: #8f0000; FONT-FAMILY: Arial;">'.substr($combination,0,strlen($combination)-1).'</span> <br />
<table border=1 cellspacing=0>
<tr>
<td align=center style="width:150px;"><b>Угадано номеров</b></td>
<td align=center style="width:150px;"><b>Выиграно билетов</b></td>
<td align=center style="width:150px;"><b>Сумма выиграша</b></td>
</tr>
<tr>
<td align=center>5</td>
<td align=center>'.$count_5.'</td>
<td align=center>
';
if ($count_5 == 0){
$str .= 'Не выиграл ни один билет <BR>'.$summ_5.' ER идут в джекпот';
}
else{
$str .= $summ_5.' ER';
}
$str .= '
</td>
</tr>
<tr>
<td align=center>4</td>
<td align=center>'.$count_4.'</td>
<td align=center>
';
if ($count_4 == 0){
$str .= 'Не выиграл ни один билет <BR>'.$summ_4.' ER идут в джекпот';
}
else{
$str .= $summ_4.' ER';
}
$str .= '
</td>
</tr>
<tr>
<td align=center>3</td>
<td align=center>'.$count_3.'</td>
<td align=center>
';
if ($count_3 == 0){
$str .= 'Не выиграл ни один билет <BR>'.$summ_3.' ER идут в джекпот';
}
else{
$str .= $summ_3.' ER';
}
$str .= '
</td>
</tr>
</table>
<br />
Всего победителей: <b>'.$count.'</b> <br />
Всего выиграно: <b>'.$summ.' ER</b> <br />
';
return $str;
}
function view_buy_ticket(){
$str = '';
$str .= '
<style>
td.select{ width: 20px; text-align: center; background-color: #999; cursor: pointer; }
td.unselect{ width: 20px; text-align: center; background-color: none; cursor: pointer; }
</style>
<script>
function add(name){
var array = new Array();
var test = document.getElementById('value').value;
if (test.indexOf(",") > 0){
array = test.split(",");
//alert(array.lenght);
if (array[5] != ''){
document.getElementById(name).className='select';
document.getElementById(name).onclick = function() { del(name) };
test = test + name + ",";
document.getElementById('value').value = test;
}
else{
alert('Вы выбрали уже 5 номеров. Снимите выделение с любого номера.');
}
}
else{
document.getElementById(name).className='select';
document.getElementById(name).onclick = function() { del(name) };
test = test + name + ",";
document.getElementById('value').value = test;
}
}
function del(name){
var array = new Array();
var test = document.getElementById('value').value;
document.getElementById(name).className='unselect';
document.getElementById(name).onclick = function() { add(name) };
test = test.replace(name+",","");
document.getElementById('value').value = test;
}
</script>
<table style="background-color: #ccc">
<tr>
<td class="unselect" id="1" onclick="add('1')">1</td>
<td class="unselect" id="2" onclick="add('2')">2</td>
<td class="unselect" id="3" onclick="add('3')">3</td>
<td class="unselect" id="4" onclick="add('4')">4</td>
<td class="unselect" id="5" onclick="add('5')">5</td>
</tr>
<tr>
<td class="unselect" id="6" onclick="add('6')">6</td>
<td class="unselect" id="7" onclick="add('7')">7</td>
<td class="unselect" id="8" onclick="add('8')">8</td>
<td class="unselect" id="9" onclick="add('9')">9</td>
<td class="unselect" id="10" onclick="add('10')">10</td>
</tr>
<tr>
<td class="unselect" id="11" onclick="add('11')">11</td>
<td class="unselect" id="12" onclick="add('12')">12</td>
<td class="unselect" id="13" onclick="add('13')">13</td>
<td class="unselect" id="14" onclick="add('14')">14</td>
<td class="unselect" id="15" onclick="add('15')">15</td>
</tr>
<tr>
<td class="unselect" id="16" onclick="add('16')">16</td>
<td class="unselect" id="17" onclick="add('17')">17</td>
<td class="unselect" id="18" onclick="add('18')">18</td>
<td class="unselect" id="19" onclick="add('19')">19</td>
<td class="unselect" id="20" onclick="add('20')">20</td>
</tr>
<tr>
<td class="unselect" id="21" onclick="add('21')">21</td>
<td class="unselect" id="22" onclick="add('22')">22</td>
<td class="unselect" id="23" onclick="add('23')">23</td>
<td class="unselect" id="24" onclick="add('24')">24</td>
<td class="unselect" id="25" onclick="add('25')">25</td>
</tr>
<tr>
<td class="unselect" id="26" onclick="add('26')">26</td>
<td class="unselect" id="27" onclick="add('27')">27</td>
<td class="unselect" id="28" onclick="add('28')">28</td>
<td class="unselect" id="29" onclick="add('29')">29</td>
<td class="unselect" id="30" onclick="add('30')">30</td>
</tr>
</table>
Выбраные Вами номера : <input style="border: 0px solid #000; background:transparent;" type="text" readonly="true" id="value" name="value" />
';
return $str;
}
}
$Lottery = new Lottery();
if ($_GET['startlotery'] == 'whf784whfy7w8jfyw8hg745g3y75h7f23785yh38259648gjn6f6734h798h2q398fgsdhnit734') {
mysql_query("INSERT INTO `chat` (`time`,`login`,`msg`) VALUES ('".time()."','sys','".addslashes("top.frames['chmain'].add_msg('<font class=chattime> ".date("H:i:s")." </font> <font color=000000><b><font color=#CC0000>Системная информация</font></b>:</font> Закончился очередной тираж Лотереи. Чтобы ознакомиться с результатами и получить выигрыш, посетите Таверна -> Азартный Зал.</font><BR>'+'');")."');");
$Lottery->get_win_combination();
}
if ($_POST['value']) {
echo $Lottery->buy_ticket($_POST['value']);
}
$sql = "select * from lottery where end=0 order by id DESC LIMIT 1;";
$res = mysql_query($sql);
while ($result = mysql_fetch_assoc($res)){
$id_lottery = $result['id'];
$date = $result['date'];
$jackpot = $result['jackpot'];
$fond = $result['fond'];
$summ_5 = $result['summ_5'];
$summ_4 = $result['summ_4'];
$summ_3 = $result['summ_3'];
$count_5 = $result['count_5'];
$count_4 = $result['count_4'];
$count_3 = $result['count_3'];
}
?>
Следующий тираж <B>№ <?=$id_lottery?></B> состоится <span class=date><?=$date?></span> <BR>
Призовой фонд: <b><?=$fond?> ER</b> <br />
Джекпот: <b><?=$jackpot?> ER</b> <br />
Стоимость лотерейного билета: <B>100 ER</B><BR><BR>
<input type="button" value="Купить лотерейный билет" onClick="document.all['adde'].style.visibility='visible';document.all['adde'].style.display='block';">
<div style="display:none;visivility:hidden;" id="adde">
<h4>Выберите 5 номеров</h4>
<form method='post' style="margin:0px;">
<? echo $Lottery->view_buy_ticket(); ?>
<BR><input type=submit value='Купить билет'></form></div>
<BR>
<input type="button" value="Проверить лотерейные билеты" onClick="location.href='?check=1';">
<BR>
<? if($pers['clan_id']=='admin'){?>
<form method='get' style="margin:0px;">
<input type=hidden name="startlotery" id="startlotery" value="whf784whfy7w8jfyw8hg745g3y75h7f23785yh38259648gjn6f6734h798h2q398fgsdhnit734"><input type="submit" class="lbut" value="Провести лотерею" /></form>
<? }?>
<?
if($_GET['check']) {
$Lottery->check($_POST['tiraj']);
}
echo $Lottery->view_results($_POST['tiraj']);
//echo $Lottery->check(8);
//echo $Lottery->get_count("1,2,3,4,5,","1,2,3,4,5")
?>
</td></table></div></td></tr></table></td></tr><tr><td bgcolor=#ffffff><img src=http://image.gamele.ru/1x1.gif width=1 height=3></td></tr><tr><td><table cellpadding=0 cellspacing=0 border=0 align=center width=760><tr><td bgcolor=#e0e0e0><table cellpadding=3 cellspacing=1 border=0 width=100%>
</table>
</td></tr>
</table>