<?php
/*
=============================================
Движок: SHCMS Engine
=============================================
Название файла: Обменник
=============================================
Official website: http://shcms.ru
=============================================
*/
define('SHCMS', true);
include_once'../system/inc/basic_settings.php';
 if(isset($_GET['act_dir']))
{$shcmsengine['title'] = 'Создание новой папки';}
else{$shcmsengine['title'] = 'Файловый обменник';}
include_once'../template/head.php';


        $allfield = mysql_result(mysql_query("SELECT COUNT(*) FROM `download_dir` WHERE `dir_index`='0'"),0);
        $newlist = new Navigation($allfield,10, true);
        $file_cat = mysql_query("SELECT * FROM `download_dir` WHERE `dir_index`='0' ". $newlist->limit()."");
        $dir_cats = mysql_fetch_array($file_cat);
    
	if($_GET['dir']){
	    $dir = $_GET['dir'];
	}
	
    if($dir == false) 
	{ 
		echo '<div class="maintitle mainrazd">Поиск файлов:</div>
		<div class="maintext"><form action="search.php" method="post">';
		echo '<input type="text" name="search">';
		echo '<input type="submit" name="submit" value="Искать"></form>
		<small> * Файлы найти можно по названию</small></div>';

        $new_files = mysql_result(mysql_query("SELECT COUNT(*) FROM `download_file` WHERE `time` > '".(time()-86400)."'"),0);
        echo '<div class="posts"><a href="new.files.php">Новые поступление  ('.$new_files .')</a></div><hr/>';
    
	if($dir_cats == null)
    {
        echo '<div class="posts">Файловый обменник пуст.</div>';
    }
    else
    {
        echo '<div class="maintitle mainrazd">Обменник файлов</div><div class="maintext">';
  do
  {
        echo '<div class="posts"> <img src="icons/dir.png"/>  <a href="?dir='.$dir_cats['id'].'">'.$dir_cats['name'].' </a>';
        echo '</div>';
  }
		
  while($dir_cats = mysql_fetch_array($file_cat));
        echo '</div>';
        echo '<div class="pages">';
        echo $newlist->pagination();
        echo '</div>';
    }
    if($user4['team'] == 6)
    {
	echo '<div class="maintitle mainrazd">Навигация</div>';
        echo '<div class="maintext"><div class="posts"><a href="new_dir.php">Создать папку</a></div>';
		echo '<div class="posts"><a href="edit.php">Настройка папок</a></div></div>';
    }
            }	
    if(isset($_GET['dir']))
    {
        $id = $dir;
        $yel_down = mysql_query("SELECT * FROM `download_dir` WHERE `dir_index`='$dir'");
	    $ok_down = mysql_fetch_array($yel_down);

            if($ok_down)
            {
 do {
        $result_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `download_file` WHERE `id_dir` = '$ok_down[id]'"),0);

    if (mysql_result(mysql_query("SELECT COUNT(*) FROM `download_dir` WHERE `dir_path` LIKE '%$ok_down[dir_path]%' AND `id` != '$ok_down[id]'  AND `time` > '". (time()-3600*24*3) ."'"), 0) != 0) ;
	    echo '<div class="posts">
	         <img src="icons/dir.png"/> <a href="?dir='.$ok_down['id'].'">'.$ok_down['name'].'</a> 
			 <span class="count">'. $result_count.'</span></div>';
    }
  while ($ok_down = mysql_fetch_array($yel_down));
            }

        $files = mysql_fetch_array(mysql_query("SELECT * FROM `download_file` WHERE `id_dir`='$dir'"));
        $rt_d = mysql_result(mysql_query("SELECT COUNT(*) FROM  `download_dir` WHERE `dir_index` = '$dir'"), 0);
        $allfield1 = mysql_result(mysql_query("SELECT COUNT(*) FROM `download_file` WHERE `id_dir`='$dir'"),0);
        $newlist1 = new Navigation($allfield1,10,true);   	  
        $filew = mysql_query("SELECT * FROM `download_file` WHERE `id_dir`= '$dir' ORDER BY `id` DESC ". $newlist1->limit()."");
		
		
		
				if(mysql_num_rows($yel_down) == NULL and mysql_num_rows($filew)== NULL )
		{
		echo '<div class="posts">В данной папки нет файлов</div>';
		}
		
		
        $file_while = mysql_fetch_array($filew);
            if($file_while != null)
            {
 do
 {
    files::files_icon($file_while['type']);
 }
  while($file_while = mysql_fetch_array($filew));
        echo '<div class="pages">';
        echo $newlist1->pagination('dir='.$id);
        echo '</div>';

            }
        if($user_id)
        {  
        $world =  mysql_fetch_array(mysql_query("SELECT * FROM `download_dir` WHERE `id`='$id'"));
		echo '<div class="maintitle mainrazd">Добавление</div><div class="maintext">';
   if($world['vib'] == 1 or $user4['team'] == 6)
   {
       echo '<div class="posts"><a href="upload.php?dir='.$dir.'&'.$conservation.'">Добавить файл</a></div>';
   }
        }  
	if($user4['team'] == 6){
        echo '<div class="posts"><a href="new_dir.php?dir='.$dir.'&act_dir&'.$conservation.'">Создание папку</a></div>';
    } 
	if($user_id)
	{
	echo '</div>';
	}

    }
include_once'../template/foot.php';
?>