<?php

require_once '../incfiles/core.php';
require_once '../incfiles/func.php';
require_once '../incfiles/auth.php';
require_once '../incfiles/user.php';

if (empty($user_id)) {go(URL.'/');}

$title = lang('Поиск','Пошук');
require_once '../incfiles/head.php';
?>
<script type="text/javascript">
$(function(){
	$('#form').on('submit', function(e){
	Page.Loading('start');
    e.preventDefault();
    var $that = $(this),
        formData = new FormData($that.get(0));
    $.ajax({
      url: $that.attr('action'),
      type: $that.attr('method'),
      contentType: false,
      processData: false,
      data: formData,
      success: function(response){
        if(response){
 			$('.content').html(response);
			Page.Loading('stop');
      }
     }
    });
  });
});
</script>
<?
$act = htmlentities(trim($_GET['act']));

echo '<div class="title"><center>'.lang('Тип поиска','Тип пошуку').'</center></div>';
echo'<div class="title">
	<a href="'.URL.'/search/" onclick="Page.Go(this.href); return false;">'.lang('Музыка','Музика').'</a>
	<a href="'.URL.'/search/?act=video" onclick="Page.Go(this.href); return false;">'.lang('Видеозаписи','Відеозапис').'</a>
	<a href="'.URL.'/search/?act=soo" onclick="Page.Go(this.href); return false;">'.lang('Сообщества','Спільноти').'</a>
	<a href="'.URL.'/search/?act=news" onclick="Page.Go(this.href); return false;">'.lang('Поиск новостей','Пошук новин').'</a>
	</div>';
