Файл: files.php
Строк: 200
<?php
    session_start();
    error_reporting(E_ALL^E_DEPRECATED);
    
    include "sys/system.page.php";
    include "sys/system.db.php";
    include "sys/system.auth.php";
    include "sys/system.files.php";
    include "sys/system.comments.php";
    class Page {
        
        var $gen;
        var $auth;
        var $db;
        var $files;
        var $comments;
        
        function __construct() {
            global $gen;
            global $auth;
            global $db;
            global $files;
            global $comments;
            
            $gen = new PageGenerator();
            $db = new Database;
            $auth = new Authorization;
            $files = new Files;
            $comments = new Comments;
        }
        
        function DoFileID() {
            global $gen;
            global $auth;
            global $db;
            global $files;
            global $comments;
            
            $info = $files->GetFileInfo($db, $_GET["fileid"]);
            
            if($info["owner"] == "") {
                $gen->CreateText("Такого файла не существует!");
                $gen->CreateBackLink();
                exit;
            }
            
            $gen->CreateTextWithIcon("file-zip-o", $info["name"]);
            $gen->CreateTextWithIcon("wpforms", "Описание: $info[description]");
            $gen->CreateTextWithIcon("user", "Выгрузил: " . $auth->GetUserFromID($db, $info["owner"]));
            $gen->CreateTextWithIcon("upload", "Загрузок: $info[downloads]");
            if($info["category"] == "progs") {
                $gen->CreateLinkWithIcon("download", "Скачать", "files.php?download=$info[id]");
            }
            if($info["category"] == "games") {
                $gen->CreateLinkWithIcon("download", "Скачать", "files.php?download=$info[id]");
            }
            if($info["category"] == "music") {
                $gen->CreateLinkWithIcon("download", "Скачать", "files.php?download=$info[id]");
            }
            if($info["category"] == "pictures") {
                $gen->CreateLinkWithIcon("download", "Скачать", "files.php?download=$info[id]");
            }
            $gen->CreateBackLink();
            $gen->CreateText("Комментарии:");
            
            $comment = $comments->GetFileComments($db, $_GET["fileid"]);
            
            for($i = 1; $i < count($comment) + 1; $i++) {
                $gen->CreateText($comment[$i]["date"] . " " . "<a class="link" href="profile.php?id=" . $auth->GetUserID($db, $comment[$i]["author"]) . "">" . $comment[$i]["author"] . "</a>: ");
                $gen->CreateText($comment[$i]["text"]);
            }
            
            if($auth->IsUserAuthorized()) {
                $gen->StartForm("files.php?leavecomment=true&fileid=" . $_GET["fileid"]);
                $gen->CreateText("Текст комментария:");
                $gen->CreateInput("text");
                $gen->CreateSubmit();
                $gen->EndForm();
            } else {
                $gen->CreateText("Вы должны зарегистрироватся чтобы оставлять комментарии!");
            }
        }
        
        function DoLeaveComment() {
            global $gen;
            global $auth;
            global $db;
            global $files;
            global $comments;
            
            echo "<script type="javascript">alert("ok");</script>";
            
            if(!$auth->IsUserAuthorized()) {
                echo "<script language="javascript">window.location = "login.php";</script>";
                exit;
            }
            
            $comments->SendComment($db, $_GET["fileid"], $_SESSION["username"], $_POST["text"]);
            echo "<script language="javascript">history.back();;</script>";
        }
        
        function DoUploadForm() {
            global $gen;
            global $auth;
            global $db;
            global $files;
            
            $gen->CreateText("Выгрузить файл");
            echo "<form action="files.php?doupload=true" method="POST" enctype="multipart/form-data"";
            $gen->CreateText("Максимальный размер файла: 10мб");
            $gen->CreateText("Файл:");
            $gen->CreateText("Имя файла:");
            $gen->CreateInput("name");
            $gen->CreateText("Описание:");
            $gen->CreateInput("desc");
            echo "<div class="content-field"><input name="userfile" type="file" /></div>";
            $gen->CreateSubmit();
            $gen->EndForm();
        }
        
        function DoUpload() {
            global $gen;
            global $auth;
            global $db;
            global $files;
            
            $files->Upload($db, $_FILES["userfile"], $_POST["desc"], $_POST["name"], $gen, $auth);
        }
        
        function DoDownload() {
            global $gen;
            global $auth;
            global $db;
            global $files;
            
            $url = $files->Download($db, $_GET["download"]);
            
            echo "<script language="javascript">window.location = "$url";</script>";
            
            $gen->CreateBackLink();
        }
        
        function Render() {
            global $gen;
            global $auth;
            global $db;
            global $files;
            
            if($auth->GetUserRights($db) == "Парится в баньке") {
                $gen->CreateText("<b style="color: red">У вас нет доступа к этой странице</b>");
                $gen->CreateLinkWithIcon("close", "Выйти", "logout.php");
                exit;
            }
            
            if(isset($_GET["leavecomment"]) && isset($_GET["fileid"])) {
                $this->DoLeaveComment();
                exit;
            }
            
            if(isset($_GET["fileid"])) {
                $this->DoFileID();
                exit;
            }
            
            if(isset($_GET["upload"])) {
                $this->DoUploadForm();
                exit;
            }
            
            if(isset($_GET["doupload"])) {
                $this->DoUpload();
                exit;
            }
            
            if(isset($_GET["download"])) {
                $this->DoDownload();
                exit;
            }
            
            if(isset($_GET["id"])) {
                
                $gen->CreateText("Файлы пользователя <a class="link" href="profile.php?id=" . $_GET["id"] . "">" . $auth->GetUserFromID($db, $_GET["id"]) . "</a>");
            
                $res = $files->GetFilesByOwner($db, $_GET["id"]);
                if($res == 0) {
                    $gen->CreateText("Нет файлов!");
                    $gen->CreateLinkWithIcon("home", "Домой", "index.php");
                    exit;
                }
            
                for($i = 1; $i < count($res) + 1; $i++) {
                    $gen->CreateLinkWithIcon("cloud-download", $res[$i]["name"], "files.php?fileid=" . $res[$i]["id"]);
                }
                
                if(isset($_SESSION["username"])) {
                    if($auth->GetUserID($db, $_SESSION["username"]) == $_GET["id"]) {
                        $gen->CreateLinkWithIcon("upload", "Загрузить файл", "files.php?upload=true");
                    }
                }
            
                $gen->CreateLinkWithIcon("home", "Домой", "index.php");
                exit;
            }
            
            echo "<script language="javascript">window.location = "index.php";</script>";
        }
        
    }
    
    $index = new Page;
    $index->Render();
?>