Project

General

Profile

1 238 stefan
<?php
2 1400 FrankH
/**
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$
14
 * @filesource		$HeadURL:  $
15
 * @lastmodified    $Date:  $
16
 *
17
 */
18 238 stefan
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 1475 Luisehahne
$directory = ($directory == '/') ?  '' : $directory;
30 1400 FrankH
31 1475 Luisehahne
$dirlink = 'browse.php?dir='.$directory;
32
$rootlink = 'browse.php?dir=';
33
34 1400 FrankH
// Check to see if it contains ..
35
if (!check_media_path($directory)) {
36 1414 Luisehahne
	// $admin->print_header();
37 1475 Luisehahne
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH'],$rootlink,false );
38 238 stefan
}
39
40 1475 Luisehahne
// Get the file id
41
$file_id = $admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']);
42 1400 FrankH
if (!$file_id) {
43 1475 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $dirlink,false);
44 238 stefan
}
45
46
// Get home folder not to show
47
$home_folders = get_home_folders();
48 1457 Luisehahne
$usedFiles = array();
49
// feature freeze
50
// require_once(ADMIN_PATH.'/media/dse.php');
51
/*
52 238 stefan
53 1457 Luisehahne
if(!empty($currentdir)) {
54
	$usedFiles = $Dse->getMatchesFromDir( $directory, DseTwo::RETURN_USED);
55
}
56
*/
57 238 stefan
// 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 384 Ruebenwurz
		sort($DIR);
74 238 stefan
		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 384 Ruebenwurz
		sort($FILE);
84 238 stefan
		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 1475 Luisehahne
	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], $dirlink, false);
97 238 stefan
}
98
$relative_path = WB_PATH.MEDIA_DIRECTORY.'/'.$directory.'/'.$delete_file;
99
// Check if the file/folder exists
100
if(!file_exists($relative_path)) {
101 1475 Luisehahne
	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], $dirlink, false);
102 238 stefan
}
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 1475 Luisehahne
		$admin->print_success($MESSAGE['MEDIA']['DELETED_DIR'], $dirlink);
109 238 stefan
	} else {
110 1475 Luisehahne
		$admin->print_error($MESSAGE['MEDIA']['CANNOT_DELETE_DIR'], $dirlink, false);
111 238 stefan
	}
112
} else {
113
	// Try and delete the file
114
	if(unlink($relative_path)) {
115 1475 Luisehahne
		$admin->print_success($MESSAGE['MEDIA']['DELETED_FILE'], $dirlink);
116 238 stefan
	} else {
117 1475 Luisehahne
		$admin->print_error($MESSAGE['MEDIA']['CANNOT_DELETE_FILE'], $dirlink, false);
118 238 stefan
	}
119
}
120
121 239 stefan
?>