1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
<?PHP //$Id: delete.php,v 1.9 2006/03/06 10:02:59 skodak Exp $
// Deletes the moodledata directory, COMPLETELY!!
// BE VERY CAREFUL USING THIS!
require_once('../config.php');
require_login();
$sure = optional_param('sure', 0, PARAM_BOOL);
$reallysure = optional_param('reallysure', 0, PARAM_BOOL);
if (!isadmin()) {
error('You must be admin to use this script!');
}
$deletedir = $CFG->dataroot; // The directory to delete!
if (empty($sure)) {
notice_yesno ('Are you completely sure you want to delete everything inside the directory '. $deletedir .' ?', 'delete.php?sure=yes&sesskey='.sesskey(), 'index.php');
exit;
}
if (empty($reallysure)) {
notice_yesno ('Are you REALLY REALLY completely sure you want to delete everything inside the directory '. $deletedir .' (this includes all user images, and any other course files that have been created) ?', 'delete.php?sure=yes&reallysure=yes&sesskey='.sesskey(), 'index.php');
exit;
}
if (!confirm_sesskey()) {
error('This script was called wrongly');
}
/// OK, here goes ...
delete_subdirectories($deletedir);
echo '<h1 align="center">Done!</h1>';
print_continue($CFG->wwwroot);
exit;
function delete_subdirectories($rootdir) {
$dir = opendir($rootdir);
while ($file = readdir($dir)) {
if ($file != '.' and $file != '..') {
$fullfile = $rootdir .'/'. $file;
if (filetype($fullfile) == 'dir') {
delete_subdirectories($fullfile);
echo 'Deleting '. $fullfile .' ... ';
if (rmdir($fullfile)) {
echo 'Done.<br />';
} else {
echo 'FAILED.<br />';
}
} else {
echo 'Deleting '. $fullfile .' ... ';
if (unlink($fullfile)) {
echo 'Done.<br />';
} else {
echo 'FAILED.<br />';
}
}
}
}
closedir($dir);
}
?>
|