View file download/index.php

File size: 14.74Kb
<?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`"),0);
        $newlist = new Navigation($allfield,   10, true);
        $file_cat = mysql_query("SELECT * FROM download_dir WHERE dir_index=0 ". $newlist->limit()."");
        $file_cat_x = 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($file_cat_x == 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='.$file_cat_x['id'].'">'.$file_cat_x['name'].' </a>';
    if($user4['team'] == 6){
	echo ' [<a href="?delete_dir&dir='.$file_cat_x['id'].'">Удалить</a>][<a href="?editor_dir&dir='.$file_cat_x['id'].'">Редактировать</a>]';
	}
        echo '</div>';
  }
		
  while($file_cat_x = mysql_fetch_array($file_cat));
        echo '</div>';
        echo '<div class="pages">';
        echo $newlist->pagination();
        echo '</div>';
    }
    if($user4['team'] == 6)
    {
        echo '<hr/><a href="?act_dir">Создать папку</a>';
    }
            }	
    if(isset($_GET['dir']))
    {
	      echo '<div class="maintitle mainrazd">Список файлов и разделов</div><div class="maintext">';
        $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()."");
        $file_while = mysql_fetch_array($filew);
		
            if($file_while != null)
            {
 do
 {
    if($file_while['type'] == 'exe'){
        echo '<div class="posts"><img src="icons/exe.png"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'zip'){
	    echo '<div class="posts"><img src="icons/zip.png"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'rar'){
	    echo '<div class="posts"><img src="icons/zip.png"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'txt'){
	    echo '<div class="posts"><img src="icons/txt.png"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'sql'){
	    echo '<div class="posts"><img src="icons/txt.png"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'jar'){
	    echo '<div class="posts"><img src="icons/txt.png"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'png'){
	    echo '<div class="posts"><img src="icons/image.png"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'gif'){
	    echo '<div class="posts"><img width="50" height="40" src="../download/files_obmen/'.$file_while['name'].'"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'jpg'){
	    echo '<div class="posts"><img width="50" height="40" src="../download/files_obmen/'.$file_while['name'].'"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'jpeg'){
	    echo '<div class="posts"><img width="50" height="40" src="../download/files_obmen/'.$file_while['name'].'"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'swf'){
	    echo '<div class="posts"><img src="icons/flash.png"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    elseif($file_while['type'] == 'php'){
	    echo '<div class="posts"><img src="icons/php.png"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
    else{
	    echo '<div class="posts"><img src="icons/file.png"/> <a href="files.php?id='.$file_while['id'].'">'.$file_while['names'].'</a> ('.size($file_while['size']).')</div>';
	}
 }
  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="?dir='.$dir.'&act_dir&'.$conservation.'">Создание папку</a></div>';
    } 
	   echo '</div>';
       echo '</div>';
    }
 /*
=========================
Создание новой папки
=========================
*/

if($user4['team'] == 6)
{
	
    if(isset($_GET['act_dir']))
    {

            if($_POST['submit_dir'])
            {
                $submit_dir = $_POST['submit_dir'];
            }
                echo '<div class="user_foot">Создании новой папки</div><div class="posts">';
				
        if(isset($submit_dir))
        {
		
    if($_POST['dir_name']){
	    $dir_names = $_POST['dir_name'];
	}
        if($_POST['vib']){
		    $vib = $_POST['vib'];
		}

            if(mysql_result(mysql_query("SELECT * FROM `download_dir` WHERE `name`='$dir_names'"),0) != 0)
            {
                echo '<div class="errors">Папка с таким именем уже существует</div>';
                header("Refresh: 1; url=?act_dir");
                include_once'../template/foot.php';
                exit();
            }

    if(empty($dir_names))
    {
        echo '<div class="errors">Введите название папки</div>';
        header('Refresh: 1; url=?act_dir' );
        include_once'../template/foot.php';
        exit();
    }

            $dir_names = htmlspecialchars($dir_names);
            $dir_names = stripslashes($dir_names);
			
        if(strlen($dir_names)<1 || strlen($dir_names) >30)
        {
            echo '<div class="errors">Название должно быть не больше 30 символов</div>';
            header('Refresh:1; url=?act_dir');
            include_once'../template/foot.php';
            exit();
        }
		
            if($submit_dir and $dir_names)
            {
                $dir_path1 = 'download/'. $dir_path . $dir_names;
                $dir_n = $dir_path . $dir_names .'/';
                $ok_mysql_dir = mysql_query("INSERT INTO `download_dir` (name,time,dir_path,dir_index,vib) VALUES ('$dir_names','$time_date','$dir_n','$dir','$vib')");
				
                if($ok_mysql_dir == true)
                {
                    echo '<div class="actshcms">Папка создана</div>';
                    header("Refresh: 1; url=?");
                    include_once'../template/foot.php';
                    exit;
                }
                else
                {
                    echo '<div class="errors">Ошибка создании папки</div>';
                    header("Refresh: 1; url=?act_dir");
                    include_once'../template/foot.php';
                    exit;
                }
            }
        }

            echo '<form action="?act_dir&'.$conservation.'&dir='.$dir.'" method="post">';
            echo 'Название папки:<br/><input type="text" name="dir_name"><br/>';
            echo '<input name="vib" type="checkbox" value="1" ' .($file_while['vib']?'checked="checked"':'') . ' />&nbsp;Для файлов<br />';
            echo '<input type="submit" name="submit_dir" value="Создать">';
            echo '</form></div>';
    }
/*
==================
Удаление папки
==================
*/
    if(isset($_GET['delete_dir']))
    {
        echo '<div class="user_foot">Удаление папки</div>';
        $delw = mysql_fetch_array(mysql_query("SELECT * FROM download_dir WHERE id=$dir"));
		
            if(!$dir or !$delw['id'])
            {
                echo '<div class="errors">Вы непрвильно зашли</div>';
                header("Refresh: 1; url=?");
                include_once'../template/foot.php';
                exit();
            }

                if($_POST['delete_dir_submit'])
				{
				    $delete_dir_submit = $_POST['delete_dir_submit'];
				}
                    if(isset($delete_dir_submit))
                    {
                        $dele = mysql_query("DELETE FROM `download_dir` WHERE id=$dir");
						
                            if($dele == true){
                                echo '<div class="actshcms">Папка успешно удалена</div>';
                                header("Refresh:1; url=?");
                                exit();
                            }
							else
                            {
                                echo '<div class="errors">Ошибка удаление папки</div>';
                                header("Refresh:1; url=?delete_dir");
                                exit();
                            }
                    }

            echo '<form action="?delete_dir&dir='.$dir.'&'.$conservation.'" method="post">';
            echo '<input type="submit" name="delete_dir_submit" value="Удалить">';
            echo '</form>';
    }
	
/*
========================
Редактирование папки
========================
*/

    if(isset($_GET['editor_dir']))
    {
        $edit_dirs = mysql_fetch_array(mysql_query("SELECT * FROM download_dir WHERE id=$dir"));
            
			if($_POST['submit_dir_editor'])
            {
			    $submit_dir_editor = $_POST['submit_dir_editor'];
			}

        if(isset($submit_dir_editor))
        {

				    if($_POST['editor_name'])
					{
					    $editor_name =$_POST['editor_name'];
					}

        if(mysql_result(mysql_query("SELECT * FROM download_dir WHERE name='$editor_name'"),0) != 0)
        {
            echo '<div class="errors">Папка с таким именем уже существует</div>';
            header("Refresh: 1; url=?act_dir");
            include_once'../template/foot.php';
            exit();
        }


        if(empty($editor_name))
        {
            echo '<div class="errors">Введите название папки</div>';
            header("Refresh: 1; url=?editor_dir");
            include_once'../template/foot.php';
            exit();
        }

                $editor_name = htmlspecialchars($editor_name);
                $editor_name =stripslashes($editor_name);

    if($submit_dir_editor)
    {
        $ed_dirs = mysql_query("UPDATE download_dir SET name='$editor_name' WHERE id='$dir'");
        
		    if($ed_dirs == true)
            {
                echo '<div class="actshcms">Папка успешно изменена</div>';
                header("Refresh: 1; url=?");
                include_once'../template/foot.php';
                exit();
            }
            else
            {
                echo '<div class="errors">Ошибка редактирование папки</div>';
                header("Refresh: 1; url=?editor_dir&dir=".$dir."&");
                include_once'../template/foot.php';
                exit();
            }
    }
        }


            echo '<form action="?editor_dir&dir='.$dir.'&'.$conservation.'" method="post">';
            echo 'Название папки:<br/><input value="'.$edit_dirs['name'].'" type="text" name="editor_name"><br/>';
            echo '<input type="submit" name="submit_dir_editor" value="Редактировать">';
    }
}
include_once'../template/foot.php';
?>