Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         admintools
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: delete.php 1475 2011-07-12 23:07:10Z Luisehahne $
14
 * @filesource		$HeadURL:  $
15
 * @lastmodified    $Date:  $
16
 *
17
 */
18

    
19
// Create admin object
20
require('../../config.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
$admin = new admin('Media', 'media_delete', false);
23

    
24
// Include the WB functions file
25
require_once(WB_PATH.'/framework/functions.php');
26

    
27
// Get the current dir
28
$directory = $admin->get_get('dir');
29
$directory = ($directory == '/') ?  '' : $directory;
30

    
31
$dirlink = 'browse.php?dir='.$directory;
32
$rootlink = 'browse.php?dir=';
33

    
34
// Check to see if it contains ..
35
if (!check_media_path($directory)) {
36
	// $admin->print_header();
37
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH'],$rootlink,false );
38
}
39

    
40
// Get the file id
41
$file_id = $admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']);
42
if (!$file_id) {
43
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $dirlink,false);
44
}
45

    
46
// Get home folder not to show
47
$home_folders = get_home_folders();
48
$usedFiles = array();
49
// feature freeze
50
// require_once(ADMIN_PATH.'/media/dse.php');
51
/*
52

    
53
if(!empty($currentdir)) {
54
	$usedFiles = $Dse->getMatchesFromDir( $directory, DseTwo::RETURN_USED);
55
}
56
*/
57
// Figure out what folder name the temp id is
58
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
59
	// Loop through the files and dirs an add to list
60
   while (false !== ($file = readdir($handle))) {
61
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
62
			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
63
				if(!isset($home_folders[$directory.'/'.$file])) {
64
					$DIR[] = $file;
65
				}
66
			} else {
67
				$FILE[] = $file;
68
			}
69
		}
70
	}
71
	$temp_id = 0;
72
	if(isset($DIR)) {
73
		sort($DIR);
74
		foreach($DIR AS $name) {
75
			$temp_id++;
76
			if(!isset($delete_file) AND $file_id == $temp_id) {
77
				$delete_file = $name;
78
				$type = 'folder';
79
			}
80
		}
81
	}
82
	if(isset($FILE)) {
83
		sort($FILE);
84
		foreach($FILE AS $name) {
85
			$temp_id++;
86
			if(!isset($delete_file) AND $file_id == $temp_id) {
87
				$delete_file = $name;
88
				$type = 'file';
89
			}
90
		}
91
	}
92
}
93

    
94
// Check to see if we could find an id to match
95
if(!isset($delete_file)) {
96
	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], $dirlink, false);
97
}
98
$relative_path = WB_PATH.MEDIA_DIRECTORY.'/'.$directory.'/'.$delete_file;
99
// Check if the file/folder exists
100
if(!file_exists($relative_path)) {
101
	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], $dirlink, false);
102
}
103

    
104
// Find out whether its a file or folder
105
if($type == 'folder') {
106
	// Try and delete the directory
107
	if(rm_full_dir($relative_path)) {
108
		$admin->print_success($MESSAGE['MEDIA']['DELETED_DIR'], $dirlink);
109
	} else {
110
		$admin->print_error($MESSAGE['MEDIA']['CANNOT_DELETE_DIR'], $dirlink, false);
111
	}
112
} else {
113
	// Try and delete the file
114
	if(unlink($relative_path)) {
115
		$admin->print_success($MESSAGE['MEDIA']['DELETED_FILE'], $dirlink);
116
	} else {
117
		$admin->print_error($MESSAGE['MEDIA']['CANNOT_DELETE_FILE'], $dirlink, false);
118
	}
119
}
120

    
121
?>
(5-5/15)