Просмотр файла wip-site-portal/src/search.php

Размер файла: 9.42Kb
<?
require('ini.php');
$link=connect();

$user=login('nick, search, loc');

@$mod=$_GET['mod'];
@$s = intval($_GET['s']);

head('Добавить/найти');

switch($mod){
	
	default:
		echo '<small>Добавить/найти юзеров<br/>';
		echo '---<br/>';
		echo 'Поиск по нику:<br/>';
		echo 'Ник:</small><br/>';
		echo '<input name="snick'.$ref.'" type="text" maxlength="30"/><br/>';
		echo '<small>---<br/>';
		echo 'Поиск по параметрам: (можно заполнять выборочно)<br/>';
		echo 'Пол:</small>';
		echo '<select name="sex">';
		echo '<option value=""></option>';
		echo '<option value="m">M</option>';
		echo '<option value="zh">Ж</option>';
		echo '</select><br/>';
		echo '<small>Место жительства (код) <a href="help.php?sid='.$sid.'&amp;mod=city">[?]</a>:</small><br/>';
		echo '<input name="city" maxlength="3" format="*N" size="3"/><br/>';
		echo '<small>---<br/>';
		echo 'Если вы хотите искать по следующим параметрам, заполните либо оба поля, либо только поле "От", при этом верхний предел параметра будет неограничен<br/>';
		echo 'Возраст:<br/>';
		echo 'От</small> <input name="start_age" maxlength="2" format="*N" size="2"/> <small>до</small> <input name="end_age" maxlength="2" format="*N" size="2"/><br/>';
		echo '<small>Рост:<br/>';
		echo 'От</small> <input name="start_height" maxlength="3" format="*N" size="3"/> <small>до</small> <input name="end_height" maxlength="3" format="*N" size="3"/><br/>';
		echo '<small>Вес:<br/>';
		echo 'От</small> <input name="start_weight" maxlength="3" format="*N" size="3"/> <small>до</small> <input name="end_weight" maxlength="3" format="*N" size="3"/><br/>';
		echo '<small>---</small><br/>';
		echo '<select name="status">';
		echo '<option value="0">Все юзеры</option>';
		echo '<option value="1">Только онлайн юзеры</option>';
		echo '</select><br/>';
		echo '<small><anchor>Искать<go href="search.php?sid='.$sid.'&amp;mod=search" method="post">';
		echo '<postfield name="snick" value="$(snick'.$ref.')"/>';
		echo '<postfield name="sex" value="$(sex)"/>';
		echo '<postfield name="city" value="$(city)"/>';
		echo '<postfield name="start_age" value="$(start_age)"/>';
		echo '<postfield name="end_age" value="$(end_age)"/>';
		echo '<postfield name="start_height" value="$(start_height)"/>';
		echo '<postfield name="end_height" value="$(end_height)"/>';
		echo '<postfield name="start_weight" value="$(start_weight)"/>';
		echo '<postfield name="end_weight" value="$(end_weight)"/>';
		echo '<postfield name="status" value="$(status)"/>';
		echo '</go></anchor><br/>';
		echo '</small>';
		break;
	
	case 'search':
		@$snick=htmlspecialchars($_POST['snick'],ENT_QUOTES);
		@$sex=($_POST['sex']=='m' or $_POST['sex']=='zh')?$_POST['sex']:false;
		@$city=substr(intval($_POST['city']),0,3);
		@$start_age=substr(intval($_POST['start_age']),0,2);
		@$end_age=substr(intval($_POST['end_age']),0,2);
		@$start_height=substr(intval($_POST['start_height']),0,3);
		@$end_height=substr(intval($_POST['end_height']),0,3);
		@$start_weight=substr(intval($_POST['start_weight']),0,3);
		@$end_weight=substr(intval($_POST['end_weight']),0,3);
		@$status=($_POST['status']==1)?1:0;
		
		$others=($sex or $city or $start_age or $start_height or $start_weight or $end_age or $end_height or $end_weight or $s)?true:false;
		
		//Поиск по нику
		if(!$others and $snick){
			$select=mysql_query("SELECT `id`, `online`, `sex`, `day`, `month`, `year` FROM `wip_users` WHERE `nick`='".$snick."' AND `id`!=1 AND `id`!=3;");
			if(mysql_affected_rows()<1){
				echo '<small>Нет такого юзера</small><br/>';
				break;
			}
			
			$res=mysql_fetch_assoc($select);
			
			$sexx=($res['sex']=='zh')?'Ж':'M';
			
			if($res['day']){
				$tb=mktime(0,0,0,$res['month'],$res['day'],$res['year']);
				$age='-'.floor((time()-$tb)/31536000);
			}
			else $age=false;
			
			echo '<small>Найден: <b>'.$snick.'</b> ['.$sexx.$age.']<br/>';
			echo '<a href="user.php?sid='.$sid.'&amp;uid='.$res['id'].'">Информация и анкета юзера</a><br/>';
			
			mysql_query("select id from wip_contacts where uid='$user[id]' and cid='$res[id]';");
			if(mysql_affected_rows()<1) echo '<a href="contacts.php?sid='.$sid.'&amp;uid='.$res['id'].'&amp;mod=add">Добавить в список контактов</a><br/>';
			else{
				echo '<b>'.$snick.'</b> находится в Вашем списке контактов [<a href="contacts.php?sid='.$sid.'&amp;uid='.$res['id'].'&amp;mod=del">Удалить</a>]<br/>';
				echo '<a href="talk.php?sid='.$sid.'&amp;uid='.$res['id'].'">Чат с '.$snick.'</a><br/>';
			}
			
			echo '</small>';
			break;
		}
		
		/////////
		
		//Если ничего не введено
		if(!$others and !$snick and !$s){
			echo '<small>Вы не заполнили ни одно из полей!</small><br/>';
			break;
		}
		/////////
		
		//Поиск по параметрам
		if($others and !$snick){
			if($city){
				mysql_query("select name from wip_regions where id='$city';");
				if(mysql_affected_rows()<1){
					echo '<small>Введен неверный код региона/страны!<br/>Список доступных кодов Вы можете посмотреть <a href="help.php?mod=city">здесь</a></small><br/>';
				}
			}
			
			//Установка поискового условия
			$cond=false;
			
			if($s) $cond=base64_decode($user['search']);
			else {
				if($sex) $cond.="sex='$sex' and ";
				if($city) $cond.="city='$city' and ";
				if($start_age){
					$start_year=date('Y')-$start_age;
					if($end_age) $end_year=date('Y')-$end_age;
					$cond.="year!=0 and year<='$start_year' and ";
					if($end_age) $cond.="year>='$end_year' and ";
				}
				if($start_height){
					$cond.="height!=0 and height>='$start_height' and ";
					if($end_height) $cond.="height<='$end_height' and ";
				}
				if($start_weight){
					$cond.="weight!=0 and weight>='$start_weight' and ";
					if($end_weight) $cond.="weight<='$end_weight' and ";
				}
				if($status){
					$cond.="online>'".(time()-300)."' and ";
				}
				$cond.="`id`!=1 AND `id`!=3 ORDER BY `rating` DESC, `votes` DESC "; //Спасаемся от возможного and в конце запроса и добавляем сортировку
				#$cond.="`id`!='".$user['id']."' AND `id`!=1 AND `id`!=3 ORDER BY `rating` DESC, `votes` DESC "; //Спасаемся от возможного and в конце запроса и добавляем сортировку
			}
			/////////
			
			# Постраничный вывод
			$slim = 1;
			
			if (!$s or $s<=0) $s=1;
			$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `wip_users` WHERE ".$cond.";"), 0);
			$pgs=ceil($all / $slim);
			if($s > $pgs) $s = $pgs;
			$n = ($s-1) * $slim;
			###
			
			if($all<1){
				echo '<small>К сожалению, по Вашему запросу ничего не найдено. Попробуйте изменить параметры поиска.</small><br/>';
			}
			
			else { 
				$select=mysql_query("SELECT `id`, `nick`, `online`, `sex`, `day`, `month`, `year` FROM `wip_users` WHERE ".$cond." LIMIT ".$n.", ".$slim.";");
				
				mysql_query("update wip_users set search='".base64_encode($cond)."' where id='$user[id]';");
				
				echo '<small>';
				echo 'По запросу найдено найдено '.$all.' '.word_case('юзеров:юзера:юзер', $all).':<br/>---<br/>';
				
				$np = $n+1;
				
				while($res=mysql_fetch_assoc($select)){
					$sexx=($res['sex']=='zh')?'Ж':'M';
				
					if($res['day']){
						$tb=mktime(0, 0 , 0, $res['month'], $res['day'], $res['year']);
						$age='-'.floor((time()-$tb)/31536000);
					}
					else $age=false;
					
					echo $np.') <a href="user.php?sid='.$sid.'&amp;uid='.$res['id'].'">'.$res['nick'].'</a> ['.$sexx.$age.']<br/>';
					
					$np ++;
				}
				
				# Список страниц
				if ($all > $slim){
					echo '---<br/>';
					
					if ($pgs>3 and $s>2) echo '<a href="search.php?sid='.$sid.'&amp;mod=search&amp;s=1">1</a>...';
		
					$beg=$s-1; $end=$s+1;
					if ($end>$pgs+1){
						$end=$pgs; $beg=$beg-2;
					}
					elseif ($end>$pgs){
						$end=$pgs; $beg=$beg-1;
					}
					
					for($m=$beg;$m<=$end;$m++){
						if ($m<=0) $end++;
						
						else{
							if($m==$s) echo '<b>'.$m.'</b>';
							else echo '<a href="search.php?sid='.$sid.'&amp;mod=search&amp;s='.$m.'">'.$m.'</a>';
				
							if($m!=$end) echo '-';
						}
					
						if ($end>$pgs) $end=$pgs;
					}
		
					if ($pgs>3 and $s<=($pgs-2)) echo '...<a href="search.php?sid='.$sid.'&amp;mod=search&amp;s='.$pgs.'">'.$pgs.'</a>';
					
					echo '<br/>';
				}
				
				echo '</small>';
			}
			
		}
		
		break;
}

echo '<small>---<br/>';
if($mod) echo '<a href="search.php?sid='.$sid.'">Изменить условия поиска</a><br/>';
if($user['loc']) echo '<a href="'.$user['loc'].'.php?sid='.$sid.'">'.$locs[$user['loc']].'</a><br/>';
echo '<a href="contacts.php?sid='.$sid.'">Контакт-лист</a><br/>';
echo '<a href="enter.php?sid='.$sid.'">Главное меню</a>';
echo '</small>';
foot();

mysql_close($link);
?>