Subversion Repositories travelsized

Rev

Rev 468 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?PHP
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This file is part of Travelsized CMS
 *              A content management system with modules, based on wiki syntax
 *
 * Author: Dan Jensen <admin@leinir.dk>
 * Copyright 2003/2004
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The GNU General Public License is available at: http://www.gnu.org/copyleft/
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


$page_author = $creator_name;
$page_author_email = $creator_email;
$page_menu = 1;
$page_date = formatTime( time() );
$page_title = i18n("File setup");

function filesetup_compare_title($x, $y) { return arrayColumnCompare($x, $y, "title"); }
function filesetup_compare_size($x, $y) { return arrayColumnCompare($x, $y, "size"); }
function filesetup_compare_mimetype($x, $y) { return arrayColumnCompare($x, $y, "mimetype"); }
function filesetup_compare_mtime($x, $y) { return arrayColumnCompare($x, $y, "mtime"); }

if( !auth($_REQUEST["username"], $_REQUEST["password"]) )
        $page_content = loginform($language, thisPageURL(), $auth_messages);
else if( isauth() && !isAllowed("global_files") )
        $page_content = "<p>" . i18n("You are not authorised to manage files") . "</p>";
else if( isauth() )
{
        $setupPage = new setupPage();
        $setupPage->addBreadcrumb( i18n("Files"), globalIDtoURL("setup/filesetup") );
        $setupPage->addCommand( i18n("Upload file"), i18n("Upload a new file"), globalIDtoURL("setup/filesetup/upload") );
        //Manage files (images, downloads...)

        if( $theAction == "upload" )
        {
                $setupPage->contents = "<form enctype=\"multipart/form-data\" action=\"" . globalIDtoURL("setup/filesetup/uploadcomplete") . "\" method=\"post\">" .
                renderInformationBox( i18n("Upload file"),
                        "<p>" . i18n("Please select the file you wish to upload.") . "</p>
                        <input style=\"width: 100%;\" name=\"uploadedfile\" type=\"file\" />
                        <div align=\"center\">
                                <input type=\"submit\" value=\""
. i18n("Upload file") . "\" />
                        </div>"
) . "
                </form>
                "
;
        }
        else if( $theAction == "uploadcomplete" )
        {
                $uploadFile = $files_folder . "/" . $_FILES['uploadedfile']['name'];
                if( move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadFile) )
                {
                        chmod($uploadFile, 0664);// make sure the file is actually accessible...
                        $setupPage->contents = "<p>" . i18n("The file has been uploaded.") . "</p>";
                        header("Location: " .  globalIDtoURL("setup/filesetup") );
                }
                else
                {
                        $setupPage->contents = "<p>" . i18n("The file could not be uploaded. The error message can be found below:") . "</p>
                        <pre>"
;
                        switch( $_FILES['uploadedfile']['error'] )
                        {
                        case 1:
                                $setupPage->contents .= "The uploaded file exceeds the upload_max_filesize directive in php.ini.\nPlease contact your host and rectify this (or better yet, select a smaller file.\nMost often, this directive states 2MB as the maximum upload size).";
                                break;
                        case 2:
                                $setupPage->contents .= "The uploaded file exceeds 1MB in size,\nand is too large to upload in this manner.";
                                break;
                        case 3:
                                $setupPage->contents .= "The uploaded file was only partially uploaded.";
                                break;
                        case 4:
                                $setupPage->contents .= "No file was uploaded.";
                                break;
                        }
                        $setupPage->contents .= "</pre>";
                }
        }
        else if( $theAction == "delete" )
        {
                $dialog = new confirmDeleteDialog( "confirmDelete", i18n("The file with the filename: ##0##", array($deleteFile)), "setup/filesetup/confirm/$deleteFile" );
               
                if( $dialog->submitted )
                {
                        if( $dialog->confirmed )
                        {
                                if( unlink("$files_folder/$deleteFile") )
                                        header( "Location: " . globalIDtoURL("setup/filesetup") );
                                else
                                        $setupPage->contents = renderErrorBox( i18n("Error during delete!"), i18n("Deletion of the file could not be completed! Click your browser's &quot;Refresh&quot; button to try again, or ##0##.", array( drawCommand( i18n("click here to return to the list of files"), i18n(""), globalIDtoURL("setup/filesetup") ) ) ) );
                        }
                        else
                                header( "Location: " . globalIDtoURL("setup/filesetup") );
                }
                else
                        $setupPage->contents = $dialog->render();
        }
        else if( $theAction == "rename" )
        {
                if( $_POST["new_filename"] != "" )
                {
                        if( rename("$files_folder/$renameFrom","$files_folder/{$_REQUEST['new_filename']}") )
                        {
                                $setupPage->contents = "<p>" . i18n("Renaming of the file was successfully completed.") . "</p>";
                                header("Location: " . globalIDtoURL("setup/filesetup") );
                        }
                        else
                                $setupPage->contents = renderErrorBox( i18n("Renaming failed!"), i18n("Renaming of the file could not be completed! Please click your browser's &quot;Back&quot; button to return to the edit dialog, or the &quot;Refresh&quot; button to try again.") );
                }
                else
                {
                        $setupPage->contents = "<form action=\"" . globalIDtoURL("setup/filesetup/rename/$renameFrom") . "\" method=\"post\">" .
                        renderInformationBox( i18n("Type the new file name below"), "
                        <div align=\"center\"><input type=\"text\" value=\"$renameFrom\" style=\"width: 80%;\" name=\"new_filename\" /></div>
                        <br />
                        <div align=\"center\">
                                <input type=\"submit\" value=\""
. i18n("Rename") . "\" />
                                <input type=\"reset\" value=\""
. i18n("Reset changes") . "\" />
                        </div>"
) . "
                        </form>"
;
                }
        }
        else
        {
                $fp = opendir($files_folder);
                while( $file = readdir($fp) )
                {
                        if( substr( $file, 0, 1) != "." )
                        {
                                $title = $file;
                                $weight = fileweight( $files_folder . "/" . $file );
                                $size = filesize( $files_folder . "/" . $file );
                                $mimetype = getMime( $files_folder . "/" . $file );
                                $mtime = filemtime( $files_folder . "/" . $file );
                                $files_temp[] = array( "title" => $title, "weight" => $weight, "size" => $size, "mimetype" => $mimetype, "mtime" => $mtime );
                        }
                }
                closedir($fp);
               
                if( !empty($files_temp) )
                {
                        $alternateRow = false;
                       
                        $table = new Table("setup", "setup", "setup");
                       
                        $table->newRow( null, true );
                        $table->newCell( drawCommand( i18n("Filename"), i18n("Sort by name"), globalIDtoURL("setup/filesetup/", array("sortBy" => "title") ) ) );
                        $table->newCell( drawCommand( i18n("Filesize"), i18n("Sort by size"), globalIDtoURL("setup/filesetup/", array("sortBy" => "size") ) ) );
                        $table->newCell( drawCommand( i18n("Filetype"), i18n("Sort by type"), globalIDtoURL("setup/filesetup/", array("sortBy" => "mimetype") ) ) );
                        $table->newCell( drawCommand( i18n("Last modified"), i18n("Sort by last modified time"), globalIDtoURL("setup/filesetup/", array("sortBy" => "mtime") ) ) );
                        $table->newCell( i18n("Functions") );
                       
                        $sortBy = $_REQUEST["sortBy"];
                        if( $sortBy != null )
                                usort( $files_temp, "filesetup_compare_$sortBy" );
                       
                        foreach( $files_temp as $key => $value )
                        {
                                if( !is_dir( "$files_folder/$value" ) )
                                {
                                        $alternateRow = !$alternateRow;
                                       
                                        $table->newRow( $alternateRow ? "alternateRow setup" : null );
                                        $table->newCell($value["title"]);
                                        $table->newCell($value["weight"]);
                                        $table->newCell($value["mimetype"]);
                                        $table->newCell( date( "j M Y H:i", $value["mtime"] ) );
                                        $table->newCell(
                                                drawCommand( i18n("View"), i18n("View the file"), siteURL(true) . "$files_folder/" . $value["title"] ) . " " .
                                                drawCommand( i18n("Rename"), i18n("Rename the file"), globalIDtoURL("setup/filesetup/rename/" . $value["title"]) ) . " " .
                                                drawCommand( i18n("Delete"), i18n("Delete the file"), globalIDtoURL("setup/filesetup/delete/" . $value["title"]) )
                                                , null, "setup wikirightalign" );
                                }
                        }
                       
                        $setupPage->contents = $table->render();
                }
                else
                        $setupPage->contents = renderInformationBox( "No files found", i18n("There are not currently any files uploaded. ##0##" , array( drawCommand( i18n("Click here to upload a file"), i18n("Click here to upload a file"), globalIDtoURL("setup/filesetup/upload") ) ) ) );
        }
       
        $page_content = $setupPage->render();
}
?>