battles/_unused-files/deal.php

274 lines
12 KiB
PHP
Raw Normal View History

2018-01-28 16:40:49 +00:00
<?php
/**
* Copyright (c) 2018.
* Author: Igor Barkov <lopar.4ever@gmail.com>
* Project name: Battles-Game
*/
session_start();
2018-01-28 16:40:49 +00:00
if (!($_SESSION['uid'] >0)) header("Location: index.php");
include "config.php";
$user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '{$_SESSION['uid']}' LIMIT 1;"));
if ($user['battle'] != 0) { header('location: fbattle.php'); die(); }
$user['prof3_lvl'] = $user['prof3_level'];
if($user['prof3_lvl'] == 0) {
$user['prof3_lvl'] = 1;
}
function timeOut($ttm) {
$out = '';
$time_still = $ttm;
$tmp = floor($time_still/2592000);
$id=0;
if ($tmp > 0)
{
$id++;
if ($id<3) {$out .= $tmp." мес. ";}
$time_still = $time_still-$tmp*2592000;
}
$tmp = floor($time_still/86400);
if ($tmp > 0)
{
$id++;
if ($id<3) {$out .= $tmp." дн. ";}
$time_still = $time_still-$tmp*86400;
}
$tmp = floor($time_still/3600);
if ($tmp > 0)
{
$id++;
if ($id<3) {$out .= $tmp." ч. ";}
$time_still = $time_still-$tmp*3600;
}
$tmp = floor($time_still/60);
if ($tmp > 0)
{
$id++;
if ($id<3) {$out .= $tmp." мин. ";}
}
if($out=='')
{
if($time_still<0)
{
$time_still = 0;
}
$out = $time_still.' сек.';
}
return $out;
}
if(isset($_POST['login_deal']) && ( $user['prof3'] + $user['prof3_lvl'] * 86400 * 30 > time() )) {
if($_POST['login_deal'] == $user['login']) {
$error = 'Нельзя предложить наставничество самому себе ;)';
}else{
$user2 = mysql_fetch_array(mysql_query('SELECT `id`,`login` FROM `users` WHERE `login` = "'.mysql_real_escape_string($_POST['login_deal']).'" LIMIT 1'));
if(isset($user2['id'])) {
$deal = mysql_fetch_array(mysql_query('SELECT `id` FROM `deal` WHERE `uid1` = "'.$user['id'].'" AND `uid2` = "'.$user2['id'].'" AND `finish` > "'.time().'" AND `status` = 0 AND `type` = 1 LIMIT 1'));
if(isset($deal['id'])) {
$error = 'Вы уже подали предложение стать вашим наставником персонажу &quot;'.htmlspecialchars($_POST['login_deal'],NULL,'cp1251').'&quot;.';
}else{
$deal = mysql_fetch_array(mysql_query('SELECT `id` FROM `deal` WHERE `uid2` = "'.$user2['id'].'" AND `status` = 1 AND `type` = 1 LIMIT 1'));
if(isset($deal['id'])) {
$error = 'У персонажа &quot;'.htmlspecialchars($_POST['login_deal'],NULL,'cp1251').'&quot; уже есть наставник!';
}else{
$deal = mysql_fetch_array(mysql_query('SELECT `id`,`finish` FROM `deal` WHERE `uid1` = "'.$user['id'].'" AND `uid2` = "'.$user2['id'].'" AND `status` = 2 AND `type` = 1 AND `finish` > "'.time().'" LIMIT 1'));
if(isset($deal['id'])) {
$error = 'Персонаж &quot;'.htmlspecialchars($_POST['login_deal'],NULL,'cp1251').'&quot; отказался от ваших услуг! Попробуйте через '.timeOut($deal['finish']-time()).', возможно игрок передумает ;)';
}else{
$error = 'Вы предложили &quot;'.htmlspecialchars($_POST['login_deal'],NULL,'cp1251').'&quot; стать вашим учеником! Ожидайте подтверждения!';
mysql_query('INSERT INTO `deal` (
`uid1`,`uid2`,`type`,`status`,`start`,`finish`
) VALUES (
"'.$user['id'].'","'.$user2['id'].'","1","0","'.time().'","'.(time() + 7200).'"
)');
}
}
}
}else{
$error = 'Персонаж с логином &quot;'.htmlspecialchars($_POST['login_deal'],NULL,'cp1251').'&quot; не найден.';
}
}
}elseif(isset($_GET['d'])) {
$deal = mysql_fetch_array(mysql_query('SELECT * FROM `deal` WHERE `id` = "'.mysql_real_escape_string($_GET['d']).'" AND `uid2` = "'.$user['id'].'" AND `finish` > "'.time().'" AND `status` = 0 LIMIT 1'));
if(isset($deal['id'])) {
if(isset($_GET['yes'])) {
$error = 'Вы успешно согласились на сделку!';
mysql_query('UPDATE `deal` SET `status` = "1" WHERE `id` = "'.$deal['id'].'" LIMIT 1');
}elseif(isset($_GET['no'])) {
$error = 'Вы успешно отказались от сделки!';
mysql_query('UPDATE `deal` SET `status` = "2" WHERE `id` = "'.$deal['id'].'" LIMIT 1');
}
}else{
$error = 'Сделка не найдена!';
}
}elseif(isset($_GET['un'])) {
$deal = mysql_fetch_array(mysql_query('SELECT * FROM `deal` WHERE `id` = "'.mysql_real_escape_string($_GET['un']).'" AND `uid2` = "'.$user['id'].'" AND `status` = 1 AND `type` = 1 LIMIT 1'));
if(isset($deal['id'])) {
$error = 'Вы успешно отказались от наставничества!';
mysql_query('UPDATE `deal` SET `status` = "2" WHERE `id` = "'.$deal['id'].'" LIMIT 1');
}else{
$error = 'Сделка не найдена!';
}
}elseif(isset($_GET['un2']) && ( $user['prof3'] + $user['prof3_lvl'] * 86400 * 30 > time() )) {
$deal = mysql_fetch_array(mysql_query('SELECT * FROM `deal` WHERE `id` = "'.mysql_real_escape_string($_GET['un2']).'" AND `uid1` = "'.$user['id'].'" AND `status` = 1 AND `type` = 1 LIMIT 1'));
if(isset($deal['id'])) {
$error = 'Вы успешно отказались от ученика!';
mysql_query('UPDATE `deal` SET `status` = "2" WHERE `id` = "'.$deal['id'].'" LIMIT 1');
}else{
$error = 'Сделка не найдена!';
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>old-dark :: Сделки</title>
<link rel=stylesheet type="text/css" href="css/main.css">
<script language="JavaScript" src="js/jquery.min.js"></script>
</head>
<body leftmargin=0 topmargin=0 marginheight=0 marginwidth=0 bgcolor=#eeeeee style="background: rgb(226, 224, 224);">
<h3>Сделки \ Наставничество</h3>
<br><br>
<div align="center"><font color="red"><?=$error?></font></div><br>
<br>
<div style="position:absolute;top:10px; right:10px;">
<input type="button" onClick="location.href='/deal.php';" value="Обновить">
<input type="button" onClick="location.href='/main.php';" value="Вернуться">
</div>
<table width="90%" border="0" align="center" cellpadding="5" cellspacing="0" style="border:1px solid #000;">
<tr style="color:#FFF;">
<td width="70" align="center" valign="middle" bgcolor="#666666" style="border-right:1px solid #000;">Действие</td>
<td align="center" valign="middle" bgcolor="#666666" style="border-right:1px solid #000;">Предмет сделки</td>
<td width="200" align="center" valign="middle" bgcolor="#666666" style="border-right:1px solid #000;">Кто предложил</td>
<td width="200" align="center" valign="middle" bgcolor="#666666">Оставшееся время</td>
</tr>
<?
$i = 0;
$sp = mysql_query('SELECT * FROM `deal` WHERE `uid2` = "'.$user['id'].'" AND `finish` > "'.time().'" AND `status` = 0');
while( $pl = mysql_fetch_array($sp) ) {
//
$txt = '';
if( $pl['type'] == 1 ) {
$txt = 'Стать учеником';
}
//
$time = $pl['finish']-time();
$time = timeOut($time);
//
$user2 = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'.$pl['uid1'].'" LIMIT 1'));
//
$see = 1;
if(isset($_GET['d']) && $_GET['d'] == $pl['id'] && (isset($_GET['yes']) || isset($_GET['no']))) {
$see = 0;
}
if( $see == 1 ) {
?>
<tr>
<td align="center" style="border-right:1px solid #000;border-top:1px solid #000;"><a href="/deal.php?d=<?=$pl['id']?>&yes">Да</a> \ <a href="/deal.php?d=<?=$pl['id']?>&no">Нет</a></td>
<td align="center" style="border-right:1px solid #000;border-top:1px solid #000;"><?=$txt?></td>
<td align="center" style="border-right:1px solid #000;border-top:1px solid #000;"><?=$user2['login']. '' .$user2['id']. '&nbsp;<a href="/inf.php?EXTERNAL_FRAGMENT" target="_blank"><img width="12" height="11" src="http://capitalcity.old-dark.ru/i/inf.gif"></a>' ?></td>
2018-01-28 16:40:49 +00:00
<td align="center" style="border-top:1px solid #000;"><?=$time?></td>
</tr>
<?
$i++;
}
} ?>
</table>
<? if( $i == 0 ) { ?>
<table width="90%" border="0" align="center" cellpadding="5" cellspacing="0" style="border-left:1px solid #000;border-right:1px solid #000;border-bottom:1px solid #000;">
<tr>
<td align="center" style="border-top:1px solid #000;">Нет сделок</td>
</tr>
</table>
<? } ?>
<p>&nbsp;</p>
<h3>Наставничество</h3>
<?
if( $user['prof3'] + $user['prof3_lvl'] * 86400 * 30 > time() ) {
//
$denast = mysql_fetch_array(mysql_query('SELECT * FROM `deal` WHERE `uid2` = "'.$user['id'].'" AND `type` = 1 AND `status` = 1 LIMIT 1'));
$nast = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'.$denast['uid1'].'" LIMIT 1'));
//
$html = '';
$i = 0;
$sp = mysql_query('SELECT * FROM `deal` WHERE `uid1` = "'.$user['id'].'" AND `status` = 1 AND `type` = 1');
while( $pl = mysql_fetch_array($sp) ) {
$user2 = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'.$pl['uid2'].'" LIMIT 1'));
if(isset($user2['id'])) {
$html .= ' <tr>
<td align="right" style="border-top:1px solid #000;">&nbsp;'.($i+1).'.&nbsp;</td>
<td align="left" style="border-top:1px solid #000;"><b>'.$user2['login'].'</b> ['.$user2['level'].']<a href="/inf.php?'.$user2['id'].'" target="_blank"><img width="12" height="11" src="http://capitalcity.old-dark.ru/i/inf.gif"></a>'.
'<small> обучается с '.date('d.m.Y H:i',$pl['start']).'</small>'.
'&nbsp;<small>(<a href="/deal.php?un2='.$pl['id'].'">отказаться</a>)</small>'.
'</td>
</tr>';
$i++;
}
}
//
$lvl = 0;
$exp = 0;
if( $i < 10 ) {
$lvl = 0;
$exp = 10;
}elseif( $i < 15 ) {
$lvl = 1;
$exp = 15;
}elseif( $i < 25 ) {
$lvl = 2;
$exp = 25;
}else{
$lvl = 3;
$exp = '--';
}
//
?>
<table width="90%" border="0" align="center" cellpadding="5" cellspacing="0" style="border:1px solid #000;">
<tr>
<td width="200" align="center" style="border-right:1px solid #000;border-top:1px solid #000;">Ваш наставник</td>
<td align="left" style="border-top:1px solid #000;"><?
if(isset($nast['id'])) {
echo '<b>'.$nast['login'].'</b>&nbsp;<a href="/inf.php?'.$nast['id'].'" target="_blank"><img width="12" height="11" src="http://capitalcity.old-dark.ru/i/inf.gif"></a>';
echo ' <small>(<a href="/deal.php?un='.$denast['id'].'">отказаться</a>)</small>';
}else{
echo 'Нет';
}
?></td>
</tr>
<tr>
<td align="center" style="border-right:1px solid #000;border-top:1px solid #000;">Уровень наставничества</td>
<td align="left" style="border-top:1px solid #000;"><?=$lvl?></td>
</tr>
<tr>
<td align="center" style="border-right:1px solid #000;border-top:1px solid #000;">Опыт наставничества</td>
<td align="left" style="border-top:1px solid #000;"><?=$i?> / <?=$exp?></td>
</tr>
<tr>
<td align="center" style="border-right:1px solid #000;border-top:1px solid #000;">Срок действия лицензии</td>
<td align="left" style="border-top:1px solid #000;">до <?=date('d.m.Y H:i', $user['prof3'] + 86400*30*$user['prof3_lvl'] )?> <small style="color:#666">(Продлевается в Академмии на Торговой ул.)</small></td>
</tr>
<tr>
<td align="center" style="border-right:1px solid #000;border-top:1px solid #000;">Ваши ученики (<?=$i?> чел.):</td>
<td align="left" style="border-top:1px solid #000;">
<form method="post" action="/deal.php">
Введите логин ученика: <input style="width:174px;" type="text" value="" name="login_deal">&nbsp;<input type="submit" value="Предложить наставничество">
</form>
</td>
</tr>
<?=$html?>
</table>
<?
}else{
if($user['prof3'] > 0 ) {
echo '<center><br><br>У вас закончилась лицензия Наставника, продлите её в Академии!</center>';
}else{
echo '<center><br><br>У вас нет лицензия Наставника, приобретите её в Академии!</center>';
}
}?>
</body>
</html>