OKAY! THIS IS IT! MOODLE 1.6!
[moodle.git] / admin / delete.php
blob0f068d52a30b56796e44e274e5c3180b45f9be7f
1 <?PHP //$Id$
3 // Deletes the moodledata directory, COMPLETELY!!
4 // BE VERY CAREFUL USING THIS!
6 require_once('../config.php');
8 require_login();
10 $sure = optional_param('sure', 0, PARAM_BOOL);
11 $reallysure = optional_param('reallysure', 0, PARAM_BOOL);
13 if (!isadmin()) {
14 error('You must be admin to use this script!');
17 $deletedir = $CFG->dataroot; // The directory to delete!
19 if (empty($sure)) {
20 notice_yesno ('Are you completely sure you want to delete everything inside the directory '. $deletedir .' ?', 'delete.php?sure=yes&amp;sesskey='.sesskey(), 'index.php');
21 exit;
24 if (empty($reallysure)) {
25 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&amp;reallysure=yes&amp;sesskey='.sesskey(), 'index.php');
26 exit;
29 if (!confirm_sesskey()) {
30 error('This script was called wrongly');
33 /// OK, here goes ...
35 delete_subdirectories($deletedir);
37 echo '<h1 align="center">Done!</h1>';
38 print_continue($CFG->wwwroot);
39 exit;
42 function delete_subdirectories($rootdir) {
44 $dir = opendir($rootdir);
46 while ($file = readdir($dir)) {
47 if ($file != '.' and $file != '..') {
48 $fullfile = $rootdir .'/'. $file;
49 if (filetype($fullfile) == 'dir') {
50 delete_subdirectories($fullfile);
51 echo 'Deleting '. $fullfile .' ... ';
52 if (rmdir($fullfile)) {
53 echo 'Done.<br />';
54 } else {
55 echo 'FAILED.<br />';
57 } else {
58 echo 'Deleting '. $fullfile .' ... ';
59 if (unlink($fullfile)) {
60 echo 'Done.<br />';
61 } else {
62 echo 'FAILED.<br />';
67 closedir($dir);