View file main.php

File size: 13.04Kb
<?php
// by mides, wmclub.mobi

require_once 'system/sys.php';
require_once 'system/auth_u.php';
require_once 'system/header.php';

switch ($_GET['act']) {
	default:
		if ($u['access'] > 0) { 
			tp('Мое меню (<a href="panel">+</a>)');
		} else {
			tp('Мое меню');
		}
		$private = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `private` WHERE `id_user` = '$u[id]'"), 0);
		echo '<a href="profile.php?id='.$u['id'].'">Мой профиль</a> [<a href="?act=edit">ред</a>]<br />
		<a href="?act=my_topics">Мои темы</a>/<a href="?act=my_msg">сообщения</a><br />
		<a href="?act=private">Входящая почта</a> ('.$private.')<br />
		<a href="?act=send">Отправить письмо</a><br />
		<a href="?act=contact">Контакт-лист</a><br />
		<a href="?act=ignor">Игнор-лист</a><br />
		<a href="?act=set">Настройки</a><br />
		<a href="?act=exit">Завершить сенс</a><br />';
		nav_main();
	break;
	
	case 'edit':
		if ($_REQUEST['ok']) {
			if ($_POST['email']) {
				$email = check($_POST['email']);
				$icq = intval($_POST['icq']);
				$name = check($_POST['name']);
				$sex = intval($_POST['sex']);
				$from = check($_POST['from']);
				$birthday = check($_POST['birthday']);
				$site = check($_POST['site']);
				$about = check($_POST['about']);
				if (preg_match('/[0-9a-z_\-]+@[0-9a-z_\-^\.]+\.[a-z]{2,6}/i', $email)) {
					mysql_query("UPDATE `users` SET `email` = '$email', `icq` = '$icq', `name` = '$name', `sex` = '$sex', `from` = '$from', `birthday` = '$birthday', `site` = '$site', `about` = '$about' WHERE `id` = '$u[id]'");
					header('location: ?act=edit');
				} else {
					error('Неверный формат e-mail. Пример: [email protected]');
					nav('?act=edit');
				}
			} else {
				error('Поле "E-mail" обязательное для заполнения.');
				nav('?act=edit');
			}
		} else {
			tp('Ред-ть профиль');
			echo '<form action="?act=edit&amp;ok=1" method="post">
			E-mail(max50)*:<br /><input name="email" type="text" maxlength="50" value="'.$u['email'].'" /><br />
			ICQ(max9):<br /><input name="icq" type="text" maxlength="9" value="'.$u['icq'].'" /><br />
			Имя(max20):<br /><input name="name" type="text" maxlength="20" value="'.$u['name'].'" /><br />
			Пол: ';
			switch ($u['sex']) {
				case '1': echo 'муж<input name="sex" type="radio" value="1" checked /> <input name="sex" type="radio" value="2" />жен'; break;
				case '2': echo 'муж<input name="sex" type="radio" value="1" /> <input name="sex" type="radio" value="2" checked />жен'; break;
				default: echo 'муж<input name="sex" type="radio" value="1" /> <input name="sex" type="radio" value="2" />жен'; break;
			}
			echo '<br />
			Откуда(max25):<br /><input name="from" type="text" maxlength="25" value="'.$u['from'].'" /><br />
			Дата рождения (дд.мм.гггг):<br /><input name="birthday" type="text" maxlength="25" value="'.$u['birthday'].'" /><br />
			Wap-сайт(<del>http://</del>, max20):<br /><input name="site" type="text" maxlength="20" value="'.$u['site'].'" /><br />
			О себе(max250):<br /><textarea name="about" cols="" rows="3">'.$u['about'].'</textarea>
			<input name="submit" type="submit" value="Ok" />
			</form>';
			nav('?');
		}
	break;
	
	case 'my_topics':
		$all_topics = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_user` = '$u[id]'"), 0);
		if ($all_topics > 0) {
			tp('Мои темы');
			$pages = ceil($all_topics / $config['onpage']);
			$page = intval($_GET['p']) ? abs($_GET['p']) : 1;
			$begin = ($page - 1) * $config['onpage'];
			
			$topics_r = mysql_query("SELECT * FROM `forum_topics` WHERE `id_user` = '$u[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);
				// getting last page
				$last_page = ceil($t_msg / $config['onpage']);
				// output
				echo '<a href="forum.php?act=topic&amp;id='.$topic['id'].'">'.$topic['title'].'</a> ('.$t_msg.') '.login($last_user['id_user']).'<a href="forum.php?act=topic&amp;id='.$topic['id'].'&amp;p='.$last_page.'">&raquo;</a><br />';
			}
			navig($page, '?act=my_topics&amp;', $pages);
		} else {
			error('Вы не создали ни одной темы на форуме :(');
		}
		nav('?');
	break;

	case 'my_msg':
		$all_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_user` = '$u[id]'"), 0);
		if ($all_msg > 0) {
			echo '<div class="title">Мои сообщения</div><div class="list">';
			$pages = ceil($all_msg / $config['onpage']);
			$page = intval($_GET['p']) ? abs($_GET['p']) : 1;
			$begin = ($page - 1) * $config['onpage'];
			
			$msg_r = mysql_query("SELECT * FROM `forum_msg` WHERE `id_user` = '$u[id]' ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
			while ($msg = mysql_fetch_assoc($msg_r)) {
				if (!isset($num) ) $num = 1;  
				$num++;
				$row_class = (!($num % 2)) ? 'row1' : 'row2';
				echo '<div class="'.$row_class.'">'.bb($msg['text']).'<a href="forum.php?act=topic&amp;id='.$msg['id_topic'].'">&raquo;</a> </div>';
			}
			navig($page, '?act=my_msg&amp;', $pages);
		} else {
			error('Вы не создали ни одной темы на форуме :(');
		}
		nav('?');
	break;

	case 'private':
		tp('Входящая почта');
		$all_private = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `private` WHERE `id_user` = '$u[id]'"), 0);
		if ($all_private > 0) {
			$pages = ceil($all_private / $config['onpage']);
			$page = intval($_GET['p']) ? abs($_GET['p']) : 1;
			$begin = ($page - 1) * $config['onpage'];
			
			$private_r = mysql_query("SELECT * FROM `private` WHERE `id_user` = '$u[id]' ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
			while ($priv = mysql_fetch_assoc($private_r)) {
				$private_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `private_msg` WHERE `id_private` = '$priv[id]'"), 0);
				echo '<a href="?act=private_view&amp;id='.$priv['id'].'">'.login($priv['id_sender']).'</a> ('.$private_msg.')<br />';
			}
			navig($page, '?act=private', $pages);
		} else {
			echo 'Еще нет входящих сообщений.<br />';
		}
		nav('?');
	break;
	
	case 'private_view':
		$id = intval($_REQUEST['id']);
		$priv_r = mysql_query("SELECT * FROM `private` WHERE `id` = '$id'");
		$priv = mysql_fetch_assoc($priv_r);
		if ($priv['id']) {
			echo '<div class="title">Переписка с '.login($priv['id_sender']).'</div>
			<div class="main">Сообщение(max250):<br />
			<form action="?act=send&amp;id='.$priv['id_sender'].'&amp;ok=1" method="post">
			<input name="login" type="hidden" value="'.login_simple($priv['id_sender']).'" />
			<textarea name="text" cols="" rows="3"></textarea>';
			echo '<input name="" type="submit" value="Добавить">
			</form>
			</div>';
			$pages = ceil($all_private / $config['onpage']);
			$page = intval($_GET['p']) ? abs($_GET['p']) : 1;
			$begin = ($page - 1) * $config['onpage'];
			
			navig($page, '?act=private_view&amp;id='.$id.'&amp;', $pages);
			
			echo '</div><div class="list">';
				
			$msg_r = mysql_query("SELECT * FROM `private_msg` WHERE `id_private` = '$priv[id]' ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
			while ($msg = mysql_fetch_assoc($msg_r)) {
				if (!isset($num) ) $num = 1;  
				$num++;
				$row_class = (!($num % 2)) ? 'row1' : 'row2';	
				echo '<div class="'.$row_class.'">'.login($msg['id_user']).' ('.date('d.m.y, H:i', $msg['time']).')<br />'.bb($msg['text']).'</div>';
			}
			navig($page, '?act=private_view&amp;id='.$id.'&amp;', $pages);
		}
		nav('?act=private');
	break;
		
	case 'send':
		if ($_REQUEST['ok']) {
			if ($_POST['login'] and $_POST['text']) {
				$login = check($_POST['login']);
				$text = check($_POST['text']);
				$id_user = get_id($login);
				if ($id_user > 0) {
					$priv_r = mysql_query("SELECT `id` FROM `private` WHERE `id_user` = '$id_user' and `id_sender` = '$u[id]'");
					$priv = mysql_fetch_assoc($priv_r);
					if ($priv['id']) {
						mysql_query("UPDATE `private` SET `time` = '".time()."'");
						$id_private = $priv['id'];
					} else {
						mysql_query("INSERT INTO `private` SET `id_user` = '$id_user', `id_sender` = '$u[id]', `time` = '".time()."'");
						$id_private = mysql_insert_id();
					}
					mysql_query("INSERT INTO `private_msg` SET `id_private` = '$id_private', `id_user`  ='$u[id]', `text` = '$text', `time` = '".time()."'");
					header('location: ?act=private_view&id='.$id_private);
				} else {
					error('Пользователь, которому вы хотите отправить письмо, не существует.');
				}
			} else {
				error('Вы не заполнили поля.');
			}
		} else {
			$id = intval($_REQUEST['id']);
			if ($id) $login = login_simple($id);
			tp('Отправить письмо');
			echo '<form action="?act=send&amp;ok=1" method="post" name="form">
			Кому(max12):<br /><input name="login" type="text" value="'.$login.'" maxlength="12" /><br />
			Сообщение(max250):<br /><textarea name="text" cols="" rows="4"></textarea><br />
			<input name="submit" type="submit" value="Ok" />
			</form>';
		}
		nav('?');
	break;
	
	case 'contact':
		tp('Мои контакты');
		$all_contacts = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `contacts` WHERE `is_contact_for` = '$u[id]'"), 0);
		if ($all_contacts > 0) {
			$pages = ceil($all_contacts / $config['onpage']);
			$page = intval($_GET['p']) ? abs(intval($_GET['p'])) : 1;
			$begin = ($page - 1) * $config['onpage'];
			
			$contact_r = mysql_query("SELECT * FROM `contacts` WHERE `is_contact_for` = '$u[id]' ORDER BY `id` DESC LIMIT $begin, $config[onpage]");
			while ($contact = mysql_fetch_assoc($contact_r)) {
				echo '<a href="profile.php?id='.$contact['id_user'].'">'.login($contact['id_user']).'</a> (<a href="?act=send&amp;id='.$contact['id_user'].'">приват</a>, <a href="?act=contact&amp;del='.$contact['id'].'">уд</a>)<br />';
			}
			navig($page, '?act=contact&amp;', $pages);
			if ($_REQUEST['del']) {
				$id_contact = intval($_REQUEST['del']);
				$contact_r = mysql_query("SELECT `id` FROM `contacts` WHERE `id` = '$id_contact' and `is_contact_for` = '$u[id]'");
				if (mysql_num_rows($contact_r)) {
					mysql_query("DELETE FROM `contacts` WHERE `id` = '$id_contact'");
				}
				header('location: ?act=contact');
			}
		} else {
			echo 'Пусто.<br />';
		}
		nav('?');
	break;
	
	case 'ignor':
		tp('Игнор-лист');
		$all_ignores = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `ignores` WHERE `is_ignored_for` = '$u[id]'"), 0);
		if ($all_ignores > 0) {
			$pages = ceil($all_ignores / $config['onpage']);
			$page = intval($_GET['p']) ? abs(intval($_GET['p'])) : 1;
			$begin = ($page - 1) * $config['onpage'];
			
			$ignor_r = mysql_query("SELECT * FROM `ignores` WHERE `is_ignored_for` = '$u[id]' ORDER BY `id` DESC LIMIT $begin, $config[onpage]");
			while ($ignor = mysql_fetch_assoc($ignor_r)) {
				echo '<a href="profile.php?id='.$ignor['id_user'].'">'.login($ignor['id_user']).'</a> (<a href="?act=send&amp;id='.$ignor['id_user'].'">приват</a>, <a href="?act=ignor&amp;del='.$ignor['id'].'">уд</a>)<br />';
			}
			navig($page, '?act=contact&amp;', $pages);
			if ($_REQUEST['del']) {
				$id_ignored = intval($_REQUEST['del']);
				$ignor_r = mysql_query("SELECT `id` FROM `ignores` WHERE `id` = '$id_ignored' and `is_ignored_for` = '$u[id]'");
				if (mysql_num_rows($ignor_r)) {
					mysql_query("DELETE FROM `ignores` WHERE `id` = '$id_ignored'");
				}
				header('location: ?act=ignor');
			}
		} else {
			echo 'Пусто.<br />';
		}
		nav('?');
	break;
		
	case 'set':
		if ($_REQUEST['ok']) {
			if ($_POST['onpage']) {
				$onpage = intval($_POST['onpage']);
				mysql_query("UPDATE `users` SET `onpage` = '$onpage' WHERE `id` = '$u[id]'");
				header('location: ?act=set');
			} else {
				error('Вы не заполнили поле.');
				nav('?act=set');
			}
		} else {
			tp('Настройки');
			echo '<form action="?act=set&amp;ok=1" method="post">
			Элементов на страницу(1-99):<br /><input name="onpage" type="text" maxlength="2" value="'.$u['onpage'].'" /><br />
			<input name="submit" type="submit" value="Ok" />
			</form>';
			nav('?');
		}
	break;
	
	case 'exit':
		mysql_query("DELETE FROM `online` WHERE `id_user` = '$u[id]'");
		setcookie('ulogin', '', time() - 86400*31);
		setcookie('upassword', '', time() - 86400*31);
		header('location: ./');
	break;

}

require_once 'system/tail.php';
?>