Browse Source

[svn r14808] "update_item_property" now available in Forums when adding por deleting attachments (see FS#2396)

Julio Montoya 17 years ago
parent
commit
fa2a5e62b5

+ 7 - 6
main/blog/download.php

@@ -64,8 +64,10 @@ if (! isset($_course))
 {
 	api_not_allowed(true);	
 }
-//if the rewrite rule asks for a directory, we redirect to the document explorer
-if (is_dir(api_get_path(SYS_COURSE_PATH).$_course['path'].'/upload/blog/'.$doc_url)) 
+$full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/blog/'.$doc_url;
+
+//if the rewrite rule asks for a directory, we redirect to the course view
+if (is_dir($full_file_name)) 
 {
 	//remove last slash if present	
 	while ($doc_url{$dul = strlen($doc_url)-1}=='/') $doc_url = substr($doc_url,0,$dul);
@@ -75,14 +77,13 @@ if (is_dir(api_get_path(SYS_COURSE_PATH).$_course['path'].'/upload/blog/'.$doc_u
 	header('Location: '.$document_explorer);
 }
 
-$blog_table_attachment	= '`'.$_course['dbNameGlu'].'blog_attachment'.'`';
+$tbl_blogs_attachment 	= Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
 
 // launch event
 event_download($doc_url);
-$sys_course_path = api_get_path(SYS_COURSE_PATH);
-$full_file_name = $sys_course_path.$_course['path'].'/upload/blog/'.$doc_url;
 
-$sql = 'SELECT filename FROM '.$blog_table_attachment.' WHERE path LIKE BINARY "'.$doc_url.'"';
+$sql = 'SELECT filename FROM '.$tbl_blogs_attachment.' WHERE path LIKE BINARY "'.$doc_url.'"';
+
 $result= api_sql_query($sql, __FILE__, __LINE__);
 $row= Database::fetch_array($result);
 DocumentManager::file_send_for_download($full_file_name,TRUE, $row['filename']);

+ 19 - 7
main/forum/download.php

@@ -42,6 +42,7 @@ include('../inc/global.inc.php');
 $this_section=SECTION_COURSES;
 
 include(api_get_path(LIBRARY_PATH).'document.lib.php');
+require_once('forumconfig.inc.php');
 
 // IMPORTANT to avoid caching of documents
 header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
@@ -64,29 +65,40 @@ if (! isset($_course))
 {
 	api_not_allowed(true);	
 }
+
+$full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/forum/'.$doc_url;
+
 //if the rewrite rule asks for a directory, we redirect to the document explorer
-if (is_dir(api_get_path(SYS_COURSE_PATH).$_course['path'].'/upload/forum/'.$doc_url)) 
+if (is_dir($full_file_name)) 
 {
 	//remove last slash if present
 	//$doc_url = ($doc_url{strlen($doc_url)-1}=='/')?substr($doc_url,0,strlen($doc_url)-1):$doc_url; 
 	//mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (Ren�)
 	while ($doc_url{$dul = strlen($doc_url)-1}=='/') $doc_url = substr($doc_url,0,$dul);
 	//create the path
-	$document_explorer = api_get_path(WEB_CODE_PATH).'forum';
+	$document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
 	//redirect
 	header('Location: '.$document_explorer);
 }
 
-$tbl_blogs_attachment 	= Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
+$tbl_forum_attachment 	= Database::get_course_table(TABLE_FORUM_ATTACHMENT);
+$tbl_forum_post 	= Database::get_course_table(TABLE_FORUM_POST);
 
 // launch event
 event_download($doc_url);
-$sys_course_path = api_get_path(SYS_COURSE_PATH);
-$full_file_name = $sys_course_path.$_course['path'].'/upload/forum/'.$doc_url;
 
-$sql = 'SELECT filename FROM '.$tbl_blogs_attachment.' WHERE path LIKE BINARY "'.$doc_url.'"';
+$sql='SELECT thread_id, forum_id,filename FROM '.$tbl_forum_post.'  f  INNER JOIN '.$tbl_forum_attachment.' a
+  	  ON a.post_id=f.post_id WHERE path LIKE BINARY "'.$doc_url.'"';
+
 $result= api_sql_query($sql, __FILE__, __LINE__);
 $row= Database::fetch_array($result);
-DocumentManager::file_send_for_download($full_file_name,TRUE, $row['filename']);
+
+$forum_thread_visibility=api_get_item_visibility(api_get_course_info($course_code),TOOL_FORUM_THREAD,$row['thread_id']);
+$forum_forum_visibility=api_get_item_visibility(api_get_course_info($course_code),TOOL_FORUM,$row['forum_id']);
+
+if ($forum_thread_visibility==1 && $forum_forum_visibility==1)
+{
+	DocumentManager::file_send_for_download($full_file_name,TRUE, $row['filename']);
+}
 exit;
 ?>

+ 2 - 5
main/forum/forumconfig.inc.php

@@ -20,7 +20,7 @@ $table_threads 			= "`".$_course["dbNameGlu"]."forum_thread"."`";
 $table_posts 			= "`".$_course["dbNameGlu"]."forum_post"."`"; 
 $table_mailcue			= "`".$_course["dbNameGlu"]."forum_mailcue"."`";
  
-$forum_table_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
+$forum_table_attachment = Database :: get_course_table(TABLE_FORUM_ATTACHMENT);
 $table_item_property 	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
 $table_users 			= Database :: get_main_table(TABLE_MAIN_USER);
 
@@ -33,10 +33,7 @@ define("TOOL_FORUM_CATEGORY",'forum_category');
 define("TOOL_FORUM",'forum');
 define("TOOL_FORUM_THREAD",'forum_thread');
 define("TOOL_FORUM_POST",'forum_post');
-
-
-
-
+define("TOOL_FORUM_ATTACH",'forum_attachment');
 /*
 -----------------------------------------------------------
 	Some configuration settings 

+ 35 - 22
main/forum/forumfunction.inc.php

@@ -532,13 +532,9 @@ function delete_forum_forumcategory_thread($content, $id)
 	{
 		$tool_constant=TOOL_FORUM_THREAD;
 		$return_message=get_lang('ThreadDeleted');
-	}
-			
-	api_item_property_update($_course,$tool_constant,$id,"delete",api_get_user_id()); // note: check if this returns a true and if so => return $return_message, if not => return false;
-			
+	}			
+	api_item_property_update($_course,$tool_constant,$id,'delete',api_get_user_id()); // note: check if this returns a true and if so => return $return_message, if not => return false;
 	//delete_attachment($post_id);
-	
-
 	return $return_message;
 }
 
@@ -562,6 +558,7 @@ function delete_post($post_id)
 
 	$sql="DELETE FROM $table_posts WHERE post_id='".Database::escape_string($post_id)."'"; // note: this has to be a recursive function that deletes all of the posts in this block.
 	api_sql_query($sql,__FILE__,__LINE__);
+	
 	delete_attachment($post_id);
 	
 	$last_post_of_thread=check_if_last_post_of_thread(strval(intval($_GET['thread'])));
@@ -584,7 +581,6 @@ function delete_post($post_id)
 		api_sql_query($sql,__FILE__,__LINE__);
 		return 'PostDeletedSpecial';
 	}
-
 }
 
 
@@ -1639,7 +1635,14 @@ function store_thread($values)
 				'".Database::escape_string($visible)."')";
 		api_sql_query($sql, __LINE__, __FILE__);
 		$last_post_id=Database::insert_id();
+				
+		// now have to update the thread table to fill the thread_last_post field (so that we know when the thread has been updated for the last time)
+		$sql="UPDATE $table_threads SET thread_last_post='".Database::escape_string($last_post_id)."'  WHERE thread_id='".Database::escape_string($last_thread_id)."'";
+		$result=api_sql_query($sql, __LINE__, __FILE__);
 	
+		$message=get_lang('NewThreadStored');
+		
+		
 		// Storing the attachments if any
 		if ($has_attachment)
 		{			
@@ -1670,16 +1673,19 @@ function store_thread($values)
 					$sql='INSERT INTO '.$forum_table_attachment.'(filename,comment, path, post_id,size) '.
 						 "VALUES ( '".Database::escape_string($file_name)."', '".Database::escape_string($comment)."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".$_FILES['user_upload']['size']."' )";						
 					$result=api_sql_query($sql, __LINE__, __FILE__);					
-					$message.=' / '.get_lang('AttachmentUpload');			
+					$message.=' / '.get_lang('FileUploadSucces').'<br />';
+					
+					$last_id=Database::insert_id();
+					api_item_property_update($_course, TOOL_FORUM_ATTACH, $last_id ,'ForumAttachmentAdded', api_get_user_id());
+								
 				}			
 			}			 
-		}		
-			
-		// now have to update the thread table to fill the thread_last_post field (so that we know when the thread has been updated for the last time)
-		$sql="UPDATE $table_threads SET thread_last_post='".Database::escape_string($last_post_id)."'  WHERE thread_id='".Database::escape_string($last_thread_id)."'";
-		$result=api_sql_query($sql, __LINE__, __FILE__);
-	
-		$message=get_lang('NewThreadStored').'<br />';
+		}
+		else
+		{
+			$message.='<br />';
+		}
+
 		if ($current_forum['approval_direct_post']=='1' AND !api_is_allowed_to_edit())
 		{
 			$message.=get_lang('MessageHasToBeApproved').'<br />';
@@ -1901,7 +1907,10 @@ function store_reply($values)
 					$sql='INSERT INTO '.$forum_table_attachment.'(filename,comment, path, post_id,size) '.
 						 "VALUES ( '".Database::escape_string($file_name)."', '".Database::escape_string($comment)."', '".Database::escape_string($new_file_name)."' , '".$new_post_id."', '".$_FILES['user_upload']['size']."' )";						
 					$result=api_sql_query($sql, __LINE__, __FILE__);					
-					$message.=' / '.get_lang('AttachmentUpload');			
+					$message.=' / '.get_lang('FileUploadSucces');
+					$last_id=Database::insert_id();
+					
+					api_item_property_update($_course, TOOL_FORUM_ATTACH, $last_id ,'ForumAttachmentAdded', api_get_user_id());							
 				}			
 			}			 
 		}
@@ -1911,7 +1920,8 @@ function store_reply($values)
 	
 		// update the forum
 		api_item_property_update($_course, TOOL_FORUM, $values['forum_id'],"NewMessageInForum", api_get_user_id());
-	
+		
+		
 
 		if ($current_forum['approval_direct_post']=='1' AND !api_is_allowed_to_edit())
 		{
@@ -2950,7 +2960,7 @@ function search_link()
 }
 
 /**
- * Show a list with all the attachments according the post's id
+ * Show a list with all the attachments according to the post's id
  * @param the post's id 
  * @return array with the post info   
  * @author Julio Montoya Dokeos
@@ -2970,8 +2980,8 @@ function get_attachment($post_id)
 	return $row;	
 }
 /**
- * Delete the all the attachments from the DB and the file according the parameters.
- * @param the post's id
+ * Delete the all the attachments from the DB and the file according to the post's id
+ * @param post id
  * @author Julio Montoya Dokeos
  * @version avril 2008, dokeos 1.8.5
  */ 
@@ -2988,10 +2998,13 @@ function delete_attachment($id)
 	$courseDir   = $_course['path'].'/upload/forum';
 	$sys_course_path = api_get_path(SYS_COURSE_PATH);		
 	$updir = $sys_course_path.$courseDir;
-	$file=$updir.'/'.$attach_list['path'];												
+	$file=$updir.'/'.$attach_list['path'];
+	
+	api_item_property_update($_course, TOOL_FORUM_ATTACH, $id ,'ForumAttachmentDelete', api_get_user_id());
+												
 	if (Security::check_abs_path($file,$updir) )
 	{			
 		@ unlink($file);
-	}			
+	}		
 }
 ?>

+ 1 - 1
main/forum/newthread.php

@@ -43,7 +43,7 @@
 */
 
 // name of the language file that needs to be included
-$language_file = 'forum';
+$language_file = array('forum','document');
 
 // including the global dokeos file
 require ('../inc/global.inc.php');

+ 1 - 1
main/forum/reply.php

@@ -43,7 +43,7 @@
 */
 
 // name of the language file that needs to be included
-$language_file = 'forum';
+$language_file = array('forum','document');
 
 // including the global dokeos file
 require ('../inc/global.inc.php');

+ 10 - 6
main/inc/lib/blog.lib.php

@@ -208,18 +208,22 @@ class Blog
 		// Init
 		$tbl_blogs 			= Database::get_course_table(TABLE_BLOGS);
 		$tbl_blogs_posts 	= Database::get_course_table(TABLE_BLOGS_POSTS);
+		$tbl_blogs_comment 	= Database::get_course_table(TABLE_BLOGS_COMMENTS);
 		$tbl_blogs_tasks 	= Database::get_course_table(TABLE_BLOGS_TASKS);
 		$tbl_tool 			= Database::get_course_table(TABLE_TOOL_LIST);
 		$tbl_blogs_rating 	= Database::get_course_table(TABLE_BLOGS_RATING);
-		$tbl_blogs_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
+		$tbl_blogs_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);		
 		
-		
-		// Delete posts and attachments
+		// Delete posts from DB and the attachments 
 		delete_all_blog_attachment($blog_id);
 		
-		// Delete attachments from DB
-		$sql = "DELETE FROM $tbl_blogs_attachment WHERE blog_id ='".(int)$blog_id."'";		
-		api_sql_query($sql, __FILE__, __LINE__);
+		//Delete comments
+		$sql = "DELETE FROM $tbl_blogs_comment WHERE blog_id ='".(int)$blog_id."'";
+   		api_sql_query($sql, __FILE__, __LINE__);	
+   					
+		// Delete posts
+   		$sql = "DELETE FROM $tbl_blogs_posts WHERE blog_id ='".(int)$blog_id."'";
+   		api_sql_query($sql, __FILE__, __LINE__); 		
 				
 		// Delete tasks
 		$sql = "DELETE FROM $tbl_blogs_tasks WHERE blog_id ='".(int)$blog_id."'";