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 1457 2011-06-25 17:18:50Z 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
if($directory == '/') {
30
	$directory = '';
31
}
32

    
33
// Check to see if it contains ..
34
if (!check_media_path($directory)) {
35
	// $admin->print_header();
36
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH'],WB_URL.'/admin/media/browse.php?dir=',false );
37
}
38

    
39
// Get the temp id
40
$file_id = $admin->checkIDKEY('id', false, 'GET');
41
if (!$file_id) {
42
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], WB_URL.'/admin/media/browse.php?dir=',false);
43
}
44

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

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

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

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

    
122
?>
(5-5/15)