root / trunk / actions / DeleteFile.php @ 1112

View | Annotate | Download (1.2 KB)

1
<?php
2
3
/*
4
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
5
* @license http://creativecommons.org/licenses/BSD/ BSD License
6
* @author Keyboard Monkeys Ltd.
7
* @since Sciret 1.2
8
* @package Sciret
9
* @packager Keyboard Monkeys
10
*/
11
12
require 'actions/Action.php';
13
14
class DeleteFile extends Action {
15
16
    function dispatch() {
17
        $fileId = isset($_GET['id'])? (int)$_GET['id'] : 0;
18
        $artId = isset($_GET['artId'])? (int)$_GET['artId'] : 0;
19
        $file = new Kb_Model_File($fileId);
20
        if (!$file->getId()) {
21
            $_SESSION['message'] = $this->translate('Wrong file ID');
22
            Library::redirect(Library::getLink(array('view' => 'ViewArticle', 'id' => $artId)));
23
        }
24
        $fileName = $file->getFileName();
25
26
        if ($file->delete()) {
27
            $_SESSION['message'] = $this->translate('File deleted successfully');
28
        } else {
29
            $_SESSION['message'] = $this->translate('File deleted on database but note there was an error attempting to delete it from the filesystem');
30
        }
31
        $this->addHistoryEntry($artId, translate('File \'%s\' deleted'), array($fileName));
32
        Library::redirect(Library::getLink(array('view' => 'ViewArticle', 'id' => $artId)));
33
    }
34
}
35
36
?>
37