Файл: element_town.php
Строк: 840
<?php
require_once './element_options/element_options.php';
if (!$user) { header('Location: /'); exit; }
// Если нет идентефикатора или он равен моему клану
if (!$id OR $id == $user['lost_town']) {
if ($user['lost_town'] == 0) {
$town_level = element_settings_game('lost_town_create_lvl');
$title = 'Город';
require_once './element_include/element_head.php';
require_once './element_include/element_header_user_true.php';
echo '<div class="nfl p5 mb5 cntr mt5 small mlra">';
echo '<span class="white">В города принимаются игроки от '.$town_level.'-го уровня, сохранившие своего персонажа.</span><br/><br/>';
echo '<span class="white">Если вы хотите вступить в существующий город, выберите его из <a class="lngreen" href="/rating?go=town">списка</a> и напишите правителю города.</span>';
echo ($user['lost_level'] >= $town_level) ? '<br/><br/><span class="white">Если Вы хотите быть правителем, <a class="lngreen" href="/town/create">создайте</a> свой город!</span>' : '';
echo '</div>';
require_once './element_include/element_foot_user_true.php';
} else {
$get_user = (isset($_GET['user']) AND is_numeric($_GET['user'])) ? (int)$_GET['user'] : false;
if ($go == 'exit_town') {
if ($town_other[0] > 0 AND $town_other[0] <= 7) {
if (isset($_GET['ok'])) {
$list_user = readcache('element_list_user_town'.$user['lost_town']);
if (!empty($list_user)) {
unset($list_user[$town_other[0]][$user['lost_id']]);
writecache('element_list_user_town'.$user['lost_town'], $list_user);
}
$journal = '<span class="red">[user]'.$user['lost_id'].'[/user] покинул город</span>';
mysql_query("INSERT INTO `element_town_journal` SET `lost_town` = '$user[lost_town]',
`lost_value` = '$journal',
`lost_time` = '".time()."'");
$user['lost_town_altar_time'] = time() - 5;
$user['lost_town'] = 0;
writecache('element_users_id_'.$user['lost_id'], $user);
user_list_update($user['lost_id']);
header('Location: /town');
exit;
} else {
$title = 'Город "'.$user_town['lost_name'].'"';
require_once './element_include/element_head.php';
require_once './element_include/element_header_user_true.php';
echo '<div class="nfl p5 mb5 mt5 red cntr small mlra">';
echo 'Вы действительно хотите покинуть город <img src="/images/town/race_'.$user_town['lost_race'].'.png" alt=""/> <span class="yellow1 bold">'.$user_town['lost_name'].'</span>?';
echo '<br/><a class="button mt5 w40" href="/town?go=exit_town&ok">Да, подтверждаю</a> <a class="button w40" href="/town">Нет, отмена</a>';
echo '</div>';
require_once './element_include/element_foot_user_true.php';
exit;
}
}
}
if ($go == 'settings_user' AND $get_user) {
if ($town_other[0] >= 0 AND $town_other[0] <= 5 AND $user['lost_id'] != $get_user) {
$set_user = cache_user($get_user);
$exp_town_set = explode(':', $set_user['lost_town_other']);
if ($town_other[0] < $exp_town_set[0] AND $set_user['lost_town'] == $user_town['lost_id']) {
$get_exp = explode(' ', $set_user['lost_exp']);
$title = 'Город "'.$user_town['lost_name'].'"';
require_once './element_include/element_head.php';
require_once './element_include/element_header_user_true.php';
// Повышаю звания
if (isset($_GET['rankup']) AND $town_other[0] < ($exp_town_set[0] - 1)) {
$list_user = readcache('element_list_user_town'.$user_town['lost_id']);
if (!empty($list_user)) {
unset($list_user[$exp_town_set[0]][$get_user]);
$list_user[$exp_town_set[0] - 1][$get_user] = $get_exp[2];
writecache('element_list_user_town'.$user_town['lost_id'], $list_user);
}
$exp_town_set[0] = $exp_town_set[0] - 1;
$set_user['lost_town_other'] = implode(':', $exp_town_set);
$journal = '<span class="lngreen">[user]'.$user['lost_id'].'[/user] повысил [user]'.$get_user.'[/user] до звания: '.town_users_zvanie($exp_town_set[0]).'</span>';
mysql_query("INSERT INTO `element_town_journal` SET `lost_town` = '$user[lost_town]',
`lost_value` = '$journal',
`lost_time` = '".time()."'");
writecache('element_users_id_'.$get_user, $set_user);
user_list_update($get_user);
header('Location: /town?user='.$get_user.'&go=settings_user');
exit;
}
// Понижаю звание
if (isset($_GET['rankdown']) AND $exp_town_set[0] < 7) {
$list_user = readcache('element_list_user_town'.$user_town['lost_id']);
if (!empty($list_user)) {
unset($list_user[$exp_town_set[0]][$get_user]);
$list_user[$exp_town_set[0] + 1][$get_user] = $get_exp[2];
writecache('element_list_user_town'.$user_town['lost_id'], $list_user);
}
$exp_town_set[0] = $exp_town_set[0] + 1;
$set_user['lost_town_other'] = implode(':', $exp_town_set);
$journal = '<span class="red">[user]'.$user['lost_id'].'[/user] понизил [user]'.$get_user.'[/user] до звания: '.town_users_zvanie($exp_town_set[0]).'</span>';
mysql_query("INSERT INTO `element_town_journal` SET `lost_town` = '$user[lost_town]',
`lost_value` = '$journal',
`lost_time` = '".time()."'");
writecache('element_users_id_'.$get_user, $set_user);
user_list_update($get_user);
header('Location: /town?user='.$get_user.'&go=settings_user');
exit;
}
if (isset($_GET['kick'])) {
if (isset($_GET['ok'])) {
$list_user = readcache('element_list_user_town'.$user_town['lost_id']);
if (!empty($list_user)) {
unset($list_user[$exp_town_set[0]][$get_user]);
writecache('element_list_user_town'.$user_town['lost_id'], $list_user);
}
$set_user['lost_town'] = 0;
$set_user['lost_town_altar_time'] = time() - 5;
$journal = '<span class="red">[user]'.$user['lost_id'].'[/user] исключил из города [user]'.$get_user.'[/user]</span>';
mysql_query("INSERT INTO `element_town_journal` SET `lost_town` = '$user[lost_town]',
`lost_value` = '$journal',
`lost_time` = '".time()."'");
mysql_query("UPDATE `element_user` SET `lost_town` = '0' WHERE `lost_id` = '$get_user' LIMIT 1");
writecache('element_users_id_'.$get_user, $set_user);
user_list_update($get_user);
header('Location: /town');
exit;
} else {
echo '<div class="nfl p5 mb5 mt5 red cntr small mlra">';
echo 'Вы действительно хотите исключить '.ikonka_user($set_user['lost_race'], ((!empty($online[$get_user])) ? 'online' : 'offline')).' <a class="yellow1 bold" href="/user?id='.$get_user.'">'.$set_user['lost_login'].'</a> с города?';
echo '<br/><a class="button mt5 w40" href="/town?user='.$get_user.'&go=settings_user&kick&ok">Да, подтверждаю</a> <a class="button w40" href="/town?user='.$get_user.'&go=settings_user">Нет, отмена</a>';
echo '</div>';
}
}
if (isset($_GET['pravitelstvo']) AND $town_other[0] == 0) {
if (isset($_GET['ok'])) {
$list_user = readcache('element_list_user_town'.$user_town['lost_id']);
if (!empty($list_user)) {
unset($list_user[$exp_town_set[0]][$get_user]);
unset($list_user[0][$user['lost_id']]);
$list_user[0][$get_user] = $get_exp[2];
$list_user[1][$user['lost_id']] = $lost_exp[2];
writecache('element_list_user_town'.$user_town['lost_id'], $list_user);
}
$town_other[0] = 1;
$user['lost_town_other'] = implode(':' ,$town_other);
$exp_town_set[0] = 0;
$set_user['lost_town_other'] = implode(':', $exp_town_set);
$journal = '<span class="admin">[user]'.$user['lost_id'].'[/user] передал правительство городом [user]'.$get_user.'[/user]</span>';
mysql_query("INSERT INTO `element_town_journal` SET `lost_town` = '$user[lost_town]',
`lost_value` = '$journal',
`lost_time` = '".time()."'");
writecache('element_users_id_'.$get_user, $set_user);
writecache('element_users_id_'.$user['lost_id'], $user);
user_list_update($get_user);
user_list_update($user['lost_id']);
header('Location: /town');
exit;
} else {
echo '<div class="nfl p5 mb5 mt5 red cntr small mlra">';
echo 'Вы действительно хотите передать правительство городом '.ikonka_user($set_user['lost_race'], ((!empty($online[$get_user])) ? 'online' : 'offline')).' <a class="yellow1 bold" href="/user?id='.$get_user.'">'.$set_user['lost_login'].'</a>?';
echo '<br/><a class="button mt5 w40" href="/town?user='.$get_user.'&go=settings_user&pravitelstvo&ok">Да, подтверждаю</a> <a class="button w40" href="/town?user='.$get_user.'&go=settings_user">Нет, отмена</a>';
echo '</div>';
}
}
echo '<div class="nfl p5 mb5 mt5 small mlra">';
echo '<div class="cntr">';
echo ikonka_user($set_user['lost_race'], ((!empty($online[$get_user])) ? 'online' : 'offline')).' <a class="yellow1 bold" href="/user?id='.$get_user.'">'.$set_user['lost_login'].'</a><br/>';
echo '<span class="yellow1"><img src="/images/town/race_'.$user_town['lost_race'].'.png" alt=""/> <a class="yellow1 bold" href="town?id='.$user_town['lost_id'].'">'.$user_town['lost_name'].'</a>, '.town_users_zvanie($exp_town_set[0]).'</span><br/>';
echo '<span class="yellow1">'.$name_race[$set_user['lost_race']].', <span class="bold">'.$set_user['lost_level'].'</span> уровень</span>';
echo '<br/><span class="yellow1">Городской опыт: <span class="bold">'.Replace_Bytes($get_exp[2]).'</span></span>';
echo '</div>';
echo '<div class="nf2 p5 mt5 cntr mlra">';
echo ($town_other[0] < ($exp_town_set[0] - 1)) ? '<div class="ml5 mr5">
<a class="bl p5 block odd" href="/town?user='.$get_user.'&go=settings_user&rankup">
<span class="small yellow1"> Повысить звание</span> <span class="lngreen"></span>
</a>
</div>' : '';
echo ($exp_town_set[0] < 7) ? '<div class="ml5 mr5">
<a class="bl p5 block odd" href="/town?user='.$get_user.'&go=settings_user&rankdown">
<span class="small yellow1"> Понизить звание</span> <span class="lngreen"></span>
</a>
</div>' : '';
echo '<div class="ml5 mr5">
<a class="bl p5 block odd" href="/town?user='.$get_user.'&go=settings_user&kick">
<span class="small yellow1"> Исключить с города</span> <span class="lngreen"></span>
</a>
</div>';
echo ($town_other[0] == 0) ? '<div class="ml5 mr5">
<a class="bl p5 block odd" href="/town?user='.$get_user.'&go=settings_user&pravitelstvo">
<span class="small yellow1"> Передать правительство</span> <span class="lngreen"></span>
</a>
</div>' : '';
echo '</div>';
echo '</div>';
require_once './element_include/element_foot_user_true.php';
exit;
}
}
}
if ($go == 'settings' AND isset($_GET['announse']) AND $town_other[0] <= 5) {
$announce = (isset($_POST['announce']) AND !empty($_POST['announce'])) ? mysql_real_escape_string(htmlspecialchars(addslashes(trim($_POST['announce'])))) : '';
$user_town['lost_text_announce'] = $announce;
$user_town['lost_other_announce'] = $user['lost_id'].'|||'.time();
writecache('element_town_id_'.$user_town['lost_id'],$user_town);
town_list_update($user_town['lost_id']);
deletecache('element_town_announce'.$user_town['lost_id']);
}
$town_announce = '';
$title = 'Город "'.$user_town['lost_name'].'"';
$list_user = array_users_town($user['lost_town']);
require_once './element_include/element_head.php';
require_once './element_include/element_header_user_true.php';
require_once './element_function/element_function_pagination.php';
require_once './element_function/element_function_town.php';
$up_level_town = town_up_level($user_town['lost_id'], $user_town['lost_level'], $user_town['lost_exp']);
if ($up_level_town[0] == 1) {
$user_town['lost_level'] = $up_level_town[1];
writecache('element_town_id_'.$user_town['lost_id'],$user_town);
town_list_update($user_town['lost_id']);
}
$teck_lvl_exp = cache_town_level($user_town['lost_level']);
$prg_bar = (int)((($user_town['lost_exp'] - $teck_lvl_exp) / $up_level_town[2]) * 100);
$page = (isset($_GET['page']) AND is_numeric($_GET['page'])) ? (int)$_GET['page'] : 1;
$pagination = pagination(10, $page, count($list_user));
echo '<div class="nfl p5 mb5 mt5 small mlra">';
echo '<table class="mlra"><td><img width="50" height="50" alt="" src="/images/town/logo_'.$user_town['lost_race'].'.png" alt=""/></td><td class="small" valign="top">';
echo '<span class="yellow1 bold"><img src="/images/town/race_'.$user_town['lost_race'].'.png" alt=""/> '.$user_town['lost_name'].'</span><br/>';
echo '<span class="white bold"><img width="13" height="11" src="/images/icons/experience.png"> Уровень: '.$user_town['lost_level'].'</span><br/>';
echo '<span class="white bold"><img width="13" height="11" src="/images/icons/experience.png"> Опыт: '.Replace_Bytes($user_town['lost_exp']).' / '.Replace_Bytes($up_level_town[2]).' <span class="ccc">('.$prg_bar.'%)</span></span><br/>';
echo '</td></table>';
if ($go == 'settings' AND $town_other[0] <= 5) {
echo '<div class="nf2 cntr p5 mt5 mb5 mlra small">
<form method="post" action="/town?go=settings&announse">
<label class="bl mb5 ccc">Новое объявление:<br>
<input class="fdark w70" type="text" name="announce" value="" size="20" maxlength="200">
</label>
<input type="submit" class="button blue w40" name="submit" value="Сохранить"/>';
echo '</form></div>';
}
if (!empty($user_town['lost_text_announce'])) {
$explode_t = explode('|||', $user_town['lost_other_announce']);
$cache_announce = cache_user($explode_t[0]);
echo '<div class="nf2 small p5 mb5 small cntr lngreen mlra">';
echo '<div class="small yellow1 bold cntr">Объявление от '.ikonka_user($cache_announce['lost_race'], ((!empty($online[$explode_t[0]])) ? 'online' : 'offline')).' <a href="/user?id='.$explode_t[0].'">'.$cache_announce['lost_login'].'</a>:</div>';
echo '<div class="small moderator cntr">'.$user_town['lost_text_announce'].'</div>';
echo '<div class="small gray1 mt5 cntr">'.Timer($explode_t[1]).'</div>';
echo '</div>';
}
echo '<div class="nf2 p5 mlra cntr">';
echo '<div class="ml5 mr5">
<a class="sndr bl" href="/town/treas?id='.$user_town['lost_id'].'">
<span class="moderator">Казна города</span>
</a>
</div>';
echo '<div class="ml5 mr5">
<a class="sndr bl" href="/town/altar?id='.$user_town['lost_id'].'">
<span class="moderator">Алтарь города</span>
</a>
</div>';
echo '<div class="ml5 mr5">
<a class="sndr bl" href="/town/journal?id='.$user_town['lost_id'].'">
<span class="moderator">Журнал города</span>
</a>
</div>';
echo '<div class="ml5 mr5">
<a class="sndr bl" href="/forum?id='.$user_town['lost_id'].'">
<span class="moderator">Форум города</span>
</a>
</div>';
echo '<div class="ml5 mr5">
<a class="sndr bl" href="/town/chat?id='.$user_town['lost_id'].'">
<span class="moderator">Чат города</span>
</a>
</div>';
echo '</div>';
echo '<div class="small p5 yellow1 bold cntr">Игроков в городе: '.count($list_user).' из '.$user_town['lost_max_users'].'</div>';
echo '<div class="nf2 p5 mlra">';
$i = $pagination['start'] + 1;
foreach(array_slice($list_user, $pagination['start'], $pagination['num'], true) as $key => $value) {
$odd = (($i % 2) ? ' odd' : '');
$cache_user = cache_user($key);
$exp123 = explode(':', $cache_user['lost_town_other']);
$setting = (($go == 'settings' AND $town_other[0] <= 5 AND $town_other[0] < $exp123[0]) ? 1 : 0);
echo '<div class="ml5 mr5">
<a class="bl p5 block'.$odd.'" href="'.(($setting == 1) ? '/town?user='.$key.'&go=settings_user' : '/user?id='.$key.'').'">
'.(($setting == 1) ? '<span class="small mb5 fr"><img src="/images/icons/settings.png"></span>' : '').'
<span class="small mb5 yellow1"><span class="white">'.$i.'.</span> '.ikonka_user($cache_user['lost_race'], ((!empty($online[$key])) ? 'online' : 'offline')).' '.$cache_user['lost_login'].'</span> <span class="lngreen"><img width="13" height="11" src="/images/icons/experience.png">'.Replace_Bytes($value).'</span>
<br/><span class="small mt5 lngreen">'.town_users_zvanie($exp123[0]).'</span>
</a>
</div>';
$i++;
}
echo pagination_echo($pagination['page'],$pagination['total'], (($go == 'settings') ? '/town?go=settings&page=' : '/town?page='));
echo '</div>';
// lost_create_time
echo '<div class="mt5">';
echo ($town_other[0] <= 5 AND $go != 'settings') ? '<img src="/images/icons/1.gif"> <a class="lngreen" href="'.((isset($_GET['page'])) ? '/town?go=settings&page='.$page.'' : '/town?go=settings').'">Управление городом</a><br/>' : '';
echo ($town_other[0] <= 5 AND $go == 'settings') ? '<img src="/images/icons/1.gif"> <a class="lngreen" href="'.((isset($_GET['page'])) ? '/town?page='.$page.'' : '/town').'">Скрыть управление</a><br/>' : '';
echo '<span class="white"><img src="/images/icons/1.gif"> Город основан: <span class="ccc">'.rdate("d M Y, H:i", $user_town['lost_create_time']).'</span></span><br/>';
$create_town = cache_user($user_town['lost_create_user']);
echo '<span class="white"><img src="/images/icons/1.gif"> Основал'.(($create_town['lost_male'] == 'female') ? 'а' : '').' город: '.ikonka_user($create_town['lost_race'], ((!empty($online[$create_town['lost_id']])) ? 'online' : 'offline')).' <a class="yellow1 bold" href="/user?id='.$create_town['lost_id'].'">'.$create_town['lost_login'].'</a></span>';
echo ($town_other[0] > 0 AND $town_other[0] <= 7) ? '<br/><img src="/images/icons/1.gif"> <a class="red" href="/town?go=exit_town">Покинуть город</a>' : '';
echo '</div>';
echo '</div>';
require_once './element_include/element_foot_user_true.php';
}
} else {
$cache_town = cache_town($id);
if (!$cache_town) {
$title = 'Доступ закрыт';
$error1 = '<span class="small">Выбранный Вами город не найден</span>';
require_once 'element_error_page.php';
exit;
}
$title = 'Город "'.$cache_town['lost_name'].'"';
$list_user = array_users_town($id);
$count_list = count($list_user);
require_once './element_include/element_head.php';
require_once './element_include/element_header_user_true.php';
require_once './element_function/element_function_town.php';
$up_level_town = town_up_level($cache_town['lost_id'], $cache_town['lost_level'], $cache_town['lost_exp']);
if ($up_level_town[0] == 1) {
$cache_town['lost_level'] = $up_level_town[1];
writecache('element_town_id_'.$cache_town['lost_id'],$cache_town);
town_list_update($cache_town['lost_id']);
}
$teck_lvl_exp = cache_town_level($cache_town['lost_level']);
$prg_bar = (int)((($cache_town['lost_exp'] - $teck_lvl_exp) / $up_level_town[2]) * 100);
echo '<div class="nfl p5 mb5 mt5 small mlra">';
echo '<table class="mlra"><td><img width="50" height="50" alt="" src="/images/town/logo_'.$cache_town['lost_race'].'.png" alt=""/></td><td class="small" valign="top">';
echo '<span class="yellow1 bold"><img src="/images/town/race_'.$cache_town['lost_race'].'.png" alt=""/> '.$cache_town['lost_name'].'</span><br/>';
echo '<span class="white bold"><img width="13" height="11" src="/images/icons/experience.png"> Уровень: '.$cache_town['lost_level'].'</span><br/>';
echo '<span class="white bold"><img width="13" height="11" src="/images/icons/experience.png"> Опыт: '.Replace_Bytes($cache_town['lost_exp']).' / '.Replace_Bytes($up_level_town[2]).' <span class="ccc">('.$prg_bar.'%)</span></span><br/>';
echo '</td></table>';
if ($user['lost_privilege'] == 3) {
echo '<div class="nf2 p5 mlra cntr">';
echo '<div class="ml5 mr5">
<a class="sndr bl" href="/town/treas?id='.$id.'">
<span class="moderator">Казна города</span>
</a>
</div>';
echo '<div class="ml5 mr5">
<a class="sndr bl" href="/town/journal?id='.$id.'">
<span class="moderator">Журнал города</span>
</a>
</div>';
echo '<div class="ml5 mr5">
<a class="sndr bl" href="/forum?id='.$id.'">
<span class="moderator">Форум города</span>
</a>
</div>';
echo '<div class="ml5 mr5">
<a class="sndr bl" href="/town/chat?id='.$id.'">
<span class="moderator">Чат города</span>
</a>
</div>';
echo '</div>';
} else {
echo '<div class="nf2 p5 mlra cntr">';
echo '<div class="ml5 mr5">
<a class="sndr bl" href="/forum?id='.$id.'">
<span class="moderator">Форум города</span>
</a>
</div>';
echo '</div>';
}
echo '<div class="small p5 yellow1 bold cntr">Игроков в городе: '.$count_list.'</div>';
echo '<div class="nf2 p5 small mlra">';
if ($count_list > 0) {
require_once './element_function/element_function_pagination.php';
$page = (isset($_GET['page']) AND is_numeric($_GET['page'])) ? (int)$_GET['page'] : 1;
$pagination = pagination(10, $page, $count_list);
$i = $pagination['start'] + 1;
foreach(array_slice($list_user, $pagination['start'], $pagination['num'], true) as $key => $value) {
$odd = (($i % 2) ? ' odd' : '');
$cache_user = cache_user($key);
$exp123 = explode(':', $cache_user['lost_town_other']);
echo '<div class="ml5 mr5">
<a class="bl p5 block'.$odd.'" href="/user?id='.$key.'">
<span class="small mb5 yellow1"><span class="white">'.$i.'.</span> '.ikonka_user($cache_user['lost_race'], ((!empty($online[$key])) ? 'online' : 'offline')).' '.$cache_user['lost_login'].'</span> <span class="lngreen"><img width="13" height="11" src="/images/icons/experience.png">'.Replace_Bytes($value).'</span>
<br/><span class="small mt5 lngreen">'.town_users_zvanie($exp123[0]).'</span>
</a>
</div>';
$i++;
}
echo pagination_echo($pagination['page'],$pagination['total'], '/town?id='.$id.'&page=');
} else echo '<div class="cntr ccc">В городе игроков не найдено</div>';
echo '</div>';
echo '<div class="mt5">';
echo '<span class="white"><img src="/images/icons/1.gif"> Город основан: <span class="ccc">'.rdate("d M Y, H:i", $cache_town['lost_create_time']).'</span></span><br/>';
$create_town = cache_user($cache_town['lost_create_user']);
echo '<span class="white"><img src="/images/icons/1.gif"> Основал'.(($create_town['lost_male'] == 'female') ? 'а' : '').' город: '.ikonka_user($create_town['lost_race'], ((!empty($online[$create_town['lost_id']])) ? 'online' : 'offline')).' <a class="yellow1 bold" href="/user?id='.$create_town['lost_id'].'">'.$create_town['lost_login'].'</a></span>';
echo '</div>';
echo '</div>';
require_once './element_include/element_foot_user_true.php';
}
?>