Browse Source

[svn r18023] FS#2867 - Simple file manager, working in a course: When a new folder is created or file is uploaded, correspondent database records should be created.

Ivan Tcholakov 16 years ago
parent
commit
166e3a68d0

+ 28 - 0
main/inc/lib/fckeditor/editor/filemanager/browser/default/connectors/php/commands.php

@@ -159,6 +159,8 @@ function CreateFolder( $resourceType, $currentFolder )
 
 function FileUpload( $resourceType, $currentFolder, $sCommand )
 {
+	// TODO: System's black and white lists to be taken into account.
+
 	if (!isset($_FILES)) {
 		global $_FILES;
 	}
@@ -264,6 +266,32 @@ function FileUpload( $resourceType, $currentFolder, $sCommand )
 	else
 		$sErrorNumber = '202' ;
 
+	if ($sErrorNumber == '0')
+	{
+		// While we are in a course: Registering the newly created folder in the course's database.
+		if (api_is_in_course())
+		{
+			global $_course, $_user;
+			$repository_path = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document/';
+			$to_group_id = 0;
+
+			if (api_is_in_group())
+			{
+				global $group_properties;
+				$to_group_id = $group_properties['id'];
+			}
+
+			$file_path = substr($sFilePath, strpos($sFilePath, $repository_path) + strlen($repository_path) - 1);
+			$path = explode('/', $file_path);
+			$file_name = $path[count($path) - 1];
+			$path[count($path) - 1] = '';
+			$folder_path = '/' + implode('/', $path);
+			$file_size = @filesize($sFilePath);
+			$doc_id = add_document($_course, $file_path, 'file', $file_size, $file_name);
+			api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], $to_group_id);
+			item_property_update_on_folder($_course, $folder_path, $_user['user_id']);
+		}
+	}
 
 	$sFileUrl = CombinePaths( GetResourceTypePath( $resourceType, $sCommand ) , $currentFolder ) ;
 	$sFileUrl = CombinePaths( $sFileUrl, $sFileName ) ;

+ 20 - 1
main/inc/lib/fckeditor/editor/filemanager/browser/default/connectors/php/io.php

@@ -95,7 +95,6 @@ function ServerMapFolder( $resourceType, $folderPath, $sCommand )
 	// Ensure that the directory exists.
 	// Modified by Ivan Tcholakov.
 	//CreateServerFolder( $sResourceTypePath ) ;
-	// TODO: To be checked if/when it is necessary.
 	if ( $resourceType != 'file' )
 	{
 		CreateServerFolder( $sResourceTypePath ) ;
@@ -161,6 +160,26 @@ function CreateServerFolder( $folderPath, $lastFolder = null )
 			umask( $oldumask ) ;
 		}
 
+		// While we are in a course: Registering the newly created folder in the course's database.
+		if (api_is_in_course())
+		{
+			global $_course, $_user;
+			$repository_path = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document/';
+			$to_group_id = 0;
+
+			if (api_is_in_group())
+			{
+				global $group_properties;
+				$to_group_id = $group_properties['id'];
+			}
+
+			$folder_path = substr($folderPath, strpos($folderPath, $repository_path) + strlen($repository_path) - 1);
+			$folder_name = explode('/', $folder_path);
+			$folder_name = $folder_name[count($folder_name) - 1];
+			$doc_id = add_document($_course, $folder_path, 'folder', 0, $folder_name);
+			api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], $to_group_id);
+		}
+
 		$sErrorMsg = $php_errormsg ;
 
 		// Restore the configurations.