if exists (select * from sysobjects where id = object_id(N'[dnt_getadmintopiclist]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dnt_getadmintopiclist]
GO
CREATE PROCEDURE [dnt_getadmintopiclist]
@pagesize int,
@pageindex int,
@startnum int,
@condition varchar(80)
AS
DECLARE @strSQL varchar(5000)
IF @pageindex = 1
BEGIN
SET @strSQL = 'SELECT TOP ' + STR(@pagesize) +' [tid],[iconid],[title],
[poster],[posterid],[replies],[views],[postdatetime],[lastpost],[lastposter],[price],
[lastpostid],[lastposterid],[replies],[highlight],[digest],[displayorder],[closed],[magic] FROM
[dnt_topics] WHERE '+ @condition + ' ORDER BY [lastpostid] DESC'
END
ELSE
BEGIN
SET @strSQL = 'SELECT TOP ' + STR(@pagesize) +' [tid],[iconid],[title],
[special],[poster],[posterid],[replies],[views],[postdatetime],[lastpost],[lastposter],[price],
[lastpostid],[lastposterid],[replies],[highlight],[digest],[displayorder],[closed],[magic] FROM
[dnt_topics] WHERE [lastpostid] < (SELECT min([lastpostid]) FROM (SELECT TOP ' + STR
((@pageindex-1)*@pagesize-@startnum) + ' [lastpostid] FROM [dnt_topics] WHERE [displayorder]=0' + @condition + ' ORDER BY [lastpostid] DESC) AS tblTmp )
AND ' + @condition + ' ORDER BY [lastpostid] DESC'
END
EXEC(@strSQL)
GO
if exists (select * from sysobjects where id = object_id(N'[dnt_deletetopicbytidlist]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dnt_deletetopicbytidlist]
GO
CREATE PROCEDURE [dnt_deletetopicbytidlist]
@tidlist AS VARCHAR(2000),
@posttablename AS VARCHAR(20),
@chanageposts AS BIT
AS
DECLARE @postcount int
DECLARE @topiccount int
DECLARE @todaycount int
DECLARE @sqlstr nvarchar(4000)
DECLARE @fid varchar(2000)
DECLARE @posterid varchar(200)
DECLARE @tempFid int
DECLARE @tempPosterid int
DECLARE @tempLayer int
DECLARE @temppostdatetime datetime
DECLARE @tempfidlist AS VARCHAR(1000)
SET @fid = ''
SET @posterid = ''
SET @postcount=0
SET @topiccount=0
SET @todaycount=0
SET @tempfidlist = '';
IF @tidlist<>''
BEGIN
SET @sqlstr = 'DECLARE cu_dnt_posts CURSOR FOR SELECT [fid],[posterid],[layer],[postdatetime] FROM [' + @posttablename + '] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
OPEN cu_dnt_posts
FETCH NEXT FROM cu_dnt_posts into @tempFid,@tempPosterid,@tempLayer,@temppostdatetime
WHILE @@FETCH_STATUS = 0
BEGIN
SET @postcount = @postcount + 1
IF @tempLayer = 0
BEGIN
SET @topiccount = @topiccount + 1
END
IF DATEDIFF(d,@temppostdatetime,GETDATE()) = 0
BEGIN
SET @todaycount = @todaycount + 1
END
IF CHARINDEX(',' + LTRIM(STR(@tempFid)) + ',',@fid + ',') = 0
BEGIN
--SET @fid = @fid + ',' + LTRIM(STR(@tempFid))
SELECT @tempfidlist = ISNULL([parentidlist],'') FROM [dnt_forums] WHERE [fid] = @tempFid
IF RTRIM(@tempfidlist)<>''
BEGIN
SET @fid = RTRIM(@fid) + ',' + RTRIM(@tempfidlist) + ',' + CAST(@tempFid AS VARCHAR(10))
END
ELSE
BEGIN
SET @fid =RTRIM(@fid) + ',' + CAST(@tempFid AS VARCHAR(10))
END
END
IF @chanageposts = 1
BEGIN
UPDATE [dnt_users] SET [posts] = [posts] - 1 WHERE [uid] = @tempPosterid
END
FETCH NEXT FROM cu_dnt_posts into @tempFid,@tempPosterid,@tempLayer,@temppostdatetime
END
CLOSE cu_dnt_posts
DEALLOCATE cu_dnt_posts
IF LEN(@fid)>0
BEGIN
SET @fid = SUBSTRING(@fid,2,LEN(@fid)-1)
IF @chanageposts = 1
BEGIN
UPDATE [dnt_statistics] SET [totaltopic]=[totaltopic] - @topiccount, [totalpost]=[totalpost] - @postcount
SET @sqlstr = 'UPDATE [dnt_forums] SET [posts]=[posts] - ' + cast(@postcount AS VARCHAR(10)) +
', [topics]=[topics] - ' + cast(@topiccount AS VARCHAR(10)) +
', [todayposts] = [todayposts] - ' + cast(@todaycount AS VARCHAR(10)) +
' WHERE [fid] IN (' + @fid + ')'
EXEC (@sqlstr)
END
SET @sqlstr = 'DELETE FROM [dnt_favorites] WHERE [tid] IN (' + @tidlist + ') AND [typeid]=0'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [dnt_polls] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [' + @posttablename + '] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [dnt_mytopics] WHERE [tid] IN (' + @tidlist + ')'
EXEC(@sqlstr)
END
SET @sqlstr = 'DELETE FROM [dnt_topics] WHERE [closed] IN (' + @tidlist + ') OR [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
SET @sqlstr = 'UPDATE [dnt_tags] SET [count]=[count]-1, [fcount]=[fcount]-1 WHERE [tagid] IN (SELECT [tagid] FROM [dnt_topictags] WHERE [tid] IN (' + @tidlist + '))'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [dnt_topictags] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [dnt_topictagcaches] WHERE [tid] IN (' + @tidlist + ') OR [linktid] IN (' + @tidlist + ')'
END
GO
if exists (select * from sysobjects where id = object_id(N'[dnt_deletepost1bypid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dnt_deletepost1bypid]
GO
CREATE PROCEDURE [dnt_deletepost1bypid]
@pid int,
@chanageposts AS BIT
AS
DECLARE @fid int
DECLARE @tid int
DECLARE @posterid int
DECLARE @lastforumposterid int
DECLARE @layer int
DECLARE @postdatetime smalldatetime
DECLARE @poster varchar(50)
DECLARE @postcount int
DECLARE @title nchar(60)
DECLARE @lasttid int
DECLARE @postid int
DECLARE @todaycount int
SELECT @fid = [fid],@tid = [tid],@posterid = [posterid],@layer = [layer], @postdatetime = [postdatetime] FROM [dnt_posts1] WHERE pid = @pid
DECLARE @fidlist AS VARCHAR(1000)
SET @fidlist = '';
SELECT @fidlist = ISNULL([parentidlist],'') FROM [dnt_forums] WHERE [fid] = @fid
IF RTRIM(@fidlist)<>''
BEGIN
SET @fidlist = RTRIM(@fidlist) + ',' + CAST(@fid AS VARCHAR(10))
END
ELSE
BEGIN
SET @fidlist = CAST(@fid AS VARCHAR(10))
END
IF @layer<>0
BEGIN
IF @chanageposts = 1
BEGIN
UPDATE [dnt_statistics] SET [totalpost]=[totalpost] - 1
UPDATE [dnt_forums] SET
[posts]=[posts] - 1,
[todayposts]=CASE
WHEN DATEPART(yyyy, @postdatetime)=DATEPART(yyyy,GETDATE()) AND DATEPART(mm, @postdatetime)=DATEPART(mm,GETDATE()) AND DATEPART(dd, @postdatetime)=DATEPART(dd,GETDATE()) THEN [todayposts] - 1
ELSE [todayposts]
END
WHERE (CHARINDEX(',' + RTRIM([fid]) + ',', ',' +
(SELECT @fidlist AS [fid]) + ',') > 0)
UPDATE [dnt_users] SET [posts] = [posts] - 1 WHERE [uid] = @posterid
UPDATE [dnt_topics] SET [replies]=[replies] - 1 WHERE [tid]=@tid
END
DELETE FROM [dnt_posts1] WHERE [pid]=@pid
END
ELSE