diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index e92c1cfda9..1f45b636cb 100755 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -1518,100 +1518,102 @@ function create_unexisting_directory( } if (!is_dir($base_work_dir.$systemFolderName)) { - mkdir( + $result = mkdir( $base_work_dir.$systemFolderName, api_get_permissions_for_new_directories(), true ); - // Check if pathname already exists inside document table - $tbl_document = Database::get_course_table(TABLE_DOCUMENT); - $sql = "SELECT id, path FROM $tbl_document - WHERE - c_id = $course_id AND - ( - path = '".$systemFolderName."' - ) - "; + if ($result) { - $rs = Database::query($sql); - if (Database::num_rows($rs) == 0) { + // Check if pathname already exists inside document table + $tbl_document = Database::get_course_table(TABLE_DOCUMENT); + $sql = "SELECT id, path FROM $tbl_document + WHERE + c_id = $course_id AND + ( + path = '" . $systemFolderName . "' + ) + "; - $document_id = add_document( - $_course, - $systemFolderName, - 'folder', - 0, - $title, - null, - 0, - true, - $to_group_id - ); + $rs = Database::query($sql); + if (Database::num_rows($rs) == 0) { - if ($document_id) { - // Update document item_property - if (!empty($visibility)) { + $document_id = add_document( + $_course, + $systemFolderName, + 'folder', + 0, + $title, + null, + 0, + true, + $to_group_id + ); - $visibilities = array( - 0 => 'invisible', - 1 => 'visible', - 2 => 'delete' - ); - api_item_property_update( - $_course, - TOOL_DOCUMENT, - $document_id, - $visibilities[$visibility], - $user_id, - $to_group_id, - $to_user_id, - null, - null, - $session_id - ); - } else { - api_item_property_update( - $_course, - TOOL_DOCUMENT, + if ($document_id) { + // Update document item_property + if (!empty($visibility)) { + + $visibilities = array( + 0 => 'invisible', + 1 => 'visible', + 2 => 'delete' + ); + api_item_property_update( + $_course, + TOOL_DOCUMENT, + $document_id, + $visibilities[$visibility], + $user_id, + $to_group_id, + $to_user_id, + null, + null, + $session_id + ); + } else { + api_item_property_update( + $_course, + TOOL_DOCUMENT, + $document_id, + 'FolderCreated', + $user_id, + $to_group_id, + $to_user_id, + null, + null, + $session_id + ); + } + + $documentData = DocumentManager::get_document_data_by_id( $document_id, - 'FolderCreated', - $user_id, - $to_group_id, - $to_user_id, - null, - null, + $_course['code'], + false, $session_id ); + + return $documentData; } + } else { + $document = Database::fetch_array($rs); $documentData = DocumentManager::get_document_data_by_id( - $document_id, + $document['id'], $_course['code'], false, $session_id ); - return $documentData; - } else { - return false; - } - } else { - $document = Database::fetch_array($rs); - $documentData = DocumentManager::get_document_data_by_id( - $document['id'], - $_course['code'], - false, - $session_id - ); - /* This means the folder NOT exist in the filesystem - (now this was created) but there is a record in the Database*/ + /* This means the folder NOT exist in the filesystem + (now this was created) but there is a record in the Database*/ - return $documentData; + return $documentData; + } } - } else { - - return false; } + + return false; } /**