<?
require('../include/path.php');
function put_content(){
global $path,$user;
$ps=(isset($_GET['ps']) && !preg_match('/[^0-9]/',$_GET['ps']))?$_GET['ps']:0;
echo '<div class="title">Файлобменник</div>';
echo '<div class="header">Поиск</div>';
$size=array(1=>'10240',2=>'51200',3=>'102400',4=>'512000',5=>'1048576');
$loads=array(1=>'1',2=>'10',3=>'50',4=>'100',5=>'500');
$times=array('86400'=>'за последние сутки','259200'=>'за последние 3 суток','604800'=>'за последнюю неделю','2592000'=>'за последний месяц');
$fields=array(1=>'file_title',2=>'file_description');
require($path.'/manage/ctype.php');
if(isset($_REQUEST['select'])){
$onpage=10;
$text=(isset($_REQUEST['text']) && preg_match('/.{2,25}/iUD',$_REQUEST['text']))?$_REQUEST['text']:false;
$field=(isset($_REQUEST['field']) && array_key_exists($_REQUEST['field'],$fields))?$_REQUEST['field']:1;
$ftype=(isset($_REQUEST['ft']) && array_key_exists($_REQUEST['ft'],$ctype))?$_REQUEST['ft']:false;
$fsize=(isset($_REQUEST['fs']) && array_key_exists($_REQUEST['fs'],$size))?$_REQUEST['fs']:false;
$floads=(isset($_REQUEST['fl']) && array_key_exists($_REQUEST['fl'],$loads))?$_REQUEST['fl']:false;
$fdate=(isset($_REQUEST['fd']) && array_key_exists($_REQUEST['fd'],$times))?$_REQUEST['fd']:false;
$fuser=(isset($_REQUEST['fuser']))?$_REQUEST['fuser']:false;
if($ftype) $term[]="file_exp='".$ftype."'";
if($fsize) $term[]="file_size<".$size[$fsize];
if($floads) $term[]="file_downloads>".$loads[$floads];
if($fdate) $term[]="file_date>'".date('Y-m-d H:i:s',time()-$fdate)."'";
if($fuser) $term[]="user='".filtr(MyDecode($fuser))."'";
if($text){
$tmptext=filtr($text);
$query1="SELECT COUNT(file_id) FROM `".PRE."dc_files` WHERE (".$fields[$field]." LIKE '%".str_replace(" ", "%' OR ".$fields[$field]." LIKE '%", $text)."%') ".((isset($term))?"AND ".implode(' AND ',$term):"");
$query2="SELECT file_id,user,file_name,file_exp,file_title,file_description,DATE_FORMAT(file_date,'%d.%m.%Y') as date,file_size,file_downloads,count_com, IF (".$fields[$field]." LIKE '%".$tmptext."%', 3*10, 0) + IF (".$fields[$field]." LIKE '%".str_replace(" ", "%', 9, 0) + IF (".$fields[$field]." LIKE '%", $tmptext)."%', 9, 0) AS relev FROM files WHERE (".$fields[$field]." LIKE '%".str_replace(" ", "%' OR ".$fields[$field]." LIKE '%", $tmptext)."%') ".((isset($term))?"AND ".implode(' AND ',$term):"")." ORDER BY relev DESC LIMIT ".($onpage*$ps).",".$onpage;
}elseif(isset($term)){
$query1="SELECT COUNT(file_id) FROM `".PRE."dc_files` WHERE ".implode(' AND ',$term);
$query2="SELECT file_id,user,file_name,file_exp,file_title,file_description,DATE_FORMAT(file_date,'%d.%m.%Y') as date,file_size,file_downloads,count_com FROM `".PRE."dc_files` WHERE ".implode(' AND ',$term)." ORDER BY file_downloads DESC LIMIT ".($onpage*$ps).",".$onpage;
}
if(isset($query1)){
if($result=sql_query($query1)){
$row=mysql_fetch_row($result);
if($row[0]){
$pagCoun=ceil($row[0]/$onpage);
$interv=5; $sint=($interv-1)/2; $limn=$sint; $lime=$pagCoun-$sint;
if($result=sql_query($query2)){
while($row=mysql_fetch_assoc($result)){
echo '<div class="header"><a href="'.$row['file_id'].'.'.$row['file_exp'].'">'.$row['file_title'].'</a><br><small>Тип: '.$row['file_exp'].'</small></div>';
if(preview($row['file_exp'])){
echo '<img src="/files/thumbnails/'.$row['file_name'].'.'.$row['file_exp'].'" alt=""/>';
}elseif(file_exists($path.'/files/thumbnails/'.$row['file_exp'].'/'.$row['file_name'].'.jpg')){
echo '<img src="/files/thumbnails/'.$row['file_exp'].'/'.$row['file_name'].'.jpg" alt=""/>';
}elseif(file_exists($path.'/files/thumbnails/'.$row['file_exp'].'/'.$row['file_name'].'.gif')){
echo '<img src="/files/thumbnails/'.$row['file_exp'].'/'.$row['file_name'].'.gif" alt=""/>';
}
echo '<br><a href="'.$row['file_id'].'.'.$row['file_exp'].'">скачать</a>';
if($row['file_exp']=='jar' && file_exists($path.'/files/jar/'.$row['file_name'].'.jad')){ echo ' <a href="java/'.$row['file_id'].'.jad">jad</a><br>'; }
echo '<small>';
if($row['file_description']){ echo '<br>Описание:<br>'.bbc($row['file_description']); }
echo '<br>Размер: '.round($row['file_size']/1024).' KB';
echo '<br>Скачано: '.$row['file_downloads'];
$author=$row['user'];
echo '<br>Добавил: '.(($author!='Гость')?'<a href="inf.php?login='.MyEncode($author).'&page=1&select&field='.$field.'&'.(($text)?'text='.rawurlencode($text).'&':'').(($ftype)?'ft='.$ftype.'&':'').(($fsize)?'fs='.$fsize.'&':'').(($floads)?'fl='.$floads.'&':'').(($fdate)?'fd='.$fdate.'&':'').'ps='.$ps.'&'.((isset($_GET['back']))?'back&':'').SID.'">'.$author.'</a>':$author);
echo '<br>Дата: '.$row['date'];
echo '<br><a href="comments.php?file='.$row['file_id'].'&page=1&select&field='.$field.'&'.(($text)?'text='.rawurlencode($text).'&':'').(($ftype)?'ft='.$ftype.'&':'').(($fsize)?'fs='.$fsize.'&':'').(($floads)?'fl='.$floads.'&':'').(($fdate)?'fd='.$fdate.'&':'').'ps='.$ps.'&'.SID.'">Комментарии</a> ('.$row['count_com'].')';
echo '</small>';
}
if($pagCoun>1){ echo'<div class="nav">Стр ';
if($ps>0) {echo '<a href="?select&field='.$field.'&'.(($text)?'text='.rawurlencode($text).'&':'').(($ftype)?'ft='.$ftype.'&':'').(($fsize)?'fs='.$fsize.'&':'').(($floads)?'fl='.$floads.'&':'').(($fdate)?'fd='.$fdate.'&':'').'ps='.($ps-1).'&'.SID.'"><<</a> '; }
if($interv>=$pagCoun) { for($i=1;$i<=$pagCoun;$i++) { if (($i-1)==$ps) { echo $i.' ';} else { echo '<a href="?select&field='.$field.'&'.(($text)?'text='.rawurlencode($text).'&':'').(($ftype)?'ft='.$ftype.'&':'').(($fsize)?'fs='.$fsize.'&':'').(($floads)?'fl='.$floads.'&':'').(($fdate)?'fd='.$fdate.'&':'').'ps='.($i-1).'&'.SID.'">'.$i.'</a> '; } }
} else {
if($ps<=$limn) { for($i=1;$i<=$interv;$i++) { if (($i-1)==$ps) { echo $i.' ';} else { echo '<a href="?select&field='.$field.'&'.(($text)?'text='.rawurlencode($text).'&':'').(($ftype)?'ft='.$ftype.'&':'').(($fsize)?'fs='.$fsize.'&':'').(($floads)?'fl='.$floads.'&':'').(($fdate)?'fd='.$fdate.'&':'').'ps='.($i-1).'&'.SID.'">'.$i.'</a> '; }}}
elseif($ps>=$lime) { for($i=$pagCoun-$interv+1;$i<=$pagCoun;$i++) { if (($i-1)==$ps) { echo $i.' ';} else { echo '<a href="?select&field='.$field.'&'.(($text)?'text='.rawurlencode($text).'&':'').(($ftype)?'ft='.$ftype.'&':'').(($fsize)?'fs='.$fsize.'&':'').(($floads)?'fl='.$floads.'&':'').(($fdate)?'fd='.$fdate.'&':'').'ps='.($i-1).'&'.SID.'">'.$i.'</a> '; }} }
else { for($i=$ps+1-$sint;$i<=$ps+1+$sint;$i++) { if (($i-1)==$ps) { echo $i.' ';} else { echo '<a href="?select&field='.$field.'&'.(($text)?'text='.rawurlencode($text).'&':'').(($ftype)?'ft='.$ftype.'&':'').(($fsize)?'fs='.$fsize.'&':'').(($floads)?'fl='.$floads.'&':'').(($fdate)?'fd='.$fdate.'&':'').'ps='.($i-1).'&'.SID.'">'.$i.'</a> '; }} }
}
if(($i-2)>$ps) { echo '<a href="?select&field='.$field.'&'.(($text)?'text='.rawurlencode($text).'&':'').(($ftype)?'ft='.$ftype.'&':'').(($fsize)?'fs='.$fsize.'&':'').(($floads)?'fl='.$floads.'&':'').(($fdate)?'fd='.$fdate.'&':'').'ps='.($ps+1).'&'.SID.'">>></a> '; }
echo'</div>'; }
}else echo mysql_error().'<br><br>';
}else echo '- По вашему запросу ничего не найдено<br><br>';
}else echo mysql_error().'<br><br>';
}else echo '- Пустой запрос<br><br>';
echo '<div class="nav"><a href="search.php?'.SID.'">к форме поиска</a></div>';
}else{
echo'<form action="?p='.$ps.'&'.SID.'" method="post" accept-charset="utf-8">';
echo'<u>Что искать?</u><br>';
echo'<input type="text" name="text" maxlength="255" class="text" value=""><br>';
echo'[3-30] символов<br><br><u>Где искать?</u><br>';
echo'<input name="field" type="radio" value="1" checked> В названиях<br><input name="field" type="radio" value="2"> В описаниях<br>';
echo'<div class="header">Дополнительные параметры</div>';
echo'Тип: ';
echo'<select name="ft">';
echo'<option value="0">Все</option>';
foreach($ctype as $key=>$value){
echo'<option value="'.$key.'">'.$key.'</option>';
}
echo'</select>';
echo'<br><br>Размер: ';
echo 'Меньше ';
echo'<select name="fs">';
echo'<option value="0">Все</option>';
foreach($size as $key=>$value){
echo'<option value="'.$key.'">'.round($value/1024).'</option>';
}
echo'</select> KB';
echo'<br><br>Количество скачиваний: ';
echo 'Более ';
echo'<select name="fl">';
echo'<option value="0">Все</option>';
foreach($loads as $key=>$value){
echo'<option value="'.$key.'">'.$value.'</option>';
}
echo'</select>';
echo'<br><br>Время размещения: ';
echo'<select name="fd">';
echo'<option value="0">Все</option>';
foreach($times as $key=>$value){
echo'<option value="'.$key.'">'.$value.'</option>';
}
echo'</select>';
echo'<br><br>По автору: ';
echo'<select name="fuser">';
echo'<option value="0" selected>Любые</option>';
echo'<option value="'.MyEncode($user['login']).'">Только свои</option>';
echo'</select>';
echo'<br><br><input type="submit" name="select" class="button" value="Выбрать">';
echo'</form>';
}
echo '<div class="nav"><a href="index.php?'.SID.'">к загрузкам</a><br>';
echo '<a href="../?'.SID.'">на главную</a></div>';
}
// подключение дизайна
design();?>