2002-10-15 16:04:38 +00:00
< ? PHP //$Id$
// Deletes the moodledata directory, COMPLETELY!!
// BE VERY CAREFUL USING THIS!
2004-09-24 22:28:50 +00:00
require_once ( '../config.php' );
2002-10-15 16:04:38 +00:00
require_login ();
2006-03-06 10:02:59 +00:00
$sure = optional_param ( 'sure' , 0 , PARAM_BOOL );
$reallysure = optional_param ( 'reallysure' , 0 , PARAM_BOOL );
2005-05-06 03:11:58 +00:00
2002-10-15 16:04:38 +00:00
if ( ! isadmin ()) {
2004-09-24 22:28:50 +00:00
error ( 'You must be admin to use this script!' );
2002-10-15 16:04:38 +00:00
}
$deletedir = $CFG -> dataroot ; // The directory to delete!
2005-05-06 03:11:58 +00:00
if ( empty ( $sure )) {
2005-05-07 16:10:50 +00:00
notice_yesno ( 'Are you completely sure you want to delete everything inside the directory ' . $deletedir . ' ?' , 'delete.php?sure=yes&sesskey=' . sesskey (), 'index.php' );
2002-10-15 16:04:38 +00:00
exit ;
}
2005-05-06 03:11:58 +00:00
if ( empty ( $reallysure )) {
2005-05-07 16:10:50 +00:00
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' );
2002-10-15 16:04:38 +00:00
exit ;
}
2005-05-06 03:11:58 +00:00
if ( ! confirm_sesskey ()) {
error ( 'This script was called wrongly' );
}
2002-10-15 16:04:38 +00:00
/// OK, here goes ...
delete_subdirectories ( $deletedir );
2004-09-24 22:28:50 +00:00
echo '<h1 align="center">Done!</h1>' ;
2002-10-15 16:04:38 +00:00
print_continue ( $CFG -> wwwroot );
exit ;
function delete_subdirectories ( $rootdir ) {
$dir = opendir ( $rootdir );
while ( $file = readdir ( $dir )) {
2004-09-24 22:28:50 +00:00
if ( $file != '.' and $file != '..' ) {
$fullfile = $rootdir . '/' . $file ;
if ( filetype ( $fullfile ) == 'dir' ) {
2002-10-15 16:04:38 +00:00
delete_subdirectories ( $fullfile );
2004-09-24 22:28:50 +00:00
echo 'Deleting ' . $fullfile . ' ... ' ;
2002-10-15 16:04:38 +00:00
if ( rmdir ( $fullfile )) {
2004-09-24 22:28:50 +00:00
echo 'Done.<br />' ;
2002-10-15 16:04:38 +00:00
} else {
2004-09-24 22:28:50 +00:00
echo 'FAILED.<br />' ;
2002-10-15 16:04:38 +00:00
}
} else {
2004-09-24 22:28:50 +00:00
echo 'Deleting ' . $fullfile . ' ... ' ;
if ( unlink ( $fullfile )) {
echo 'Done.<br />' ;
2002-10-15 16:04:38 +00:00
} else {
2004-09-24 22:28:50 +00:00
echo 'FAILED.<br />' ;
2002-10-15 16:04:38 +00:00
}
}
}
}
closedir ( $dir );
}
2005-05-06 03:11:58 +00:00
?>