######################################################################################
##
## MOD Title:           Extend_Sync
##
## MOD Author:          Ron, Berlin, Germany        eMail: Ron@RonGS.de
##
## MOD Description:     This mod extends the phpbb-function "sync". If it is needed 
##                      to synchronise a topic, it can happen, that a topic becomes
##                      to be empty of posts. In this case the topic will be 
##                      deleted by standard function "sync".
##                      But if there are some related issues in the watch-table or 
##                      in the vote-tables, these notifications will not be cleared 
##                      by the standard function and so a lot of database garbage 
##                      could be produced. This task will be done by this mod. 
##                      The tables topics_watch_table, vote_desc_table, 
##                      vote_results_table and vote_users_table will be cleared.
##
## Files to edit:       1  
##
##                      includes/functions_admin.php
##
## Included Files:      1
##
##                      Extend_Sync-Install.txt (this file)
##
## Install Level:       easy
##
## Install Time:        5 minutes
##
## Tested Version:      2.0.22
##
## MOD Version:         1.0
##
## MOD History:         2007/03/05  initial release
##
######################################################################################
##
## Important Notice:    For safety reasons make a backup of the related files
##                      and/or the database first!
##        
##                      Although this mod was tested, the author can't guarantee, 
##                      that it will work properly in each system environment nor 
##                      in each version of the phpbb forum software.
##
######################################################################################
##
## Copyright Notice:    Copyright (c) 2007 by Roland Reiche, Berlin, Germany
##
##                      This mod is a contribute to the uncommercial internet.
##                      Feel free to use, copy and modify it as you like.
##                      The only restriction is, that it must not be distributed
##                      for commercial purposes. If you want to use it this way,
##                      please contact me under the email address as noted above.
##
##                      I would appreciate it, if my nickname (Ron) is noted in any 
##                      further software development which is using this mod.
##
######################################################################################

#
#-----[ OPEN FILE ]----------------------------------------------
#
includes/functions_admin.php
#
#-----[ FIND ]---------------------------------------------------
#
	if (!$db->sql_query($sql))
	{
	   message_die(GENERAL_ERROR, 'Could not remove topic', '', __LINE__, __FILE__, $sql);
							}
#
#-----[ AFTER, ADD ]---------------------------------------------
#
	// ***** begin clear related tables *****
	$sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . " WHERE topic_id = $id";
	if (!$db->sql_query($sql)){
		message_die(GENERAL_ERROR, 'Could not remove watch', '', __LINE__, __FILE__, $sql);
		}
		$sql = 'SELECT vote_id FROM ' . VOTE_DESC_TABLE . " WHERE topic_id = $id";
		if (!($result = $db->sql_query($sql))){
			message_die(GENERAL_ERROR, 'Could not get vote desc', '', __LINE__, __FILE__, $sql);
		}
		if ($row = $db->sql_fetchrow($result)){
			if ($vote_id = $row['vote_id']){
				$sql = 'DELETE FROM ' . VOTE_DESC_TABLE . " WHERE vote_id = $vote_id";
				if (!$db->sql_query($sql)){
					message_die(GENERAL_ERROR, 'Could not remove vote desc', '', __LINE__, __FILE__, $sql);
				}
				$sql = 'DELETE FROM ' . VOTE_RESULTS_TABLE . " WHERE vote_id = $vote_id";
				if (!$db->sql_query($sql)){
					message_die(GENERAL_ERROR, 'Could not remove vote results', '', __LINE__, __FILE__, $sql);
				}
				$sql = 'DELETE FROM ' . VOTE_USERS_TABLE . " WHERE vote_id = $vote_id";
				if (!$db->sql_query($sql)){
					message_die(GENERAL_ERROR, 'Could not remove vote users', '', __LINE__, __FILE__, $sql);
				}
			}
		}
	// ***** end clear related tables *****
#
#-----[ SAVE/CLOSE ALL FILES ]-----------------------------------
#
# EoM