diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php index d8a93b3ff9..ef5e83a006 100644 --- a/main/exercice/exercice.php +++ b/main/exercice/exercice.php @@ -287,8 +287,10 @@ if ($is_allowedToEdit) { if (my_delete($documentPath . $file)) { update_db_info("delete", $file); } - my_delete($documentPath . $uploadPath . "/" . $fld . "/"); - break; + // hotpotatoes folder may contains several tests so don't delete folder if not empty : http://support.chamilo.org/issues/2165 + if (!(strstr($uploadPath, DIR_HOTPOTATOES) && !folder_is_empty($documentPath . $uploadPath . "/" . $fld . "/"))) { + my_delete($documentPath . $uploadPath . "/" . $fld . "/"); + } break; case 'enable' : // enables an exercise $newVisibilityStatus = "1"; //"visible" $query = "SELECT id FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path='" . Database :: escape_string($file) . "'"; diff --git a/main/inc/lib/fileManage.lib.php b/main/inc/lib/fileManage.lib.php index 3e530f4ec6..a1bcb98f25 100644 --- a/main/inc/lib/fileManage.lib.php +++ b/main/inc/lib/fileManage.lib.php @@ -157,6 +157,24 @@ function removeDir($dir) { return true; } + +/** + * Return true if folder is empty + * @author : hubert.borderiou@grenet.fr + * @param string $in_folder : folder path on disk + * @return 1 if folder is empty, 0 otherwise +*/ + +function folder_is_empty($in_folder) { + $tab_folder_content = scandir($in_folder); + $folder_is_empty = 0; + if ((count($tab_folder_content) == 2 && in_array(".", $tab_folder_content) && in_array("..", $tab_folder_content)) || (count($tab_folder_content) < 2)) { + $folder_is_empty = 1; + } + return $folder_is_empty; +} + + /** * Renames a file or a directory *