switch($act)
{
default:
echo '<div class="title"><center>'.lang('Музыка','Музика').'</center></div>';

if (!empty($_REQUEST['search']) && mb_strlen(check($_REQUEST['search']))>2) $search = substr(check($_REQUEST['search']),0,100);
	
?>
<script type="text/javascript">
$(function(){
	$('#form').on('submit', function(e){
	Page.Loading('start');
    e.preventDefault();
    var $that = $(this),
        formData = new FormData($that.get(0));
    $.ajax({
      url: $that.attr('action'),
      type: $that.attr('method'),
      contentType: false,
      processData: false,
      data: formData,
      success: function(response){
        if(response){
 			$('.content').html(response);
       }
		Page.Loading('stop');
     }
    });
  });
});
</script>
<?
										echo '<div class="title">	
											<div class="block2">
	<form id="form" action="'.URL.'/search/index.php" method="post">
	<input class="input2" style="width:70%" type="text" name="search" value="'.$search.'"/>
	<input class="button2" type="submit" value="'.lang('Поиск','Пошук').'"/>
	</form>
	</div></div>';	
	
	if(!empty($search))
	{
$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `audio` WHERE `artist` LIKE '%".$search."%'"),0);
if ($all > 0)
{
	$cp = ceil($all/10);
	$p = (isset($_GET['p']) and is_numeric($_GET['p']) and $_GET['p']>1 and $_GET['p']<=$cp) ? $_GET['p'] : 1;
	$start = $p*10-10;
	$res = mysql_query("SELECT * FROM `audio` WHERE `artist` LIKE '%".$search."%' ORDER by `artist` DESC LIMIT $start,100");
	while ($arr = mysql_fetch_array($res))
			{
				
		echo '<div class="block">'.track($arr['id']).'<div class="right"><a href="'.URL.'/audio/add.php?id=track_'.$arr['id'].'" onclick="Page.Go(this.href); return false"><img src="'.URL.'/design/img/adds.png"/></a></div></div>';
				echo'</div>';
			}

	navi($p,$cp,'/search/index.php?');
}
		else echo '<div class="block">'.lang('По Вашему запросу ничего не найдено','За Вашим запитом нічого не знайдено').'</div>';

	}
break;
case 'soo';

if (!empty($_REQUEST['search']) && mb_strlen(check($_REQUEST['search']))>2) $search = substr(check($_REQUEST['search']),0,100);
	
?>
<script type="text/javascript">
$(function(){
	$('#form').on('submit', function(e){
	Page.Loading('start');
    e.preventDefault();
    var $that = $(this),
        formData = new FormData($that.get(0));
    $.ajax({
      url: $that.attr('action'),
      type: $that.attr('method'),
      contentType: false,
      processData: false,
      data: formData,
      success: function(response){
        if(response){
 			$('.content').html(response);
       }
		Page.Loading('stop');
     }
    });
  });
});
</script>
<?
				
echo '<div class="title"><center>'.lang('Сообщества','Спільноти').'</center></div>';				

								echo '<div class="title">	
											<div class="block2">
	<form id="form" action="'.URL.'/search/index.php?act=soo&" method="post">
	<input class="input2" style="width:70%" type="text" name="search" value="'.$search.'"/>
	<input class="button2" type="submit" value="'.lang('Поиск','Пошук').'"/>
	</form>
	</div></div>';	
	
	if(!empty($search))
	{
$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `groups` WHERE `name` LIKE '%".$search."%'"),0);
if ($all > 0)
{
	$cp = ceil($all/10);
	$p = (isset($_GET['p']) and is_numeric($_GET['p']) and $_GET['p']>1 and $_GET['p']<=$cp) ? $_GET['p'] : 1;
	$start = $p*10-10;
	$res = mysql_query("SELECT * FROM `groups` WHERE `name` LIKE '%".$search."%' ORDER by `count_users` DESC LIMIT $start,10");
	while ($arr = mysql_fetch_array($res))
			{
				
		echo '<div class="block">'.group_name($arr['id']).'</div>';
				echo'</div>';
			}

	navi($p,$cp,'/search/index.php?act=soo');
}
		else echo '<div class="block">'.lang('По Вашему запросу ничего не найдено','За Вашим запитом нічого не знайдено').'</div>';

	}
break;

case 'video';

echo '<div class="title"><center>'.lang('Видеозаписи','Відеозаписи').'</center></div>';		



if (!empty($_REQUEST['search']) && mb_strlen(check($_REQUEST['search']))>2) $search = substr(check($_REQUEST['search']),0,100);
	
?>
<script type="text/javascript">
$(function(){
	$('#form').on('submit', function(e){
	Page.Loading('start');
    e.preventDefault();
    var $that = $(this),
        formData = new FormData($that.get(0));
    $.ajax({
      url: $that.attr('action'),
      type: $that.attr('method'),
      contentType: false,
      processData: false,
      data: formData,
      success: function(response){
        if(response){
 			$('.content').html(response);
       }
		Page.Loading('stop');
     }
    });
  });
});
</script>
<?
										echo '<div class="title">	
											<div class="block2">
	<form id="form" action="'.URL.'/search/index.php?act=video&" method="post">
	<input class="input2" style="width:70%" type="text" name="search" value="'.$search.'"/>
	<input class="button2" type="submit" value="'.lang('Поиск','Пошук').'"/>
	</form>
	</div></div>';	
	
	if(!empty($search))
	{
$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `video` WHERE `name` LIKE '%".$search."%'"),0);
if ($all > 0)
{
	$cp = ceil($all/10);
	$p = (isset($_GET['p']) and is_numeric($_GET['p']) and $_GET['p']>1 and $_GET['p']<=$cp) ? $_GET['p'] : 1;
	$start = $p*10-10;
	$res = mysql_query("SELECT * FROM `video` WHERE `name` LIKE '%".$search."%' ORDER by `name` DESC LIMIT $start,10");
	while ($arr = mysql_fetch_array($res))
			{
			echo '<a href="/video/view.php?id_video='.$arr['id'].'"" onclick="Page.Go(this.href); return false"><img class="preview_mini" src="/files/screen/'.$arr['dir'].'/'.$arr['name'].'.jpg"></a>';
	
		//echo '<div class="block">'.trackv($arr['id']).'<div class="right"><a href="'.URL.'/video/add.php?id=track_'.$arr['id'].'" onclick="Page.Go(this.href); return false"><img src="'.URL.'/design/img/adds.png"/></a></div></div>';
				echo'</div>';
			}

	navi($p,$cp,'/search/index.php?act=video');
}
		else echo '<div class="block">'.lang('По Вашему запросу ничего не найдено','За Вашим запитом нічого не знайдено').'</div>';

	}
	
break;
case 'news';

echo '<div class="title"><center>'.lang('Новости','Новини').'</center></div>';		

if (!empty($_REQUEST['search']) && mb_strlen(check($_REQUEST['search']))>2) $search = substr(check($_REQUEST['search']),0,100);
	
?>
<script type="text/javascript">
$(function(){
	$('#form').on('submit', function(e){
	Page.Loading('start');
    e.preventDefault();
    var $that = $(this),
        formData = new FormData($that.get(0));
    $.ajax({
      url: $that.attr('action'),
      type: $that.attr('method'),
      contentType: false,
      processData: false,
      data: formData,
      success: function(response){
        if(response){
 			$('.content').html(response);
       }
		Page.Loading('stop');
     }
    });
  });
});
</script>
</div>

</ul></div>
	
	<?php	
	
	echo'
	<div class="block2">
	<form id="form" action="'.URL.'/search/index.php?act=news&" method="post">
	<input class="input2" style="width:70%" type="text" name="search" value="'.$search.'"/>
	<input class="button2" type="submit" value="'.lang('Поиск','Пошук').'"/>
	</form>
	</div>';
	

	
		
	if(!empty($search))
	{
		$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `wall` WHERE `text` LIKE '%".$search."%'"),0);
		if ($all > 0)
		{		
			$cp = ceil($all/10);
			$p = (isset($_GET['p']) and is_numeric($_GET['p']) and $_GET['p']>1 and $_GET['p']<=$cp) ? $_GET['p'] : 1;
			$start = $p*10-10;

			$res = mysql_query("SELECT * FROM `wall` WHERE `text` LIKE '%".$search."%' ORDER by `time` DESC LIMIT $start,10");
			while ($arr = mysql_fetch_array($res))
			{
				echo wall_post($arr,0,$search);
			}
			navi($p,$cp,'/feed/search.php?');
		}
		else echo '<div class="block">'.lang('По Вашему запросу ничего не найдено','За Вашим запитом нічого не знайдено').'</div>';
	}
	else
	{
		$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `wall` WHERE `type` = 'post'"),0);
		if ($all > 0)
		{		
			$cp = ceil($all/10);
			$p = (isset($_GET['p']) and is_numeric($_GET['p']) and $_GET['p']>1 and $_GET['p']<=$cp) ? $_GET['p'] : 1;
			$start = $p*10-10;

			$res = mysql_query("SELECT * FROM `wall` WHERE `type` = 'post' ORDER by `time` DESC LIMIT $start,10");
			while ($arr = mysql_fetch_array($res))
			{
				echo wall_post($arr);
			}
			navi($p,$cp,'/search/index.php?act=news&'.(!empty($search)?$search.'&':''));
		}
		else echo '<div class="block">'.lang('По Вашему запросу ничего не найдено','За Вашим запитом нічого не знайдено').'</div>';
	}
	


break;

}



require_once '../incfiles/foot.php';