Просмотр файла other/profile.php

Размер файла: 15.59Kb
<?php
// by Mike O. (mides), coolcms.org
require_once '../includes/sys.php';
require_once '../includes/header.php';

$user_r = mysql_query("SELECT * FROM `users` WHERE `id` = '$id'");
$user = mysql_fetch_assoc($user_r);
if (!$user['id']) {
	redirect(HTTPHOME);
}

$type = 'profile';

switch ($act) {
    default:
        echo '<div class="title">'.username($id, 2).' ('.access2($id).') [id: '.$id.']</div><div class="body">';
		$ban_r = mysql_query("SELECT * FROM `ban` WHERE `id_user` = '$id' and `until` > '".TIME."'");
		$ban = mysql_fetch_assoc($ban_r);
		if ($ban['id']) {
			if ($ban['reason']) {
				echo username($ban['by'], 2).' выдал бан до '.ccdate($ban['until'], 0).'<br />Причина: '.$ban['reason'];
			} else {
				echo username($ban['by'], 2).' пнул этого юзера';
			}
			echo '<hr>';
		}
		note();
		if ($user['avatar']) {
			if ($user['avatar_photo']) {
				$photo = mysql_fetch_assoc(mysql_query("SELECT * FROM `photos` WHERE `id` = '$user[avatar]'"));
				if (file_exists('../photos/files/'.$photo['file'])) {
					echo '<a href="../photos/index.php?act=view&amp;id='.$photo['id'].'"><img src="../photos/resize.php?dir=photos/files&amp;name='.$photo['file'].'" /></a>';
				} else {
					mysql_query("UPDATE `users` SET `avatar` = 0, `avatar_photo` = 0 WHERE `id` = '$user[id]'");
					echo '<img src="../images/avatars/noavatar.gif" />';
				}
			} else {
				$avatar = mysql_fetch_assoc(mysql_query("SELECT * FROM `avatars` WHERE `id` = '$user[avatar]'"));
				if (file_exists('../'.$avatar['path'])) {
					echo '<img src="../'.$avatar['path'].'" />';
				} else {
					mysql_query("UPDATE `users` SET `avatar` = 0 WHERE `id` = '$user[id]'");
					echo '<img src="../images/avatars/noavatar.gif" />';
				}
			}
		} else {
			echo '<img src="../images/avatars/noavatar.gif" />';
		}
		echo '<br />';
		$online_r = mysql_query("SELECT `id` FROM `online` WHERE `id_user` = '$id'");
		if (mysql_num_rows($online_r)) {
			echo '<font color="green">On-line</font>';
		} else {
			echo '<font color="red">Off-line</font><br />Посл. визит: '.ccdate($user['lastvisit'], 0);      
		}
		echo '<br />';
		if ($user['name']) echo $lang['name'].': <b>'.$user['name'].'</b><br />';
		switch ($user['gender']) {
			case '1': $gender = $lang['male']; break;
			case '2': $gender = $lang['female']; break;
		}
		if (isset($gender)) echo $lang['gender'].': '.$gender.'<br />';
		if ($user['from']) echo $lang['from'].': '.$user['from'].'<br />';
		if ($user['birthday']) echo $lang['birthday'].': '.$user['birthday'].'<br />';
		echo $lang['Karma'].': '.$user['karma'];
		if (isset($u['id']) and $u['id'] != $id) {
			//echo ' <a href="?act=vote&amp;id='.$id.'&amp;type=1"><img src="../images/minus.png"></a> <a href="?act=vote&amp;id='.$id.'&amp;type=2"><img src="../images/plus.png"></a>';
		}
			echo ' <a href="?act=rate&amp;id='.$user['id'].'"><image src="../images/arrow_down.png" alt="arrow_down" /></a><a href="?act=rate&amp;id='.$user['id'].'&amp;ok=1""><image src="../images/arrow_up.png" alt="arrow_up" /></a> <a href="main.php?act=karma&amp;user='.$user['username'].'""><image src="../images/share.png" alt="share" /></a>';

		echo '<br />';
		if ($user['icq']) echo '<img src="http://web.icq.com/whitepages/online?icq='.$user['icq'].'&amp;img=27" alt="icq" /> ICQ: '.$user['icq'].'<br />';
		if ($user['skype']) echo '<img src="http://mystatus.skype.com/smallicon/'.$user['skype'].'" alt="skype" /> Skype: '.$user['skype'].'<br />';
		if ($user['site']) echo 'Wap-site: <a href="http://'.$user['site'].'" target="_blank" />'.$user['site'].'</a><br />';
		if ($user['about']) echo $lang['about_myself'].': '.$user['about'].'<br />';

		echo $lang['Registration'].': '.ccdate($user['regtime'], 0).'<br />';
		$banhist = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `ban` WHERE `id_user` = '$id'"), 0);
		echo '<a href="?act=banhist&amp;id='.$id.'">Строгих нарушений: '.$banhist.'</a><br />';
		echo '<a href="?act=ftopics&amp;id='.$id.'">'.$lang['forum'].'</a> (<a href="?act=fposts&amp;id='.$id.'">'.$lang['posts'].'</a>) / <a href="?act=lfiles&amp;id='.$id.'">ЗЦ</a> (<a href="../loads/index.php?act=comm_by&amp;id='.$id.'">'.$lang['comm'].'</a>)';

		echo '<hr>';
		if (isset($u['id'])) {
			if ($u['id'] == $id) {
				echo '<a href="main.php?act=edit">'.$lang['profile'].'</a>, <a href="main.php?act=set">'.$lang['settings'].'</a>';
			} else {
				echo '';
				$friend_r = mysql_query("SELECT `id` FROM `my_friends` WHERE `id_user` = '$id' and `is_friend_of` = ".$u['id']." ");
				$blacklist_r = mysql_query("SELECT `id` FROM `blacklist` WHERE `id_user` = '$id' and `blacklisted_by` = ".$u['id']." ");
				if (mysql_num_rows($friend_r)) {
					echo '<a href="main.php?act=send&amp;id='.$id.'">Написать</a> вашему другу';
				} elseif (mysql_num_rows($blacklist_r)) {
					echo 'В <a href="main.php?act=blacklist">черном списке</a>';
				} else {
					echo '<a href="main.php?act=send&amp;id='.$id.'">Написать</a>, <a href="?act=addfriend&amp;id='.$id.'">в друзья</a> | <a href="?act=blacklist&amp;id='.$id.'">Х</a>';
				}
			}
		}

		if (access(1)) {
			$lang['for_n_sec'] = str_replace('%n%', $config['kick'], $lang['for_n_sec']);
			echo '<br />
			- <a href="?act=kick&amp;id='.$user['id'].'">'.$lang['Kick'].'</a> ('.$lang['for_n_sec'].')<br />';
			if (access(2)) echo '- <a href="../panel/ban.php?user='.$user['username'].'">Забанить</a>, <a href="?act=delmsg&amp;id='.$id.'">удалить</a><br />';
			if (access(3)) echo '- <a href="../panel/users.php?act=edit&amp;id='.$user['id'].'">Редактировать</a>';
		}
		echo '</div>';
    break;
	
	case 'kick':
		if (($u['access'] > $user['access']) or $u['id'] == 1) {
			$ban_r = mysql_num_rows(mysql_query("SELECT `id` FROM `ban` WHERE `id_user` = '$user[id]' and `until` > '".TIME."'"));
			if (!$ban_r) {
				$until = $config['kick'] + TIME;
				mysql_query("INSERT INTO `ban` SET `id_user` = '$user[id]', `until` = '$until', `by` = '$u[id]'");
				
			}
		}
		redirect('?id='.$user['id']);
	break;
	
	case 'rate':
		require_once '../includes/rate.php';
	break;

	case 'ftopics':
        $total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_user` = '$id'"), 0);
        if ($total > 0) {
            tp('<a href="?id='.$id.'">Профиль</a>&raquo; все темы '.username($id, 1));
			echo '<div class="body">';
            $pages = ceil($total / $config['onpage']);
            if ($page > $pages or $page == 0) {
                $page = 1;
            }
            $begin = ($page - 1) * $config['onpage'];

            $topics_r = mysql_query("SELECT * FROM `forum_topics` WHERE `id_user` = '$id' ORDER BY `last_time` DESC LIMIT $begin, $config[onpage]");
            while ($topic = mysql_fetch_assoc($topics_r)) {
                if ($topic['stuck']) echo '!';
                if ($topic['closed'] == 1 and empty($topic['stuck'])) echo '#';
                $t_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$topic[id]'"), 0);
                // getting last user id from forum_msg
                $last_user_r = mysql_query("SELECT `id_user` FROM `forum_msg` WHERE `id_topic` = '$topic[id]' ORDER BY `time` DESC LIMIT 1");
                $last_user = mysql_fetch_assoc($last_user_r);
                // output
                echo '<a href="../forum/topic.php?id='.$topic['id'].'">'.$topic['title'].'</a> ('.$t_msg.') '.login($last_user['id_user']).'<a href="../forum/topic.php?act=end&amp;id='.$topic['id'].'">&raquo;&raquo;</a><br />';
            }
            navig($page, '?act=ftopics&amp;id='.$id.'&amp;', $pages);
        } else {
            error($lang['nothing_yet']);
        }
        echo '<br /><a href="?id='.$id.'">В профиль</a></div>';
    break;
	
	case 'fposts':
        $total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_user` = '$id'"), 0);
        if ($total > 0) {
			tp('<a href="?id='.$id.'">Профиль</a>&raquo; cообщения '.username($id, 1));
            $pages = ceil($total / $config['onpage']);
            if ($page > $pages or $page == 0) {
            	$page = 1;
            }
            $begin = ($page - 1) * $config['onpage'];

            $msg_r = mysql_query("SELECT * FROM `forum_msg` WHERE `id_user` = '$id' ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
            while ($msg = mysql_fetch_assoc($msg_r)) {
                echo '<div class="row"><a href="../forum/topic.php?id='.$msg['id_topic'].'">'.bb($msg['text']).'</a></div>';
            }
        }
		echo '<div class="body">';
		navig($page, '?act=fposts&amp;id='.$id.'&amp;', $pages);
		echo '<a href="?id='.$id.'">В профиль</a></div>';
    break;
	
	case 'lfiles':
        $total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads` WHERE `id_user` = '$id'"), 0);
        if ($total > 0) {
            echo '<div class="title">Все загрузки '.username($id, 1).'</div><div class="list">';
            $pages = ceil($total / $config['onpage']);
            if ($page > $pages or $page == 0) {
                $page = 1;
            }
            $begin = ($page - 1) * $config['onpage'];

            $loads_r = mysql_query("SELECT * FROM `loads` WHERE `id_user` = '$id' ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
            while ($load = mysql_fetch_assoc($loads_r)) {
				if (!isset($num) ) $num = 1;  
				$num++;
				$row_class = (!($num % 2)) ? 'row1' : 'row2';	
				
				$comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads_comm` WHERE `id_loads` = '$load[id]'"), 0);
				$subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_subcats` WHERE `id` = '$load[id_subcat]'"));

				echo '<div class="'.$row_class.'">
				<a href="loads.php?act=view&amp;id='.$load['id'].'">'.$load['name'].'</a> ('.size(filesize('inc/loads/'.$subcat['path'].'/'.$load['file'])).')';
				echo '<br />Комментарий: '.$comm.'<br />
				</div>';
            }
            navig($page, '?act=lfiles&amp;id='.$id.'&amp;', $pages);
        } else {
            error($lang['nothing_yet']);
        }
        nav('?id='.$id);
    break;
	
	case 'addfriend':
		if ($id !== $u['id']) {
			$friend_r = mysql_query("SELECT `id` FROM `my_friends` WHERE `id_user` = '$id' and `is_friend_of` = ".$u['id']." ");
			if (!mysql_num_rows($friend_r)) {
				$blacklist_r = mysql_query("SELECT `id` FROM `blacklist` WHERE `id_user` = '$id' and `blacklisted_by` = ".$u['id']." ");
				if (!mysql_num_rows($blacklist_r)) {
					mysql_query("INSERT INTO `my_friends` SET `id_user` = '$id', `is_friend_of` = ".$u['id']." ");
				} else {
					$_SESSION['note'] = 'Этот юзер у вас в черном списке.';
				}
			}
		}
		redirect('?id='.$id);
	break;
	
	case 'blacklist':
		if ($id !== $u['id']) {
			$blacklist_r = mysql_query("SELECT `id` FROM `blacklist` WHERE `id_user` = '$id' and `blacklisted_by` = ".$u['id']." ");
			if (!mysql_num_rows($blacklist_r)) {
				$friend_r = mysql_query("SELECT `id` FROM `my_friends` WHERE `id_user` = '$id' and `is_friend_of` = ".$u['id']." ");
				if (!mysql_num_rows($friend_r)) {
					mysql_query("INSERT INTO `blacklist` SET `id_user` = '$id', `blacklisted_by` = ".$u['id']." ");
				} else {
					mysql_query("DELETE FROM `my_friends` WHERE `id_user` = '$id' and `is_friend_of` = '$u[id]'");
					mysql_query("INSERT INTO `blacklist` SET `id_user` = '$id', `blacklisted_by` = ".$u['id']." ");
					$_SESSION['note'] = 'Юзер теперь не ваш друг, он в черном списке.';
				}
			}
		}
		redirect('?id='.$id);
	break;
	
	case 'vote':
		if ($u['id'] and $u['id'] != $id) {
			$query = mysql_query("SELECT `id` FROM `voting` WHERE `type` = 'profile' and `id_who` = '$u[id]' and `id_for` = '$id'");
			if (!mysql_num_rows($query)) {
				$type = abs(intval($_GET['type']));
				switch ($type) {
					case '1': $value = -1; sendpm($id, 'Вас минусанули :('); break;
					default: $value = 1; sendpm($id, 'Вас плюсанули :)'); break;
				}
				mysql_query("UPDATE `users` SET `karma` = (`karma`+$value) WHERE `id` = '$id'");
				mysql_query("INSERT INTO `voting` SET `type` = 'profile', `id_who` = '$u[id]', `id_for` = '$id'") or die(mysql_error());
			} else {
				$_SESSION['note'] = 'Вы уже голосовали за этого юзера.';
			}
		}
		redirect('?id='.$id);
	break;
	
	case 'banhist':
		tp('<a href="?id='.$id.'">'.login($id).'</a>&raquo; История банов');
		echo '<div class="body">';
		$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `ban` WHERE `id_user` = '$id'"), 0);
        if ($total > 0) {
            $pages = ceil($total / $config['onpage']);
            if ($page > $pages or $page == 0) {
                    $page = 1;
            }
            $begin = ($page - 1) * $config['onpage'];
						 
			$ban_r = mysql_query("SELECT * FROM `ban` WHERE `id_user` = '$id' ORDER BY `until` DESC LIMIT ".$begin.", ".$config['onpage']."");
			while ($ban = mysql_fetch_assoc($ban_r)) {
				if ($ban['reason']) {
                	echo username($ban['by'], 2).' выдал бан до '.ccdate($ban['until'], 0).'<br />Причина: '.$ban['reason'];
				} else {
                	echo username($ban['by'], 2).' дал пинка этому юзеру';
				}
				echo '<hr>';
			}
		} else {
			echo 'История банов пуста';
		}
		echo '<br /><a href="?id='.$id.'">В профиль</a></div>';
	break;
	
	case 'delmsg':
		if (access(2)) {
			if ($ok) {	
				if ($_POST['del_book']) {
					mysql_query("DELETE FROM `book` WHERE `id_user` = '$id'");
				}
				if ($_POST['del_msg']) {
					mysql_query("DELETE FROM `forum_msg` WHERE `id_user` = '$id'");
				}
				if ($_POST['del_topics']) {
					mysql_query("DELETE FROM `forum_topics` WHERE `id_user` = '$id'");
				}
				if ($_POST['del_notes']) {
					mysql_query("DELETE FROM `blogs` WHERE `id_user` = '$id'");
				}
				if ($_POST['del_cnews']) {
					mysql_query("DELETE FROM `news_comm` WHERE `id_user` = '$id'");
				}
				if ($_POST['del_cblog']) {
					mysql_query("DELETE FROM `blog_comm` WHERE `id_user` = '$id'");
				}
				if ($_POST['del_cdl']) {
					mysql_query("DELETE FROM `loads_comm` WHERE `id_user` = '$id'");
				}
				$_SESSION['note'] = 'Успешно удалено.';
				redirect('?id='.$id);
			} else {
				tp('Что удалить?');
				echo '<div class="body">';
				if (access(3)) echo '- <a href="../panel/users.php?act=del&amp;id='.$user['id'].'"><b>Удалить юзера</b></a><br /><br />';
				echo '<form name="form" action="?act=delmsg&amp;id='.$id.'&amp;ok=1" method="post" name="form">
				<input name="del_book" type="checkbox" value="1" />все сообщ. в гостевой<br />
				<input name="del_msg" type="checkbox" value="1" />все сообщ. форуме<br />
				<input name="del_topics" type="checkbox" value="1" />все темы в форуме<br />
				<input name="del_notes" type="checkbox" value="1" />все записи в блоге<br />
				<input name="del_cnews" type="checkbox" value="1" />все ком. (в новостях)<br />
				<input name="del_cblog" type="checkbox" value="1" />все ком. (в блогах)<br />
				<input name="del_cdl" type="checkbox" value="1" />все ком. (в ЗЦ)<br />
				<input name="submit" type="submit" value="Go!" /></form>';
			}
			echo '<br /><a href="?id='.$id.'">В профиль</a></div>';
		} else {
			redirect(HTTPHOME);
		}
	break;
	
}

require_once '../includes/tail.php';
?>