setup2.2 - 2005.sql
上传用户:wenllgg125
上传日期:2020-04-09
资源大小:7277k
文件大小:192k
源码类别:

SCSI/ASPI

开发平台:

Others

  1. @forumid int,
  2. @forumname nvarchar(100),
  3. @titleid int,
  4. @title nvarchar(160),
  5. @olid int
  6. AS
  7. IF (@action =5 OR @action =6)
  8. BEGIN
  9.    UPDATE [dnt_online] SET [lastactivity]=[action],[action]=@action,[lastupdatetime]=@lastupdatetime,[lastposttime]= @lastupdatetime,[forumid]=@forumid,[forumname]=@forumname,[titleid]=@titleid,[title]=@title WHERE [olid]=@olid
  10. END
  11. ELSE
  12. BEGIN
  13.    UPDATE [dnt_online] SET [lastactivity]=[action],[action]=@action,[lastupdatetime]=@lastupdatetime,[forumid]=@forumid,[forumname]=@forumname,[titleid]=@titleid,[title]=@title WHERE [olid]=@olid
  14. END
  15. GO
  16. IF OBJECT_ID('dnt_getindexforumlist','P') IS NOT NULL
  17. DROP PROC [dnt_getindexforumlist]
  18. GO
  19. CREATE PROCEDURE [dnt_getindexforumlist]
  20. AS
  21. SELECT CASE WHEN DATEDIFF(n, [lastpost], GETDATE())<600 THEN 'new' ELSE 'old' END AS [havenew],
  22. [dnt_forums].[allowbbcode],
  23. [dnt_forums].[allowblog],
  24. [dnt_forums].[alloweditrules],
  25. [dnt_forums].[allowhtml],
  26. [dnt_forums].[allowimgcode],
  27. [dnt_forums].[allowpostspecial],
  28. [dnt_forums].[allowrss],
  29. [dnt_forums].[allowsmilies],
  30. [dnt_forums].[allowspecialonly],
  31. [dnt_forums].[allowtag],
  32. [dnt_forums].[allowthumbnail],
  33. [dnt_forums].[autoclose],
  34. [dnt_forums].[colcount],
  35. [dnt_forums].[curtopics],
  36. [dnt_forums].[disablewatermark],
  37. [dnt_forums].[displayorder],
  38. [dnt_forums].[fid],
  39. [dnt_forums].[inheritedmod],
  40. [dnt_forums].[istrade],
  41. [dnt_forums].[jammer],
  42. [dnt_forums].[lastpost],
  43. [dnt_forums].[lastposter],
  44. [dnt_forums].[lastposterid],
  45. [dnt_forums].[lasttid],
  46. [dnt_forums].[lasttitle],
  47. [dnt_forums].[layer],
  48. [dnt_forums].[modnewposts],
  49. [dnt_forums].[name],
  50. [dnt_forums].[parentid],
  51. [dnt_forums].[parentidlist],
  52. [dnt_forums].[pathlist],
  53. [dnt_forums].[posts],
  54. [dnt_forums].[recyclebin],
  55. [dnt_forums].[status],
  56. [dnt_forums].[subforumcount],
  57. [dnt_forums].[templateid],
  58. [dnt_forums].[todayposts],
  59. [dnt_forums].[topics],
  60. [dnt_forumfields].[applytopictype],
  61. [dnt_forumfields].[attachextensions],
  62. [dnt_forumfields].[description],
  63. [dnt_forumfields].[fid],
  64. [dnt_forumfields].[getattachperm],
  65. [dnt_forumfields].[icon],
  66. [dnt_forumfields].[moderators],
  67. [dnt_forumfields].[password],
  68. [dnt_forumfields].[permuserlist],
  69. [dnt_forumfields].[postattachperm],
  70. [dnt_forumfields].[postbytopictype],
  71. [dnt_forumfields].[postcredits],
  72. [dnt_forumfields].[postperm],
  73. [dnt_forumfields].[redirect],
  74. [dnt_forumfields].[replycredits],
  75. [dnt_forumfields].[replyperm],
  76. [dnt_forumfields].[rewritename],
  77. [dnt_forumfields].[rules],
  78. [dnt_forumfields].[seodescription],
  79. [dnt_forumfields].[seokeywords],
  80. [dnt_forumfields].[topictypeprefix],
  81. [dnt_forumfields].[topictypes],
  82. [dnt_forumfields].[viewbytopictype],
  83. [dnt_forumfields].[viewperm]
  84. FROM [dnt_forums] 
  85. LEFT JOIN [dnt_forumfields] ON [dnt_forums].[fid]=[dnt_forumfields].[fid] 
  86. WHERE [dnt_forums].[status] > 0 AND [layer] <= 1 
  87. AND [dnt_forums].[parentid] NOT IN (SELECT [fid] FROM [dnt_forums] WHERE [status] < 1 AND [layer] = 0) ORDER BY [displayorder]
  88. GO
  89. IF OBJECT_ID('[dnt_getonlineuser]','P') IS NOT NULL
  90. DROP PROC [dnt_getonlineuser]
  91. GO
  92. CREATE PROCEDURE [dnt_getonlineuser]
  93. @userid int,
  94. @password char(32)
  95. AS
  96. SELECT TOP 1 [olid]
  97.       ,[userid]
  98.       ,[ip]
  99.       ,[username]
  100.       ,[nickname]
  101.       ,[password]
  102.       ,[groupid]
  103.       ,[olimg]
  104.       ,[adminid]
  105.       ,[invisible]
  106.       ,[action]
  107.       ,[lastactivity]
  108.       ,[lastposttime]
  109.       ,[lastpostpmtime]
  110.       ,[lastsearchtime]
  111.       ,[lastupdatetime]
  112.       ,[forumid]
  113.       ,[forumname]
  114.       ,[titleid]
  115.       ,[title]
  116.       ,[verifycode]
  117.       ,[newpms]
  118.       ,[newnotices] FROM [dnt_online] WHERE [userid]=@userid AND [password]=@password
  119. GO
  120. IF OBJECT_ID('[dnt_getonlineuserlist]','P') IS NOT NULL
  121. DROP PROC [dnt_getonlineuserlist]
  122. GO
  123. CREATE PROCEDURE [dnt_getonlineuserlist]
  124. AS
  125. SELECT [olid]
  126.       ,[userid]
  127.       ,[ip]
  128.       ,[username]
  129.       ,[nickname]
  130.       ,[password]
  131.       ,[groupid]
  132.       ,[olimg]
  133.       ,[adminid]
  134.       ,[invisible]
  135.       ,[action]
  136.       ,[lastactivity]
  137.       ,[lastposttime]
  138.       ,[lastpostpmtime]
  139.       ,[lastsearchtime]
  140.       ,[lastupdatetime]
  141.       ,[forumid]
  142.       ,[forumname]
  143.       ,[titleid]
  144.       ,[title]
  145.       ,[verifycode]
  146.       ,[newpms]
  147.       ,[newnotices] FROM [dnt_online]
  148. GO
  149. IF OBJECT_ID('[dnt_getonlineuserlistbyfid]','P') IS NOT NULL
  150. DROP PROC [dnt_getonlineuserlistbyfid]
  151. GO
  152. CREATE PROCEDURE [dnt_getonlineuserlistbyfid]
  153. @fid int
  154. AS
  155. SELECT [olid]
  156.       ,[userid]
  157.       ,[ip]
  158.       ,[username]
  159.       ,[nickname]
  160.       ,[password]
  161.       ,[groupid]
  162.       ,[olimg]
  163.       ,[adminid]
  164.       ,[invisible]
  165.       ,[action]
  166.       ,[lastactivity]
  167.       ,[lastposttime]
  168.       ,[lastpostpmtime]
  169.       ,[lastsearchtime]
  170.       ,[lastupdatetime]
  171.       ,[forumid]
  172.       ,[forumname]
  173.       ,[titleid]
  174.       ,[title]
  175.       ,[verifycode]
  176.       ,[newpms]
  177.       ,[newnotices] FROM [dnt_online] WHERE [forumid]=@fid
  178. GO
  179. IF OBJECT_ID('dnt_getrelatedtopics','P') IS NOT NULL
  180. DROP PROCEDURE [dnt_getrelatedtopics]
  181. GO
  182. CREATE PROCEDURE [dnt_getrelatedtopics]
  183. @count int,
  184. @tid int
  185. AS
  186. SELECT TOP(@count) 
  187. [dnt_topictagcaches].[linktid],
  188. [dnt_topictagcaches].[linktitle],
  189. [dnt_topictagcaches].[tid]
  190. FROM [dnt_topictagcaches] WHERE [tid]=@tid ORDER BY [linktid] DESC
  191. GO
  192. IF OBJECT_ID('[dnt_gettopicinfo]','P') IS NOT NULL
  193. DROP PROC [dnt_gettopicinfo]
  194. GO
  195. CREATE PROCEDURE [dnt_gettopicinfo]
  196. @tid int,
  197. @fid int,
  198. @mode int
  199. AS
  200. IF @mode = 1
  201. BEGIN
  202.        SELECT TOP 1 [tid]
  203.       ,[fid]
  204.       ,[iconid]
  205.       ,[readperm]
  206.       ,[price]
  207.       ,[poster]
  208.       ,[posterid]
  209.       ,[title]
  210.       ,[postdatetime]
  211.       ,[lastpost]
  212.       ,[lastpostid]
  213.       ,[lastposter]
  214.       ,[lastposterid]
  215.       ,[views]
  216.       ,[replies]
  217.       ,[displayorder]
  218.       ,[highlight]
  219.       ,[digest]
  220.       ,[hide]
  221.       ,[attachment]
  222.       ,[moderated]
  223.       ,[closed]
  224.       ,[magic]
  225.       ,[identify]
  226.       ,[special]
  227.       ,[typeid]
  228.       ,[rate]
  229.       ,[attention] FROM [dnt_topics] WHERE [fid]=@fid AND [tid]<@tid AND [displayorder]>=0 ORDER BY [tid] DESC
  230. END
  231. ELSE IF @mode = 2
  232. BEGIN
  233.        SELECT TOP 1 [tid]
  234.       ,[fid]
  235.       ,[iconid]
  236.       ,[readperm]
  237.       ,[price]
  238.       ,[poster]
  239.       ,[posterid]
  240.       ,[title]
  241.       ,[postdatetime]
  242.       ,[lastpost]
  243.       ,[lastpostid]
  244.       ,[lastposter]
  245.       ,[lastposterid]
  246.       ,[views]
  247.       ,[replies]
  248.       ,[displayorder]
  249.       ,[highlight]
  250.       ,[digest]
  251.       ,[hide]
  252.       ,[attachment]
  253.       ,[moderated]
  254.       ,[closed]
  255.       ,[magic]
  256.       ,[identify]
  257.       ,[special]
  258.       ,[typeid]
  259.       ,[rate]
  260.       ,[attention] FROM [dnt_topics] WHERE [fid]=@fid AND [tid]>@tid AND [displayorder]>=0 ORDER BY [tid] ASC
  261. END
  262. ELSE
  263. BEGIN
  264.        SELECT TOP 1 [tid]
  265.       ,[fid]
  266.       ,[iconid]
  267.       ,[readperm]
  268.       ,[price]
  269.       ,[poster]
  270.       ,[posterid]
  271.       ,[title]
  272.       ,[postdatetime]
  273.       ,[lastpost]
  274.       ,[lastpostid]
  275.       ,[lastposter]
  276.       ,[lastposterid]
  277.       ,[views]
  278.       ,[replies]
  279.       ,[displayorder]
  280.       ,[highlight]
  281.       ,[digest]
  282.       ,[hide]
  283.       ,[attachment]
  284.       ,[moderated]
  285.       ,[closed]
  286.       ,[magic]
  287.       ,[identify]
  288.       ,[special]
  289.       ,[typeid]
  290.       ,[rate]
  291.       ,[attention] FROM [dnt_topics] WHERE [tid]=@tid
  292. END
  293. GO
  294. if exists (select * from sysobjects where id = object_id(N'[dnt_gettopictags]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
  295. drop procedure [dnt_gettopictags]
  296. GO
  297. CREATE PROCEDURE [dnt_gettopictags]
  298. @topicid int
  299. AS
  300. SELECT 
  301. t.[color],
  302. t.[count],
  303. t.[fcount],
  304. t.[gcount],
  305. t.[orderid],
  306. t.[pcount],
  307. t.[postdatetime],
  308. t.[scount],
  309. t.[tagid],
  310. t.[tagname],
  311. t.[userid],
  312. t.[vcount]
  313. FROM [dnt_tags] t, [dnt_topictags] tt 
  314. WHERE tt.[tagid] = t.[tagid] AND tt.[tid] = @topicid 
  315. ORDER BY [orderid]
  316. GO
  317. IF OBJECT_ID('[dnt_createonlineuser]','P') IS NOT NULL
  318. DROP PROC [dnt_createonlineuser]
  319. GO
  320. CREATE PROCEDURE [dnt_createonlineuser] 
  321. @onlinestate int,
  322. @userid int,
  323. @ip varchar(15),
  324. @username nvarchar(40),
  325. @nickname nvarchar(40),
  326. @password char(32),
  327. @groupid smallint,
  328. @olimg varchar(80),
  329. @adminid smallint,
  330. @invisible smallint,
  331. @action smallint,
  332. @lastactivity smallint,
  333. @lastposttime datetime,
  334. @lastpostpmtime datetime,
  335. @lastsearchtime datetime,
  336. @lastupdatetime datetime,
  337. @forumid int,
  338. @forumname nvarchar(50),
  339. @titleid int,
  340. @title nvarchar(80),
  341. @verifycode varchar(10),
  342. @newpms smallint,
  343. @newnotices smallint
  344. AS
  345. IF @onlinestate = 0
  346. BEGIN
  347. UPDATE [dnt_users] SET [onlinestate]=1 WHERE [uid]=@userid
  348. END
  349. INSERT INTO [dnt_online] ([userid],[ip],[username],[nickname],[password],[groupid],[olimg],[adminid],[invisible],[action],[lastactivity],[lastposttime],[lastpostpmtime],[lastsearchtime],[lastupdatetime],[forumid],[forumname],[titleid],[title],[verifycode],[newpms],[newnotices])VALUES(@userid,@ip,@username,@nickname,@password,@groupid,@olimg,@adminid,@invisible,@action,@lastactivity,@lastposttime,@lastpostpmtime,@lastsearchtime,@lastupdatetime,@forumid,@forumname,@titleid,@title,@verifycode,@newpms,@newnotices);SELECT SCOPE_IDENTITY()
  350. GO
  351. IF OBJECT_ID('dnt_deleteonlineusers','P') IS NOT NULL
  352. DROP PROCEDURE [dnt_deleteonlineusers]
  353. GO
  354. CREATE PROCEDURE [dnt_deleteonlineusers] 
  355. @olidlist varchar(5000) = ''
  356. AS
  357. DELETE FROM [dnt_online] WHERE CHARINDEX(','+RTRIM([olid])+',', ','+@olidlist+',') > 0
  358. GO
  359. IF OBJECT_ID('dnt_getindexforumlist','P') IS NOT NULL
  360. DROP PROC [dnt_getindexforumlist]
  361. GO
  362. CREATE PROCEDURE [dnt_getindexforumlist]
  363. AS
  364. SELECT CASE WHEN DATEDIFF(n, [lastpost], GETDATE())<600 THEN 'new' ELSE 'old' END AS [havenew],
  365. [dnt_forums].[allowbbcode],
  366. [dnt_forums].[allowblog],
  367. [dnt_forums].[alloweditrules],
  368. [dnt_forums].[allowhtml],
  369. [dnt_forums].[allowimgcode],
  370. [dnt_forums].[allowpostspecial],
  371. [dnt_forums].[allowrss],
  372. [dnt_forums].[allowsmilies],
  373. [dnt_forums].[allowspecialonly],
  374. [dnt_forums].[allowtag],
  375. [dnt_forums].[allowthumbnail],
  376. [dnt_forums].[autoclose],
  377. [dnt_forums].[colcount],
  378. [dnt_forums].[curtopics],
  379. [dnt_forums].[disablewatermark],
  380. [dnt_forums].[displayorder],
  381. [dnt_forums].[fid],
  382. [dnt_forums].[inheritedmod],
  383. [dnt_forums].[istrade],
  384. [dnt_forums].[jammer],
  385. [dnt_forums].[lastpost],
  386. [dnt_forums].[lastposter],
  387. [dnt_forums].[lastposterid],
  388. [dnt_forums].[lasttid],
  389. [dnt_forums].[lasttitle],
  390. [dnt_forums].[layer],
  391. [dnt_forums].[modnewposts],
  392. [dnt_forums].[name],
  393. [dnt_forums].[parentid],
  394. [dnt_forums].[parentidlist],
  395. [dnt_forums].[pathlist],
  396. [dnt_forums].[posts],
  397. [dnt_forums].[recyclebin],
  398. [dnt_forums].[status],
  399. [dnt_forums].[subforumcount],
  400. [dnt_forums].[templateid],
  401. [dnt_forums].[todayposts],
  402. [dnt_forums].[topics],
  403. [dnt_forumfields].[applytopictype],
  404. [dnt_forumfields].[attachextensions],
  405. [dnt_forumfields].[description],
  406. [dnt_forumfields].[fid],
  407. [dnt_forumfields].[getattachperm],
  408. [dnt_forumfields].[icon],
  409. [dnt_forumfields].[moderators],
  410. [dnt_forumfields].[password],
  411. [dnt_forumfields].[permuserlist],
  412. [dnt_forumfields].[postattachperm],
  413. [dnt_forumfields].[postbytopictype],
  414. [dnt_forumfields].[postcredits],
  415. [dnt_forumfields].[postperm],
  416. [dnt_forumfields].[redirect],
  417. [dnt_forumfields].[replycredits],
  418. [dnt_forumfields].[replyperm],
  419. [dnt_forumfields].[rewritename],
  420. [dnt_forumfields].[rules],
  421. [dnt_forumfields].[seodescription],
  422. [dnt_forumfields].[seokeywords],
  423. [dnt_forumfields].[topictypeprefix],
  424. [dnt_forumfields].[topictypes],
  425. [dnt_forumfields].[viewbytopictype],
  426. [dnt_forumfields].[viewperm]
  427. FROM [dnt_forums] 
  428. LEFT JOIN [dnt_forumfields] ON [dnt_forums].[fid]=[dnt_forumfields].[fid] 
  429. WHERE [dnt_forums].[parentid] NOT IN (SELECT [fid] FROM [dnt_forums] WHERE [status] < 1 AND [layer] = 0) 
  430. AND [dnt_forums].[status] > 0 AND [layer] <= 1 ORDER BY [displayorder]
  431. GO
  432. IF OBJECT_ID('dnt_updateuseronlinestates','P') IS NOT NULL
  433. DROP PROCEDURE [dnt_updateuseronlinestates]
  434. GO
  435. CREATE PROCEDURE [dnt_updateuseronlinestates] 
  436. @uidlist varchar(5000) = '' 
  437. AS
  438. EXEC ('UPDATE [dnt_users] SET [onlinestate]=0,[lastactivity]=GETDATE() WHERE [uid] IN ('+@uidlist+')')
  439. GO
  440. IF OBJECT_ID('dnt_getonlineuserbyip','P') IS NOT NULL
  441. DROP PROCEDURE [dnt_getonlineuserbyip]
  442. GO
  443. CREATE PROCEDURE [dnt_getonlineuserbyip]
  444. @userid int,
  445. @ip varchar(15)
  446. AS
  447. SELECT TOP 1 [olid]
  448.       ,[userid]
  449.       ,[ip]
  450.       ,[username]
  451.       ,[nickname]
  452.       ,[password]
  453.       ,[groupid]
  454.       ,[olimg]
  455.       ,[adminid]
  456.       ,[invisible]
  457.       ,[action]
  458.       ,[lastactivity]
  459.       ,[lastposttime]
  460.       ,[lastpostpmtime]
  461.       ,[lastsearchtime]
  462.       ,[lastupdatetime]
  463.       ,[forumid]
  464.       ,[forumname]
  465.       ,[titleid]
  466.       ,[title]
  467.       ,[verifycode]
  468.       ,[newpms]
  469.       ,[newnotices] FROM [dnt_online] WHERE [userid]=@userid AND [ip]=@ip
  470. GO
  471. if exists (select * from sysobjects where id = object_id(N'[dnt_gettodayuploadedfilesize]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
  472. drop procedure [dnt_gettodayuploadedfilesize]
  473. GO
  474. if exists (select * from sysobjects where id = object_id(N'[dnt_getuseridbyemail]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
  475. drop procedure [dnt_getuseridbyemail]
  476. GO
  477. if exists (select * from sysobjects where id = object_id(N'[dnt_getuserinfobyip]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
  478. drop procedure [dnt_getuserinfobyip]
  479. GO
  480. IF OBJECT_ID('dnt_getreplypid1','P') IS NOT NULL
  481. DROP PROCEDURE [dnt_getreplypid1]
  482. GO
  483. CREATE PROCEDURE [dnt_getreplypid1]
  484. @uid int,
  485. @tid int
  486. AS
  487. SELECT TOP 1 [pid] FROM [dnt_posts1] WHERE [tid] =@tid AND [posterid]=@uid
  488. GO
  489. IF OBJECT_ID('[dnt_gettodayuploadedfilesize]','P') IS NOT NULL
  490. DROP PROC [dnt_gettodayuploadedfilesize]
  491. GO
  492. CREATE PROCEDURE [dnt_gettodayuploadedfilesize] 
  493. @uid int
  494. AS
  495. SELECT SUM([filesize]) AS [todaysize] FROM [dnt_attachments] WHERE [uid]=@uid AND DATEDIFF(d,[postdatetime],GETDATE())=0
  496. GO
  497. IF OBJECT_ID('[dnt_getuseridbyemail]','P') IS NOT NULL
  498. DROP PROC [dnt_getuseridbyemail]
  499. GO
  500. CREATE PROCEDURE [dnt_getuseridbyemail]
  501. @email char(50)
  502. AS
  503. SELECT TOP 1 [uid] FROM [dnt_users] WHERE [email]=@email
  504. GO
  505. IF OBJECT_ID('[dnt_getuserinfobyip]','P') IS NOT NULL
  506. DROP PROC [dnt_getuserinfobyip]
  507. GO
  508. CREATE PROCEDURE [dnt_getuserinfobyip]
  509. @regip char(15)
  510. AS
  511. SELECT TOP 1 [u].[uid], [u].[username], [u].[nickname], [u].[password], [u].[secques], [u].[spaceid], [u].[gender], [u].[adminid], [u].[groupid], [u].[groupexpiry], [u].[extgroupids], [u].[regip], [u].[joindate], [u].[lastip], [u].[lastvisit], [u].[lastactivity], [u].[lastpost], [u].[lastpostid], [u].[lastposttitle], [u].[posts], [u].[digestposts], [u].[oltime], [u].[pageviews], [u].[credits], [u].[extcredits1], [u].[extcredits2], [u].[extcredits3], [u].[extcredits4], [u].[extcredits5], [u].[extcredits6], [u].[extcredits7], [u].[extcredits8], [u].[avatarshowid], [u].[email], [u].[bday], [u].[sigstatus], [u].[tpp], [u].[ppp], [u].[templateid], [u].[pmsound], [u].[showemail], [u].[invisible], [u].[newpm], [u].[newpmcount], [u].[accessmasks], [u].[onlinestate], [u].[newsletter],[u].[salt], [uf].[website], [uf].[icq], [uf].[qq], [uf].[yahoo], [uf].[msn], [uf].[skype], [uf].[location], [uf].[customstatus], [uf].[avatar], [uf].[avatarwidth], [uf].[avatarheight], [uf].[medals], [uf].[bio], [uf].[signature], [uf].[sightml], [uf].[authstr], [uf].[authtime], [uf].[authflag], [uf].[realname], [uf].[idcard], [uf].[mobile], [uf].[phone], [uf].[ignorepm] FROM [dnt_users] [u] LEFT JOIN [dnt_userfields] [uf] ON [u].[uid]=[uf].[uid] WHERE [u].[regip]=@regip ORDER BY [u].[uid] DESC
  512. GO
  513. if exists (select * from sysobjects where id = object_id(N'[dnt_getnoticebyuid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
  514. drop procedure [dnt_getnoticebyuid]
  515. GO
  516. CREATE PROCEDURE [dnt_getnoticebyuid]
  517. @uid int,
  518. @type int
  519. AS
  520. IF @type = 0
  521.      SELECT nid, uid, type, new, posterid, poster, note, postdatetime FROM [dnt_notices] WHERE [uid] = @uid  ORDER BY [postdatetime] DESC
  522. ELSE
  523.     SELECT nid, uid, type, new, posterid, poster, note, postdatetime  FROM [dnt_notices] WHERE [uid] = @uid AND [type] = @type ORDER BY [postdatetime] DESC
  524. GO
  525. if exists (select * from sysobjects where id = object_id(N'[dnt_createnotice]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
  526. drop procedure [dnt_createnotice]
  527. GO
  528. CREATE PROCEDURE [dnt_createnotice]
  529. @uid int,
  530. @type int,
  531. @new  int,
  532. @posterid int,
  533. @poster nchar(20),
  534. @note ntext,
  535. @postdatetime datetime
  536. AS
  537. INSERT INTO [dnt_notices] ([uid], [type], [new], [posterid], [poster], [note], [postdatetime]) VALUES (@uid, @type, @new, @posterid, @poster, @note, @postdatetime);
  538. SELECT SCOPE_IDENTITY()  AS 'nid'
  539. GO
  540. if exists (select * from sysobjects where id = object_id(N'[dnt_getnewnoticecountbyuid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
  541. drop procedure [dnt_getnewnoticecountbyuid]
  542. GO
  543. CREATE PROCEDURE [dnt_getnewnoticecountbyuid]
  544. @uid int
  545. AS
  546. SELECT COUNT(nid) FROM [dnt_notices] WHERE [uid] =  @uid  AND [new] = 1
  547. GO
  548. if exists (select * from sysobjects where id = object_id(N'[dnt_getnoticecountbyuid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
  549. drop procedure [dnt_getnoticecountbyuid]
  550. GO
  551. CREATE PROCEDURE [dnt_getnoticecountbyuid]
  552. @uid int,
  553. @type int
  554. AS
  555. IF @type = -1
  556.    SELECT COUNT(nid) FROM [dnt_notices] WHERE [uid] = @uid
  557. ELSE
  558.     SELECT COUNT(nid) FROM [dnt_notices] WHERE [uid] = @uid AND [type]=@type
  559. GO
  560. IF OBJECT_ID ('dnt_getpostlist1','P') IS NOT NULL
  561. DROP PROCEDURE [dnt_getpostlist1]
  562. GO
  563. CREATE PROCEDURE [dnt_getpostlist1]
  564. @tid int,
  565. @pagesize int,
  566. @pageindex int
  567. AS
  568. DECLARE @startRow int,
  569. @endRow int
  570. SET @startRow = (@pageIndex - 1) * @pageSize +1
  571. SET @endRow = @startRow + @pageSize -1 
  572. SELECT 
  573. [POSTS].[pid],
  574. [POSTS].[fid], 
  575. [POSTS].[title], 
  576. [POSTS].[layer],
  577. [POSTS].[message], 
  578. [POSTS].[ip], 
  579. [POSTS].[lastedit], 
  580. [POSTS].[postdatetime], 
  581. [POSTS].[attachment], 
  582. [POSTS].[poster], 
  583. [POSTS].[posterid], 
  584. [POSTS].[invisible], 
  585. [POSTS].[usesig], 
  586. [POSTS].[htmlon], 
  587. [POSTS].[smileyoff], 
  588. [POSTS].[parseurloff], 
  589. [POSTS].[bbcodeoff], 
  590. [POSTS].[rate], 
  591. [POSTS].[ratetimes],  
  592. [POSTS].[nickname],  
  593. [POSTS].[username], 
  594. [POSTS].[groupid], 
  595. [POSTS].[spaceid],
  596. [POSTS].[gender],
  597. [POSTS].[bday],
  598. [POSTS].[email], 
  599. [POSTS].[showemail], 
  600. [POSTS].[digestposts], 
  601. [POSTS].[credits], 
  602. [POSTS].[extcredits1], 
  603. [POSTS].[extcredits2], 
  604. [POSTS].[extcredits3], 
  605. [POSTS].[extcredits4], 
  606. [POSTS].[extcredits5], 
  607. [POSTS].[extcredits6], 
  608. [POSTS].[extcredits7], 
  609. [POSTS].[extcredits8], 
  610. [POSTS].[posts], 
  611. [POSTS].[joindate], 
  612. [POSTS].[onlinestate],
  613. [POSTS].[lastactivity],  
  614. [POSTS].[userinvisible], 
  615. [POSTS].[avatar], 
  616. [POSTS].[avatarwidth], 
  617. [POSTS].[avatarheight], 
  618. [POSTS].[medals],
  619. [POSTS].[signature], 
  620. [POSTS].[location], 
  621. [POSTS].[customstatus], 
  622. [POSTS].[website], 
  623. [POSTS].[icq], 
  624. [POSTS].[qq], 
  625. [POSTS].[msn], 
  626. [POSTS].[yahoo],
  627. [POSTS].[oltime],
  628. [POSTS].[lastvisit],
  629. [POSTS].[skype] 
  630. FROM (SELECT ROW_NUMBER() OVER(ORDER BY pid)AS ROWID,
  631. [dnt_posts1].[pid],
  632. [dnt_posts1].[fid], 
  633. [dnt_posts1].[title], 
  634. [dnt_posts1].[layer],
  635. [dnt_posts1].[message], 
  636. [dnt_posts1].[ip], 
  637. [dnt_posts1].[lastedit], 
  638. [dnt_posts1].[postdatetime], 
  639. [dnt_posts1].[attachment], 
  640. [dnt_posts1].[poster], 
  641. [dnt_posts1].[posterid], 
  642. [dnt_posts1].[invisible], 
  643. [dnt_posts1].[usesig], 
  644. [dnt_posts1].[htmlon], 
  645. [dnt_posts1].[smileyoff], 
  646. [dnt_posts1].[parseurloff], 
  647. [dnt_posts1].[bbcodeoff], 
  648. [dnt_posts1].[rate], 
  649. [dnt_posts1].[ratetimes],  
  650. [dnt_users].[nickname],  
  651. [dnt_users].[username], 
  652. [dnt_users].[groupid], 
  653. [dnt_users].[spaceid],
  654. [dnt_users].[gender],
  655. [dnt_users].[bday],
  656. [dnt_users].[email], 
  657. [dnt_users].[showemail], 
  658. [dnt_users].[digestposts], 
  659. [dnt_users].[credits], 
  660. [dnt_users].[extcredits1], 
  661. [dnt_users].[extcredits2], 
  662. [dnt_users].[extcredits3], 
  663. [dnt_users].[extcredits4], 
  664. [dnt_users].[extcredits5], 
  665. [dnt_users].[extcredits6], 
  666. [dnt_users].[extcredits7], 
  667. [dnt_users].[extcredits8], 
  668. [dnt_users].[posts], 
  669. [dnt_users].[joindate], 
  670. [dnt_users].[onlinestate],
  671. [dnt_users].[lastactivity],
  672. [dnt_users].[oltime],
  673. [dnt_users].[lastvisit],
  674. [dnt_users].[invisible] AS [userinvisible], 
  675. [dnt_userfields].[avatar], 
  676. [dnt_userfields].[avatarwidth], 
  677. [dnt_userfields].[avatarheight], 
  678. [dnt_userfields].[medals],
  679. [dnt_userfields].[sightml] AS [signature], 
  680. [dnt_userfields].[location], 
  681. [dnt_userfields].[customstatus], 
  682. [dnt_userfields].[website], 
  683. [dnt_userfields].[icq], 
  684. [dnt_userfields].[qq], 
  685. [dnt_userfields].[msn], 
  686. [dnt_userfields].[yahoo], 
  687. [dnt_userfields].[skype]
  688. FROM [dnt_posts1] LEFT JOIN [dnt_users] ON [dnt_users].[uid]=[dnt_posts1].[posterid] LEFT JOIN [dnt_userfields] ON [dnt_userfields].[uid]=[dnt_users].[uid] 
  689. WHERE [tid] = @tid AND [dnt_posts1].[invisible] <=0) AS POSTS 
  690. WHERE ROWID BETWEEN @startRow AND @endRow
  691. GO
  692. if exists (select * from sysobjects where id = object_id(N'[dnt_getexpiredonlineuserlist]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
  693. drop procedure [dnt_getexpiredonlineuserlist]
  694. GO
  695. CREATE PROCEDURE [dnt_getexpiredonlineuserlist]
  696. @expires datetime
  697. AS
  698. SELECT [olid], [userid] FROM [dnt_online] WHERE [lastupdatetime]<@expires
  699. GO
  700. IF OBJECT_ID('dnt_getfirstpost1id','P') IS NOT NULL
  701. DROP PROC dnt_getfirstpost1id
  702. GO
  703. CREATE PROCEDURE dnt_getfirstpost1id
  704. @tid int
  705. AS
  706. SELECT TOP 1 [pid] FROM [dnt_posts1] WHERE [tid]=@tid ORDER BY [pid]
  707. GO
  708. IF OBJECT_ID('dnt_getattachpaymentlogbyaid','P') IS NOT NULL
  709. DROP PROC [dnt_getattachpaymentlogbyaid]
  710. GO
  711. CREATE PROCEDURE [dnt_getattachpaymentlogbyaid]
  712. @aid int
  713. AS
  714. SELECT 
  715. [id],
  716. [uid],
  717. [username],
  718. [aid],
  719. [authorid],
  720. [postdatetime],
  721. [amount],
  722. [netamount]
  723. FROM [dnt_attachpaymentlog]
  724. WHERE [aid] = @aid
  725. GO
  726. IF OBJECT_ID('dnt_getonlineuercount','P') IS NOT NULL
  727. DROP PROC [dnt_getonlineuercount]
  728. GO
  729. CREATE PROCEDURE [dnt_getonlineuercount]
  730. AS
  731. SELECT COUNT(olid) FROM [dnt_online]
  732. GO
  733. IF OBJECT_ID('dnt_getalltoptopiclist','P') IS NOT NULL
  734. DROP PROC [dnt_getalltoptopiclist]
  735. GO
  736. CREATE PROCEDURE [dnt_getalltoptopiclist]
  737. AS
  738. SELECT 
  739. [tid],
  740. [displayorder],
  741. [fid] 
  742. FROM [dnt_topics] 
  743. WHERE [displayorder] > 0 ORDER BY [fid]
  744. GO
  745. IF OBJECT_ID('dnt_getattachpaymentlogbyuid','P') IS NOT NULL
  746. DROP PROC [dnt_getattachpaymentlogbyuid]
  747. GO
  748. CREATE PROCEDURE [dnt_getattachpaymentlogbyuid]
  749. @attachidlist varchar(500),
  750. @uid int
  751. AS
  752. EXEC('
  753. SELECT 
  754. [aid]
  755. FROM [dnt_attachpaymentlog] 
  756. WHERE [uid] = '+@uid+ ' AND [dnt_attachpaymentlog].[aid] IN ('+@attachidlist+')
  757. ')
  758. GO
  759. IF OBJECT_ID('dnt_getnousedforumattachment','P') IS NOT NULL
  760. DROP PROC [dnt_getnousedforumattachment]
  761. GO
  762. CREATE PROCEDURE [dnt_getnousedforumattachment]
  763. AS
  764. SELECT 
  765. [aid],
  766. [uid],
  767. [tid],
  768. [pid],
  769. [postdatetime],
  770. [readperm],
  771. [filename],
  772. [description],
  773. [filetype],
  774. [filesize],
  775. [attachment],
  776. [downloads],
  777. [attachprice],
  778. [width],
  779. [height]
  780. FROM [dnt_attachments] 
  781. WHERE [tid]= 0 AND [pid]=0 AND DATEDIFF(n, postdatetime, GETDATE()) > 30 
  782. GO
  783. IF OBJECT_ID('dnt_deletenousedforumattachment','P') IS NOT NULL
  784. DROP PROC [dnt_deletenousedforumattachment]
  785. GO
  786. CREATE PROCEDURE [dnt_deletenousedforumattachment]
  787. AS
  788. DELETE FROM [dnt_attachments] 
  789. WHERE [tid]= 0 AND [pid]=0 AND DATEDIFF(n, postdatetime, GETDATE()) > 30
  790. GO
  791. IF OBJECT_ID('dnt_getnousedattachmentlistbytid','P') IS NOT NULL
  792. DROP PROC [dnt_getnousedattachmentlistbytid]
  793. GO
  794. CREATE PROCEDURE [dnt_getnousedattachmentlistbytid]
  795. @uid INT
  796. AS
  797. SELECT 
  798. [aid], 
  799. [attachment] 
  800. FROM [dnt_attachments] 
  801. WHERE [uid]= @uid AND [tid]=0 AND [pid]=0
  802. GO
  803. IF OBJECT_ID('dnt_updateattachmenttidtoanothertopic','P') IS NOT NULL
  804. DROP PROC [dnt_updateattachmenttidtoanothertopic]
  805. GO
  806. CREATE PROCEDURE [dnt_updateattachmenttidtoanothertopic]
  807. @tid INT,
  808. @oldtid INT
  809. AS
  810. UPDATE [dnt_attachments] SET [tid]=@tid WHERE [tid]=@oldtid
  811. GO
  812. IF OBJECT_ID('dnt_getfirstimageattachbytid','P') IS NOT NULL
  813. DROP PROC [dnt_getfirstimageattachbytid]
  814. GO
  815. CREATE PROCEDURE [dnt_getfirstimageattachbytid]
  816. @tid INT
  817. AS
  818. SELECT TOP 1 
  819. [aid],
  820. [uid],
  821. [tid],
  822. [pid],
  823. [postdatetime],
  824. [readperm],
  825. [filename],
  826. [description],
  827. [filetype],
  828. [filesize],
  829. [attachment],
  830. [downloads],
  831. [attachprice],
  832. [width],
  833. [height] 
  834. FROM [dnt_attachments] 
  835. WHERE [tid]=@tid AND LEFT([filetype], 5)='image' ORDER BY [aid]
  836. GO
  837. IF OBJECT_ID('dnt_getattachmentlistbyaid','P') IS NOT NULL
  838. DROP PROC [dnt_getattachmentlistbyaid]
  839. GO
  840. CREATE PROCEDURE [dnt_getattachmentlistbyaid]
  841. @aidlist varchar(500)
  842. AS
  843. EXEC('SELECT 
  844. [aid],
  845. [tid],
  846. [pid],
  847. [filename]
  848. FROM [dnt_attachments] 
  849. WHERE [aid] IN ('+@aidlist+')')
  850. GO
  851. IF OBJECT_ID('dnt_updateattachment','P') IS NOT NULL
  852. DROP PROC [dnt_updateattachment]
  853. GO
  854. CREATE PROCEDURE [dnt_updateattachment]
  855. @readperm INT,
  856. @description NCHAR(100),
  857. @attachprice INT,
  858. @aid INT
  859. AS
  860. UPDATE [dnt_attachments] 
  861. SET [readperm] = @readperm, [description] = @description, [attachprice] = @attachprice 
  862. WHERE [aid] = @aid
  863. GO
  864. IF OBJECT_ID('dnt_updateattachmentinfo','P') IS NOT NULL
  865. DROP PROC [dnt_updateattachmentinfo]
  866. GO
  867. CREATE PROCEDURE [dnt_updateattachmentinfo]
  868. @readperm INT,
  869. @description NCHAR(100),
  870. @aid INT
  871. AS
  872. UPDATE [dnt_attachments] 
  873. SET [readperm] = @readperm, [description] = @description 
  874. WHERE [aid] = @aid
  875. GO
  876. IF OBJECT_ID('dnt_updateallfieldattachmentinfo','P') IS NOT NULL
  877. DROP PROC [dnt_updateallfieldattachmentinfo]
  878. GO
  879. CREATE PROCEDURE [dnt_updateallfieldattachmentinfo]
  880. @postdatetime DATETIME,
  881. @readperm INT,
  882. @filename NCHAR(100),
  883. @filetype NCHAR(50),
  884. @description NCHAR(100),
  885. @filesize INT,
  886. @attachment NCHAR(100),
  887. @downloads INT,
  888. @tid INT,
  889. @pid INT,
  890. @aid INT,
  891. @attachprice INT,
  892. @width INT,
  893. @height INT
  894. AS
  895. UPDATE [dnt_attachments] 
  896. SET 
  897. [postdatetime] = @postdatetime, 
  898. [readperm] = @readperm, 
  899. [filename] = @filename, 
  900. [description] = @description, 
  901. [filetype] = @filetype, 
  902. [filesize] = @filesize, 
  903. [attachment] = @attachment, 
  904. [downloads] = @downloads, 
  905. [tid]=@tid, 
  906. [pid]=@pid, 
  907. [attachprice]=@attachprice, 
  908. [width]=@width, 
  909. [height]=@height 
  910. WHERE [aid]=@aid
  911. GO
  912. IF OBJECT_ID('dnt_deleteattachmentbypid','P') IS NOT NULL
  913. DROP PROC [dnt_deleteattachmentbypid]
  914. GO
  915. CREATE PROCEDURE [dnt_deleteattachmentbypid]
  916. @pid INT
  917. AS
  918. DELETE FROM [dnt_attachments] 
  919. WHERE [pid]=@pid
  920. GO
  921. IF OBJECT_ID('dnt_deleteattachmentbyaidlist','P') IS NOT NULL
  922. DROP PROC [dnt_deleteattachmentbyaidlist]
  923. GO
  924. CREATE PROCEDURE [dnt_deleteattachmentbyaidlist]
  925. @aidlist VARCHAR(500)
  926. AS
  927. EXEC('DELETE FROM [dnt_attachments] WHERE [aid] IN ('+@aidlist+')')
  928. GO
  929. IF OBJECT_ID('dnt_deleteattachmentbyaid','P') IS NOT NULL
  930. DROP PROC [dnt_deleteattachmentbyaid]
  931. GO
  932. CREATE PROCEDURE [dnt_deleteattachmentbyaid]
  933. @aid INT
  934. AS
  935. DELETE FROM [dnt_attachments] 
  936. WHERE [aid]=@aid
  937. GO
  938. IF OBJECT_ID('dnt_deleteattachmentbytid','P') IS NOT NULL
  939. DROP PROC [dnt_deleteattachmentbytid]
  940. GO
  941. CREATE PROCEDURE [dnt_deleteattachmentbytid]
  942. @tid INT
  943. AS
  944. DELETE FROM [dnt_attachments] WHERE [tid] = @tid
  945. GO
  946. IF OBJECT_ID('dnt_deleteattachmentbytidlist','P') IS NOT NULL
  947. DROP PROC [dnt_deleteattachmentbytidlist]
  948. GO
  949. CREATE PROCEDURE [dnt_deleteattachmentbytidlist]
  950. @tidlist VARCHAR(500)
  951. AS
  952. EXEC('DELETE FROM [dnt_attachments] WHERE [tid] IN ('+@tidlist+')')
  953. GO
  954. IF OBJECT_ID('dnt_getattachmentlistbytidlist','P') IS NOT NULL
  955. DROP PROC [dnt_getattachmentlistbytidlist]
  956. GO
  957. CREATE PROCEDURE [dnt_getattachmentlistbytidlist]
  958. @tidlist VARCHAR(500)
  959. AS
  960. EXEC('SELECT 
  961. [aid],
  962. [filename] 
  963. FROM [dnt_attachments] 
  964. WHERE [tid] IN ('+@tidlist+')')
  965. GO
  966. IF OBJECT_ID('dnt_getattachmentlistbytid','P') IS NOT NULL
  967. DROP PROC [dnt_getattachmentlistbytid]
  968. GO
  969. CREATE PROCEDURE [dnt_getattachmentlistbytid]
  970. @tid INT
  971. AS
  972. SELECT 
  973. [aid],
  974. [filename] 
  975. FROM [dnt_attachments] 
  976. WHERE [tid] = @tid
  977. GO
  978. IF OBJECT_ID('dnt_updateattachmentdownloads','P') IS NOT NULL
  979. DROP PROC [dnt_updateattachmentdownloads]
  980. GO
  981. CREATE PROCEDURE [dnt_updateattachmentdownloads]
  982. @aid INT
  983. AS
  984. UPDATE [dnt_attachments] SET [downloads]=[downloads]+1 WHERE [aid]=@aid;
  985. UPDATE  [dnt_myattachments]
  986. SET    [downloads] = (SELECT [downloads] FROM [dnt_attachments] WHERE [dnt_attachments].aid = @aid)
  987. WHERE  [aid]=@aid
  988. GO
  989. IF OBJECT_ID('dnt_getattachenmtlistbypid','P') IS NOT NULL
  990. DROP PROC [dnt_getattachenmtlistbypid]
  991. GO
  992. CREATE PROCEDURE [dnt_getattachenmtlistbypid]
  993. @pid INT
  994. AS
  995. SELECT 
  996. [aid],
  997. [uid],
  998. [tid],
  999. [pid],
  1000. [postdatetime],
  1001. [readperm],
  1002. [filename],
  1003. [description],
  1004. [filetype],
  1005. [filesize],
  1006. [attachment],
  1007. [downloads],
  1008. [attachprice],
  1009. [width],
  1010. [height] 
  1011. FROM [dnt_attachments] 
  1012. WHERE [pid]=@pid
  1013. GO
  1014. IF OBJECT_ID('dnt_getattachmentcountbytid','P') IS NOT NULL
  1015. DROP PROC [dnt_getattachmentcountbytid]
  1016. GO
  1017. CREATE PROCEDURE [dnt_getattachmentcountbytid]
  1018. @tid INT
  1019. AS
  1020. SELECT COUNT([aid]) AS [acount] FROM [dnt_attachments] WHERE [tid]=@tid
  1021. GO
  1022. IF OBJECT_ID('dnt_getattachmentcountbypid','P') IS NOT NULL
  1023. DROP PROC [dnt_getattachmentcountbypid]
  1024. GO
  1025. CREATE PROCEDURE [dnt_getattachmentcountbypid]
  1026. @pid INT
  1027. AS
  1028. SELECT COUNT([aid]) AS [acount] FROM [dnt_attachments] WHERE [pid]=@pid
  1029. GO
  1030. IF OBJECT_ID('dnt_getattachenmtinfobyaid','P') IS NOT NULL
  1031. DROP PROC [dnt_getattachenmtinfobyaid]
  1032. GO
  1033. CREATE PROCEDURE [dnt_getattachenmtinfobyaid]
  1034. @aid INT
  1035. AS
  1036. SELECT TOP 1
  1037. [aid],
  1038. [uid],
  1039. [tid],
  1040. [pid],
  1041. [postdatetime],
  1042. [readperm],
  1043. [filename],
  1044. [description],
  1045. [filetype],
  1046. [filesize],
  1047. [attachment],
  1048. [downloads],
  1049. [attachprice],
  1050. [width],
  1051. [height] 
  1052. FROM [dnt_attachments] 
  1053. WHERE [aid]=@aid
  1054. GO
  1055. IF OBJECT_ID('dnt_getpolllist','P') IS NOT NULL
  1056. DROP PROC [dnt_getpolllist]
  1057. GO
  1058. CREATE PROCEDURE [dnt_getpolllist]
  1059. @tid int
  1060. AS
  1061. SELECT 
  1062. [pollid],
  1063. [tid],
  1064. [displayorder],
  1065. [multiple],
  1066. [visible],
  1067. [maxchoices],
  1068. [expiration],
  1069. [uid],
  1070. [voternames] 
  1071. FROM [dnt_polls] 
  1072. WHERE [tid]=@tid
  1073. GO
  1074. IF OBJECT_ID('dnt_gettaginfo','P') IS NOT NULL
  1075. DROP PROC [dnt_gettaginfo]
  1076. GO
  1077. CREATE PROCEDURE [dnt_gettaginfo]
  1078. @tagid int
  1079. AS
  1080. SELECT 
  1081. [tagid],
  1082. [tagname],
  1083. [userid],
  1084. [postdatetime],
  1085. [orderid],
  1086. [color],
  1087. [count],
  1088. [fcount],
  1089. [pcount],
  1090. [scount],
  1091. [vcount],
  1092. [gcount] 
  1093. FROM [dnt_tags] 
  1094. WHERE [tagid]=@tagid
  1095. GO
  1096. IF OBJECT_ID('dnt_setcurrenttopics','P') IS NOT NULL
  1097. DROP PROC [dnt_setcurrenttopics]
  1098. GO
  1099. CREATE PROCEDURE [dnt_setcurrenttopics]
  1100. @fid int
  1101. AS
  1102. UPDATE 
  1103. [dnt_forums] 
  1104. SET [curtopics] = (SELECT COUNT(tid) FROM [dnt_topics] WHERE [displayorder] >= 0 AND [fid]=@fid) WHERE [fid]=@fid
  1105. GO
  1106. --2009-10-30 后台优化----------------------------------------------
  1107. IF OBJECT_ID('dnt_getmaxandmintid','P') IS NOT NULL
  1108. DROP PROC [dnt_getmaxandmintid]
  1109. GO
  1110. CREATE PROC [dnt_getmaxandmintid]
  1111. @fid INT
  1112. AS
  1113. SELECT 
  1114. MAX([tid]) AS [maxtid],
  1115. MIN([tid]) AS [mintid] 
  1116. FROM [dnt_topics] 
  1117. WHERE 
  1118. [fid] IN (SELECT [fid] 
  1119.   FROM [dnt_forums] 
  1120.   WHERE [fid]=@fid 
  1121.   OR (CHARINDEX(',' + RTRIM(@fid) + ',', ',' + RTRIM(parentidlist) + ',') > 0))
  1122. GO
  1123. IF OBJECT_ID('dnt_getdesignatepostcount','P') IS NOT NULL
  1124. DROP PROC [dnt_getdesignatepostcount]
  1125. GO
  1126. CREATE PROC [dnt_getdesignatepostcount]
  1127. @fid INT,
  1128. @posttablename VARCHAR(50)
  1129. AS
  1130. EXEC ('SELECT COUNT([pid]) AS [postcount] FROM [' + @posttablename + '] WHERE [fid] = ' + @fid)
  1131. GO
  1132. IF OBJECT_ID('dnt_getpostcountbyuid','P') IS NOT NULL
  1133. DROP PROC [dnt_getpostcountbyuid]
  1134. GO
  1135. CREATE PROC [dnt_getpostcountbyuid]
  1136. @uid INT,
  1137. @posttablename VARCHAR(50)
  1138. AS
  1139. EXEC ('SELECT COUNT([pid]) AS [postcount] FROM [' + @posttablename + '] WHERE [posterid] = ' + @uid)
  1140. GO
  1141. IF OBJECT_ID('dnt_gettodaypostcountbyuid','P') IS NOT NULL
  1142. DROP PROC [dnt_gettodaypostcountbyuid]
  1143. GO
  1144. CREATE PROC [dnt_gettodaypostcountbyuid]
  1145. @uid INT,
  1146. @posttablename VARCHAR(50)
  1147. AS
  1148. EXEC ('SELECT COUNT([pid]) AS [postcount] 
  1149. FROM [' + @posttablename + '] 
  1150. WHERE [posterid] = ' + @uid + ' AND DATEDIFF(day, [postdatetime], GETDATE()) = 0')
  1151. GO
  1152. IF OBJECT_ID('dnt_gettotaltopiccount','P') IS NOT NULL
  1153. DROP PROC [dnt_gettotaltopiccount]
  1154. GO
  1155. CREATE PROC [dnt_gettotaltopiccount]
  1156. AS
  1157. SELECT COUNT([tid]) AS [topicscount] FROM [dnt_topics]
  1158. GO
  1159. IF OBJECT_ID('dnt_resetstatistic','P') IS NOT NULL
  1160. DROP PROC [dnt_resetstatistic]
  1161. GO
  1162. CREATE PROC [dnt_resetstatistic]
  1163. @totaltopic INT,
  1164. @totalpost INT,
  1165. @totalusers INT,
  1166. @lastusername VARCHAR(20),
  1167. @lastuserid INT
  1168. AS
  1169. UPDATE [dnt_statistics] 
  1170. SET 
  1171. [totaltopic]=@totaltopic,[totalpost]=@totalpost,[totalusers]=@totalusers,[lastusername]=@lastusername,[lastuserid]=@lastuserid
  1172. GO
  1173. IF OBJECT_ID('dnt_gettopusers','P') IS NOT NULL
  1174. DROP PROC [dnt_gettopusers]
  1175. GO
  1176. CREATE PROC [dnt_gettopusers]
  1177. @statcont INT,
  1178. @lastuid INT
  1179. AS
  1180. SELECT TOP (@statcont) [uid] FROM [dnt_users] WHERE [uid] > @lastuid
  1181. GO
  1182. IF OBJECT_ID('dnt_resetuserdigestposts','P') IS NOT NULL
  1183. DROP PROC [dnt_resetuserdigestposts]
  1184. GO
  1185. CREATE PROC [dnt_resetuserdigestposts]
  1186. @userid INT
  1187. AS
  1188. UPDATE [dnt_users] 
  1189. SET [digestposts]=(SELECT COUNT(tid) AS [digestposts] FROM [dnt_topics] WHERE [dnt_topics].[posterid] = [dnt_users].[uid] AND [digest] > 0) WHERE [dnt_users].[uid] = @userid
  1190. GO
  1191. IF OBJECT_ID('dnt_getusers','P') IS NOT NULL
  1192. DROP PROC [dnt_getusers]
  1193. GO
  1194. CREATE PROC [dnt_getusers]
  1195. @start_uid INT,
  1196. @end_uid INT
  1197. AS
  1198. SELECT [uid] FROM [dnt_users] WHERE [uid] >= @start_uid AND [uid]<=@end_uid
  1199. GO
  1200. IF OBJECT_ID('dnt_updateuserpostcount','P') IS NOT NULL
  1201. DROP PROC [dnt_updateuserpostcount]
  1202. GO
  1203. CREATE PROC [dnt_updateuserpostcount]
  1204. @postcount INT,
  1205. @userid INT
  1206. AS
  1207. UPDATE [dnt_users] SET [posts]=@postcount WHERE [dnt_users].[uid] = @userid
  1208. GO
  1209. IF OBJECT_ID('dnt_getonlineregistercount','P') IS NOT NULL
  1210. DROP PROC [dnt_getonlineregistercount]
  1211. GO
  1212. CREATE PROC [dnt_getonlineregistercount]
  1213. AS
  1214. SELECT COUNT(olid) FROM [dnt_online] WHERE [userid]>0
  1215. GO
  1216. IF OBJECT_ID('dnt_gettopictids','P') IS NOT NULL
  1217. DROP PROC [dnt_gettopictids]
  1218. GO
  1219. CREATE PROC [dnt_gettopictids]
  1220. @statcount INT,
  1221. @lasttid INT
  1222. AS
  1223. SELECT TOP(@statcount) [tid] FROM [dnt_topics] WHERE [tid] > @lasttid ORDER BY [tid]
  1224. GO
  1225. IF OBJECT_ID('dnt_updatelastpostoftopic','P') IS NOT NULL
  1226. DROP PROC [dnt_updatelastpostoftopic]
  1227. GO
  1228. CREATE PROC [dnt_updatelastpostoftopic]
  1229. @tid INT,
  1230. @postcount INT,
  1231. @lastpostid INT,
  1232. @lastpost VARCHAR(20),
  1233. @lastposterid INT,
  1234. @lastposter VARCHAR(20)
  1235. AS
  1236. UPDATE [dnt_topics] 
  1237. SET [lastpost]=@lastpost, [lastposterid]=@lastposterid, [lastposter]=@lastposter, [replies]=@postcount, [lastpostid]=@lastpostid 
  1238. WHERE [tid] = @tid
  1239. GO
  1240. IF OBJECT_ID('dnt_updatetopiclastposterid','P') IS NOT NULL
  1241. DROP PROC [dnt_updatetopiclastposterid]
  1242. GO
  1243. CREATE PROC [dnt_updatetopiclastposterid]
  1244. @tid INT
  1245. AS
  1246. UPDATE [dnt_topics] 
  1247. SET [lastposterid]=(SELECT ISNULL(MIN(lastpostid), -1)-1 FROM [dnt_topics] WHERE [tid] = @tid)
  1248. GO
  1249. IF OBJECT_ID('dnt_gettopics','P') IS NOT NULL
  1250. DROP PROC [dnt_gettopics]
  1251. GO
  1252. CREATE PROC [dnt_gettopics]
  1253. @start_tid INT,
  1254. @end_tid INT
  1255. AS
  1256. SELECT [tid] 
  1257. FROM [dnt_topics] 
  1258. WHERE [tid] >= @start_tid AND [tid]<=@end_tid 
  1259. ORDER BY [tid]
  1260. GO
  1261. IF OBJECT_ID('dnt_gettopforumfids','P') IS NOT NULL
  1262. DROP PROC [dnt_gettopforumfids]
  1263. GO
  1264. CREATE PROC [dnt_gettopforumfids]
  1265. @lastfid INT,
  1266. @statcount INT
  1267. AS
  1268. SELECT TOP(@statcount) [fid] FROM [dnt_forums] WHERE [fid] > @lastfid
  1269. GO
  1270. IF OBJECT_ID('dnt_getlastpostbyfid','P') IS NOT NULL
  1271. DROP PROC [dnt_getlastpostbyfid]
  1272. GO
  1273. CREATE PROC [dnt_getlastpostbyfid]
  1274. @fid INT,
  1275. @posttablename VARCHAR(50)
  1276. AS
  1277. EXEC ('SELECT TOP 1 [tid], [title], [postdatetime], [posterid], [poster], [pid] 
  1278. FROM [' + @posttablename + '] 
  1279. WHERE [fid] = ' + @fid +
  1280. 'ORDER BY [pid] DESC')
  1281. GO
  1282. IF OBJECT_ID('dnt_updateforum','P') IS NOT NULL
  1283. DROP PROC [dnt_updateforum]
  1284. GO
  1285. CREATE PROC [dnt_updateforum]
  1286. @lastfid INT,
  1287. @topiccount INT,
  1288. @postcount INT,
  1289. @lasttid INT,
  1290. @lasttitle NCHAR(80),
  1291. @lastpost VARCHAR(20),
  1292. @lastposterid INT,
  1293. @lastposter NCHAR(20),
  1294. @todaypostcount INT 
  1295. AS
  1296. UPDATE [dnt_forums] 
  1297. SET [topics] = @topiccount, [posts]=@postcount, [todayposts] = @todaypostcount, [lasttid] = @lasttid, [lasttitle] = @lasttitle, [lastpost]=@lastpost, [lastposterid] = @lastposterid, [lastposter]=@lastposter 
  1298. WHERE [dnt_forums].[fid] = @lastfid
  1299. GO
  1300. IF OBJECT_ID('dnt_resetclearmove','P') IS NOT NULL
  1301. DROP PROC [dnt_resetclearmove]
  1302. GO
  1303. CREATE PROC [dnt_resetclearmove]
  1304. AS
  1305. DELETE FROM [dnt_topics] WHERE [closed] > 1
  1306. GO
  1307. IF OBJECT_ID('dnt_updatemytopic','P') IS NOT NULL
  1308. DROP PROC [dnt_updatemytopic]
  1309. GO
  1310. CREATE PROC [dnt_updatemytopic]
  1311. AS
  1312. DELETE FROM [dnt_mytopics]
  1313. INSERT INTO [dnt_mytopics]([uid], [tid], [dateline]) 
  1314. SELECT [posterid],[tid],[postdatetime] 
  1315. FROM [dnt_topics] 
  1316. WHERE [posterid]<>-1
  1317. GO
  1318. IF OBJECT_ID('dnt_updatemypost','P') IS NOT NULL
  1319. DROP PROC [dnt_updatemypost]
  1320. GO
  1321. CREATE PROC [dnt_updatemypost]
  1322. @tablename VARCHAR(50)
  1323. AS
  1324. DELETE FROM [dnt_myposts]
  1325. EXEC ('
  1326. INSERT INTO [dnt_myposts]([uid], [tid], [pid], [dateline])
  1327. SELECT [posterid],[tid],[pid],[postdatetime] FROM [' + @tablename + '] WHERE [posterid]<>-1
  1328. ')
  1329. GO
  1330. IF OBJECT_ID('dnt_updateforumsinfo','P') IS NOT NULL
  1331. DROP PROC [dnt_updateforumsinfo]
  1332. GO
  1333. CREATE PROC [dnt_updateforumsinfo]
  1334. @parentid SmallInt,
  1335. @layer Int,
  1336. @pathlist NChar(3000),
  1337. @parentidlist NChar(300),
  1338. @subforumcount Int,
  1339. @name NChar(50),
  1340. @status Int,
  1341. @colcount SmallInt,
  1342. @displayorder Int,
  1343. @templateid SmallInt,
  1344. @topics Int,
  1345. @curtopics Int,
  1346. @posts Int,
  1347. @todayposts Int,
  1348. @lasttid Int,
  1349. @lasttitle NChar(60),
  1350. @lastpost DateTime,
  1351. @lastposterid Int,
  1352. @lastposter NChar(20),
  1353. @allowsmilies Int,
  1354. @allowrss Int,
  1355. @allowhtml Int,
  1356. @allowbbcode Int,
  1357. @allowimgcode Int,
  1358. @allowblog Int,
  1359. @istrade Int,
  1360. @allowpostspecial Int,
  1361. @allowspecialonly Int,
  1362. @alloweditrules Int,
  1363. @allowthumbnail Int,
  1364. @allowtag Int,
  1365. @recyclebin Int,
  1366. @modnewposts Int,
  1367. @jammer Int,
  1368. @disablewatermark Int,
  1369. @inheritedmod Int,
  1370. @autoclose SmallInt,
  1371. @password NVarChar(16),
  1372. @icon VarChar(255),
  1373. @postcredits VarChar(255),
  1374. @replycredits VarChar(255),
  1375. @redirect VarChar(255),
  1376. @attachextensions VarChar(255),
  1377. @rules NText,
  1378. @topictypes Text,
  1379. @viewperm Text,
  1380. @postperm Text,
  1381. @replyperm Text,
  1382. @getattachperm Text,
  1383. @postattachperm Text,
  1384. @moderators Text,
  1385. @description NText,
  1386. @applytopictype TinyInt,
  1387. @postbytopictype TinyInt,
  1388. @viewbytopictype TinyInt,
  1389. @topictypeprefix TinyInt,
  1390. @permuserlist NText,
  1391. @seokeywords NVarChar(500),
  1392. @seodescription NVarChar(500),
  1393. @rewritename NVarChar(20),
  1394. @fid Int
  1395. AS
  1396. UPDATE [dnt_forums] 
  1397. SET [parentid]=@parentid, [layer]=@layer, [pathlist]=@pathlist, 
  1398. [parentidlist]=@parentidlist, [subforumcount]=@subforumcount, [name]=@name, [status]=@status,
  1399. [colcount]=@colcount, [displayorder]=@displayorder,[templateid]=@templateid,[topics]=@topics,
  1400. [curtopics]=@curtopics,[posts]=@posts,[todayposts]=@todayposts,[lasttid]=@lasttid,[lasttitle]=@lasttitle,
  1401. [lastpost]=@lastpost,[lastposterid]=@lastposterid,[lastposter]=@lastposter,
  1402. [allowsmilies]=@allowsmilies ,[allowrss]=@allowrss, [allowhtml]=@allowhtml, [allowbbcode]=@allowbbcode, [allowimgcode]=@allowimgcode, 
  1403. [allowblog]=@allowblog,[istrade]=@istrade,[allowpostspecial]=@allowpostspecial,[allowspecialonly]=@allowspecialonly,
  1404. [alloweditrules]=@alloweditrules ,[allowthumbnail]=@allowthumbnail ,[allowtag]=@allowtag,
  1405. [recyclebin]=@recyclebin, [modnewposts]=@modnewposts,[jammer]=@jammer,[disablewatermark]=@disablewatermark,[inheritedmod]=@inheritedmod,
  1406. [autoclose]=@autoclose 
  1407. WHERE [fid]=@fid
  1408. UPDATE [dnt_forumfields] 
  1409. SET [password]=@password,[icon]=@icon,[postcredits]=@postcredits,
  1410.  [replycredits]=@replycredits,[redirect]=@redirect,[attachextensions]=@attachextensions,[rules]=@rules,[topictypes]=@topictypes,
  1411.  [viewperm]=@viewperm,[postperm]=@postperm,[replyperm]=@replyperm,[getattachperm]=@getattachperm,[postattachperm]=@postattachperm,
  1412.  [moderators]=@moderators,[description]=@description,[applytopictype]=@applytopictype,[postbytopictype]=@postbytopictype,
  1413.  [viewbytopictype]=@viewbytopictype,[topictypeprefix]=@topictypeprefix,[permuserlist]=@permuserlist,[seokeywords]=@seokeywords,
  1414.  [seodescription]=@seodescription,[rewritename]=@rewritename 
  1415.  WHERE [fid]=@fid
  1416. GO
  1417. IF OBJECT_ID('dnt_insertforumsinfo','P') IS NOT NULL
  1418. DROP PROC [dnt_insertforumsinfo]
  1419. GO
  1420. CREATE PROC [dnt_insertforumsinfo]
  1421. @parentid SmallInt,
  1422. @layer Int,
  1423. @pathlist NChar(3000),
  1424. @parentidlist NChar(300),
  1425. @subforumcount Int,
  1426. @name NChar(50),
  1427. @status Int,
  1428. @colcount SmallInt,
  1429. @displayorder Int,
  1430. @templateid SmallInt,
  1431. @allowsmilies Int,
  1432. @allowrss Int,
  1433. @allowhtml Int,
  1434. @allowbbcode Int,
  1435. @allowimgcode Int,
  1436. @allowblog Int,
  1437. @istrade Int,
  1438. @alloweditrules Int,
  1439. @allowthumbnail Int,
  1440. @allowtag Int,
  1441. @recyclebin Int,
  1442. @modnewposts Int,
  1443. @jammer Int,
  1444. @disablewatermark Int,
  1445. @inheritedmod Int,
  1446. @autoclose SmallInt,
  1447. @allowpostspecial Int,
  1448. @allowspecialonly Int,
  1449. @description NText,
  1450. @password VarChar(16),
  1451. @icon VarChar(255),
  1452. @postcredits VarChar(255),
  1453. @replycredits VarChar(255),
  1454. @redirect VarChar(255),
  1455. @attachextensions VarChar(255),
  1456. @moderators Text,
  1457. @rules NText,
  1458. @topictypes Text,
  1459. @viewperm Text,
  1460. @postperm Text,
  1461. @replyperm Text,
  1462. @getattachperm Text,
  1463. @postattachperm Text,
  1464. @seokeywords NVarChar(500),
  1465. @seodescription NVarChar(500),
  1466. @rewritename NVarChar(20)
  1467. AS
  1468. DECLARE @fid INT
  1469. INSERT INTO [dnt_forums] ([parentid],[layer],[pathlist],[parentidlist],[subforumcount],[name],
  1470. [status],[colcount],[displayorder],[templateid],[allowsmilies],[allowrss],[allowhtml],[allowbbcode],[allowimgcode],[allowblog],
  1471. [istrade],[alloweditrules],[recyclebin],[modnewposts],[jammer],[disablewatermark],[inheritedmod],[autoclose],[allowthumbnail],
  1472. [allowtag],[allowpostspecial],[allowspecialonly]) 
  1473. VALUES (@parentid,@layer,@pathlist,@parentidlist,@subforumcount,@name,@status, @colcount, @displayorder,
  1474. @templateid,@allowsmilies,@allowrss,@allowhtml,@allowbbcode,@allowimgcode,@allowblog,@istrade,@alloweditrules,@recyclebin,
  1475. @modnewposts,@jammer,@disablewatermark,@inheritedmod,@autoclose,@allowthumbnail,@allowtag,@allowpostspecial,@allowspecialonly)
  1476. --SET @fid=@@IDENTITY
  1477. SELECT @fid = ISNULL(MAX(fid), 0) FROM [dnt_forums]
  1478. INSERT INTO [dnt_forumfields] ([fid],[description],[password],[icon],[postcredits],[replycredits],[redirect],
  1479. [attachextensions],[moderators],[rules],[topictypes],[viewperm],[postperm],[replyperm],[getattachperm],[postattachperm],[seokeywords],[seodescription],[rewritename]) 
  1480. VALUES (@fid,@description,@password,@icon,@postcredits,@replycredits,@redirect,@attachextensions,@moderators,@rules,@topictypes,@viewperm,
  1481. @postperm,@replyperm,@getattachperm,@postattachperm,@seokeywords,@seodescription,@rewritename) 
  1482. GO
  1483. IF OBJECT_ID('dnt_getsubforumcount','P') IS NOT NULL
  1484. DROP PROC [dnt_getsubforumcount]
  1485. GO
  1486. CREATE PROC [dnt_getsubforumcount]
  1487. @fid INT
  1488. AS
  1489. SELECT COUNT(fid) FROM [dnt_forums] WHERE [parentid]=@fid
  1490. GO
  1491. IF OBJECT_ID('dnt_deleteforumsbyfid','P') IS NOT NULL
  1492. DROP PROC [dnt_deleteforumsbyfid]
  1493. GO
  1494. CREATE PROC [dnt_deleteforumsbyfid]
  1495. @fid INT,
  1496. @postname NVARCHAR(50)
  1497. AS
  1498. DECLARE @parentid INT,
  1499. @displayorder INT
  1500. SELECT TOP 1 @parentid=[parentid],@displayorder=[displayorder] FROM [dnt_forums] WHERE [fid]=@fid
  1501. UPDATE [dnt_forums] SET [displayorder]=[displayorder]-1 WHERE [displayorder]>@displayorder
  1502. UPDATE [dnt_forums] SET [subforumcount]=[subforumcount]-1 WHERE  [fid]=@parentid
  1503. DELETE FROM [dnt_forumfields] WHERE [fid]=@fid
  1504. DELETE FROM [dnt_polls] WHERE [tid] IN (SELECT [tid] FROM [dnt_topics] WHERE [fid]=@fid)
  1505. EXEC ('DELETE FROM [dnt_attachments] WHERE [tid] IN(SELECT [tid] FROM [dnt_topics] WHERE [fid]=' + @fid + ') OR [pid] IN(SELECT [pid] FROM [' + @postname + '] WHERE [fid]=' + @fid + ')')
  1506. EXEC ('DELETE FROM [' + @postname + '] WHERE [fid]=' + @fid)
  1507. DELETE FROM [dnt_topics] WHERE [fid]=@fid
  1508. DELETE FROM [dnt_forums] WHERE  [fid]=@fid
  1509. DELETE FROM [dnt_moderators] WHERE  [fid]=@fid
  1510. GO
  1511. IF OBJECT_ID('dnt_getparentidbyfid','P') IS NOT NULL
  1512. DROP PROC [dnt_getparentidbyfid]
  1513. GO
  1514. CREATE PROC [dnt_getparentidbyfid]
  1515. @fid INT
  1516. AS
  1517. SELECT [parentid] From [dnt_forums] WHERE [inheritedmod]=1 AND [fid]=@fid
  1518. GO
  1519. IF OBJECT_ID('dnt_updateforumsmoderators','P') IS NOT NULL
  1520. DROP PROC [dnt_updateforumsmoderators]
  1521. GO
  1522. CREATE PROC [dnt_updateforumsmoderators]
  1523. @displayorder INT,
  1524. @moderators VARCHAR(500),
  1525. @fid INT,
  1526. @inherited INT
  1527. AS
  1528. DECLARE @usernamelist VARCHAR(255),
  1529. @username VARCHAR(255),
  1530. @uid INT,
  1531. @len INT,
  1532. @b BIT,
  1533. @begin INT,
  1534. @end INT
  1535. SELECT @len=0,@begin=1,@end=1,@b=1,@usernamelist=''
  1536. WHILE @b=1
  1537. BEGIN
  1538. IF @end=1
  1539. SET @begin=@end
  1540. ELSE
  1541. SET @begin=@end+1
  1542. SET @end = CHARINDEX(',',@moderators,@begin)
  1543. IF @end=0
  1544. SET @end=LEN(@moderators)+1
  1545. SET @len=@end-@begin
  1546. IF @len>0
  1547. BEGIN
  1548. SET @username=SUBSTRING(@moderators,@begin,@len)
  1549. IF @username<>''
  1550. BEGIN
  1551. SELECT @uid=[uid] FROM [dnt_users] WHERE [groupid]<>7 AND [groupid]<>8 AND [username]=@username
  1552. IF @uid IS NOT NULL
  1553. BEGIN
  1554. INSERT INTO [dnt_moderators] ([uid],[fid],[displayorder],[inherited]) VALUES (@uid,@fid,@displayorder,@inherited)
  1555. SET @usernamelist=@usernamelist+@username+','
  1556. SET @displayorder=@displayorder+1
  1557. SET @uid=NULL
  1558. END
  1559. END
  1560. END
  1561. ELSE
  1562. SET @b=0
  1563. END
  1564. IF RIGHT(@usernamelist,1)=','
  1565. SET @usernamelist=LEFT(@usernamelist,LEN(@usernamelist)-1)
  1566. UPDATE [dnt_forumfields] SET [moderators]=@usernamelist WHERE [fid] =@fid
  1567. GO
  1568. IF OBJECT_ID('dnt_getforumstable','P') IS NOT NULL
  1569. DROP PROC [dnt_getforumstable]
  1570. GO
  1571. CREATE PROC [dnt_getforumstable]
  1572. AS
  1573. SELECT
  1574. [f].[fid],[f].[parentid],[f].[layer],[f].[pathlist],[f].[parentidlist],[f].[subforumcount],[f].[name],[f].[status],[f].[colcount],[f].[displayorder],[f].[templateid],[f].[topics],[f].[curtopics],[f].[posts],[f].[todayposts],[f].[lasttid],[f].[lasttitle],[f].[lastpost],[f].[lastposterid],[f].[lastposter],[f].[allowsmilies],[f].[allowrss],[f].[allowhtml],[f].[allowbbcode],[f].[allowimgcode],[f].[allowblog],[f].[istrade],[f].[allowpostspecial],[f].[allowspecialonly],[f].[alloweditrules],[f].[allowthumbnail],[f].[allowtag],[f].[recyclebin],[f].[modnewposts],[f].[jammer],[f].[disablewatermark],[f].[inheritedmod],[f].[autoclose],[ff].[password],[ff].[icon],[ff].[postcredits],[ff].[replycredits],[ff].[redirect],[ff].[attachextensions],[ff].[rules],[ff].[topictypes],[ff].[viewperm],[ff].[postperm],[ff].[replyperm],[ff].[getattachperm],[ff].[postattachperm],[ff].[moderators],[ff].[description],[ff].[applytopictype],[ff].[postbytopictype],[ff].[viewbytopictype],[ff].[topictypeprefix],[ff].[permuserlist],[ff].[seokeywords],[ff].[seodescription],[ff].[rewritename] 
  1575. FROM [dnt_forums] AS [f] 
  1576. LEFT JOIN [dnt_forumfields] AS [ff] 
  1577. ON [f].[fid]=[ff].[fid] 
  1578. ORDER BY [f].[displayorder]
  1579. GO
  1580. IF OBJECT_ID('dnt_getmainforum','P') IS NOT NULL
  1581. DROP PROC [dnt_getmainforum]
  1582. GO
  1583. CREATE PROC [dnt_getmainforum]
  1584. AS
  1585. SELECT
  1586. [fid],[parentid],[layer],[pathlist],[parentidlist],[subforumcount],[name],[status],[colcount],[displayorder],[templateid],[topics],[curtopics],[posts],[todayposts],[lasttid],[lasttitle],[lastpost],[lastposterid],[lastposter],[allowsmilies],[allowrss],[allowhtml],[allowbbcode],[allowimgcode],[allowblog],[istrade],[allowpostspecial],[allowspecialonly],[alloweditrules],[allowthumbnail],[allowtag],[recyclebin],[modnewposts],[jammer],[disablewatermark],[inheritedmod],[autoclose] 
  1587. FROM [dnt_forums] 
  1588. WHERE [layer]=0 
  1589. Order By [displayorder] ASC
  1590. GO
  1591. IF OBJECT_ID('dnt_getlastposttid','P') IS NOT NULL
  1592. DROP PROC [dnt_getlastposttid]
  1593. GO
  1594. CREATE PROC [dnt_getlastposttid]
  1595. @visibleforums VARCHAR(4000),
  1596. @fid INT
  1597. AS
  1598. IF @visibleforums=''
  1599. SELECT TOP 1 [tid] FROM [dnt_topics] AS t LEFT JOIN [dnt_forums] AS f  ON [t].[fid] = [f].[fid] 
  1600. WHERE [t].[closed]<>1 AND  [t].[displayorder] >=0  AND ([t].[fid] = @fid 
  1601. OR CHARINDEX(',' + CONVERT(NVARCHAR(10), @fid) + ',' , ',' + RTRIM([f].[parentidlist]) + ',') > 0 )  
  1602. ORDER BY [t].[lastpost] DESC
  1603. ELSE
  1604. EXEC('SELECT TOP 1 [tid] FROM [dnt_topics] AS t LEFT JOIN [dnt_forums] AS f  ON [t].[fid] = [f].[fid] 
  1605. WHERE [t].[closed]<>1 AND  [t].[displayorder] >=0  AND ([t].[fid] = ' + @fid +
  1606. 'OR CHARINDEX('','' + CONVERT(NVARCHAR(10), ' + @fid + ') + '','' , '','' + RTRIM([f].[parentidlist]) + '','') > 0 )  
  1607. AND [t].[fid] IN ('+@visibleforums+')  ORDER BY [t].[lastpost] DESC')
  1608. GO
  1609. IF OBJECT_ID('dnt_deluserallinf','P') IS NOT NULL
  1610. DROP PROC [dnt_deluserallinf]
  1611. GO
  1612. CREATE PROC [dnt_deluserallinf]
  1613. @uid INT,
  1614. @delPosts BIT,
  1615. @delPms BIT
  1616. AS
  1617. DECLARE @existuid INT
  1618. SELECT @existuid = COUNT([uid]) FROM [dnt_users] WHERE [uid]=@uid
  1619. IF @existuid <>0
  1620. BEGIN
  1621. DELETE FROM [dnt_users] WHERE [uid]=@uid                 
  1622. DELETE FROM [dnt_userfields] WHERE [uid]=@uid                 
  1623. DELETE FROM [dnt_onlinetime] WHERE [uid]=@uid                
  1624. DELETE FROM [dnt_polls] WHERE [uid]=@uid                 
  1625. DELETE FROM [dnt_favorites] WHERE [uid]=@uid
  1626. DECLARE @tableid INT,
  1627. @tablename NVARCHAR(20)
  1628. IF @delPosts = 1
  1629. BEGIN
  1630. DELETE FROM [dnt_topics] WHERE [posterid]=@uid
  1631. DECLARE tables_cursor CURSOR FOR SELECT [id] FROM [dnt_tablelist]
  1632. OPEN tables_cursor
  1633. FETCH NEXT FROM tables_cursor INTO @tableid
  1634. WHILE @@FETCH_STATUS = 0
  1635. BEGIN
  1636. SET @tablename = 'dnt_posts' + LTRIM(STR(@tableid))
  1637. EXEC ('DELETE FROM ' + @tablename + ' WHERE [posterid]='+@uid)
  1638. FETCH NEXT FROM tables_cursor INTO @tableid
  1639. END
  1640. CLOSE tables_cursor
  1641. DEALLOCATE tables_cursor
  1642. SET @tableid = 0
  1643. SET @tablename = ''
  1644. END
  1645. ELSE
  1646. BEGIN
  1647. UPDATE [dnt_topics] SET [poster]='该用户已被删除' Where [posterid]=@uid
  1648. UPDATE [dnt_topics] SET [lastposter]='该用户已被删除' Where [lastpostid]=@uid
  1649. DECLARE tables_cursor CURSOR FOR SELECT [id] FROM [dnt_tablelist]
  1650. OPEN tables_cursor
  1651. FETCH NEXT FROM tables_cursor INTO @tableid
  1652. WHILE @@FETCH_STATUS = 0
  1653. BEGIN
  1654. SET @tablename = 'dnt_posts' + LTRIM(STR(@tableid))
  1655. EXEC ('UPDATE ['+@tablename+'] SET [poster]=''该用户已被删除'' WHERE [posterid]='+@uid)
  1656. FETCH NEXT FROM tables_cursor INTO @tableid
  1657. END
  1658. CLOSE tables_cursor
  1659. DEALLOCATE tables_cursor
  1660. SET @tableid = 0
  1661. SET @tablename = ''
  1662. END
  1663. IF @delPms = 1
  1664. BEGIN
  1665. DELETE FROM [dnt_pms] WHERE [msgfromid]=@uid
  1666. END
  1667. ELSE
  1668. BEGIN
  1669. UPDATE [dnt_pms] SET [msgfrom]='该用户已被删除' WHERE [msgfromid]=@uid
  1670. UPDATE [dnt_pms] SET [msgto]='该用户已被删除' WHERE [msgtoid]=@uid
  1671. END
  1672. DELETE FROM [dnt_moderators] WHERE [uid]=@uid
  1673. UPDATE [dnt_statistics] SET [totalusers]=[totalusers]-1
  1674. DECLARE @lastuserid INT,@lastusername VARCHAR(50)
  1675. SELECT TOP 1 @lastuserid=[uid],@lastusername=[username] FROM [dnt_users] ORDER BY [uid] DESC
  1676. IF @lastuserid IS NOT NULL
  1677. UPDATE [dnt_Statistics] SET [lastuserid]=@lastuserid, [lastusername]=@lastusername
  1678. END
  1679. GO
  1680. IF OBJECT_ID('dnt_addusergroup','P') IS NOT NULL
  1681. DROP PROC [dnt_addusergroup]
  1682. GO
  1683. CREATE PROC [dnt_addusergroup]
  1684. @Radminid INT,
  1685. @Grouptitle NVARCHAR(50),
  1686. @Creditshigher INT,
  1687. @Creditslower INT,
  1688. @Stars INT,
  1689. @Color CHAR(7),
  1690. @Groupavatar NVARCHAR(60), 
  1691. @Readaccess INT,
  1692. @Allowvisit INT,
  1693. @Allowpost INT,
  1694. @Allowreply INT,
  1695. @Allowpostpoll INT,
  1696. @Allowdirectpost INT,
  1697. @Allowgetattach INT,
  1698. @Allowpostattach INT,
  1699. @Allowvote INT,
  1700. @Allowmultigroups INT, 
  1701. @Allowsearch INT,
  1702. @Allowavatar INT,
  1703. @Allowcstatus INT,
  1704. @Allowuseblog INT,
  1705. @Allowinvisible INT,
  1706. @Allowtransfer INT,
  1707. @Allowsetreadperm INT, 
  1708. @Allowsetattachperm INT,
  1709. @Allowhidecode INT,
  1710. @Allowhtml INT,
  1711. @Allowcusbbcode INT,
  1712. @Allownickname INT,
  1713. @Allowsigbbcode INT,
  1714. @Allowsigimgcode INT,
  1715. @Allowviewpro INT,
  1716. @Allowviewstats INT,
  1717. @Allowtrade INT,
  1718. @Allowdiggs INT,
  1719. @Allowdebate INT,
  1720. @Allowbonus INT,
  1721. @Minbonusprice INT,
  1722. @Maxbonusprice INT,
  1723. @Disableperiodctrl INT, 
  1724. @Reasonpm INT,
  1725. @Maxprice SMALLINT,
  1726. @Maxpmnum SMALLINT,
  1727. @Maxsigsize SMALLINT,
  1728. @Maxattachsize INT,
  1729. @Maxsizeperday INT,
  1730. @Attachextensions CHAR(100),
  1731. @Maxspaceattachsize INT,
  1732. @Maxspacephotosize INT, 
  1733. @Raterange CHAR(100)
  1734. AS
  1735. INSERT INTO [dnt_usergroups]  ([radminid],[grouptitle],[creditshigher],[creditslower],
  1736. [stars] ,[color], [groupavatar],[readaccess], [allowvisit],[allowpost],[allowreply],
  1737. [allowpostpoll], [allowdirectpost],[allowgetattach],[allowpostattach],[allowvote],[allowmultigroups],
  1738. [allowsearch],[allowavatar],[allowcstatus],[allowuseblog],[allowinvisible],[allowtransfer],
  1739. [allowsetreadperm],[allowsetattachperm],[allowhidecode],[allowhtml],[allowcusbbcode],[allownickname],
  1740. [allowsigbbcode],[allowsigimgcode],[allowviewpro],[allowviewstats],[allowtrade],[allowdiggs],[disableperiodctrl],[reasonpm],
  1741. [maxprice],[maxpmnum],[maxsigsize],[maxattachsize],[maxsizeperday],[attachextensions],[raterange],[maxspaceattachsize],
  1742. [maxspacephotosize],[allowdebate],[allowbonus],[minbonusprice],[maxbonusprice]) 
  1743. VALUES(
  1744. @Radminid,@Grouptitle,@Creditshigher,@Creditslower,@Stars,@Color,@Groupavatar,@Readaccess,@Allowvisit,@Allowpost,@Allowreply,
  1745. @Allowpostpoll,@Allowdirectpost,@Allowgetattach,@Allowpostattach,@Allowvote,@Allowmultigroups,@Allowsearch,@Allowavatar,@Allowcstatus,
  1746. @Allowuseblog,@Allowinvisible,@Allowtransfer,@Allowsetreadperm,@Allowsetattachperm,@Allowhidecode,@Allowhtml,@Allowcusbbcode,@Allownickname,
  1747. @Allowsigbbcode,@Allowsigimgcode,@Allowviewpro,@Allowviewstats,@Allowtrade,@Allowdiggs,@Disableperiodctrl,@Reasonpm,@Maxprice,@Maxpmnum,@Maxsigsize,@Maxattachsize, 
  1748. @Maxsizeperday,@Attachextensions,@Raterange,@Maxspaceattachsize,@Maxspacephotosize,@Allowdebate,@Allowbonus,@Minbonusprice,@Maxbonusprice)
  1749. GO
  1750. IF OBJECT_ID('dnt_updateusergroup','P') IS NOT NULL
  1751. DROP PROC [dnt_updateusergroup]
  1752. GO
  1753. CREATE PROC [dnt_updateusergroup]
  1754. @Radminid INT,
  1755. @Grouptitle NVARCHAR(50),
  1756. @Creditshigher INT,
  1757. @Creditslower INT, 
  1758. @Stars INT,
  1759. @Color CHAR(7),
  1760. @Groupavatar NVARCHAR(60),
  1761. @Readaccess INT,
  1762. @Allowvisit INT,
  1763. @Allowpost INT,
  1764. @Allowreply INT,
  1765. @Allowpostpoll INT,
  1766. @Allowdirectpost INT,
  1767. @Allowgetattach INT,
  1768. @Allowpostattach INT,
  1769. @Allowvote INT,
  1770. @Allowmultigroups INT,
  1771. @Allowsearch INT,
  1772. @Allowavatar INT,
  1773. @Allowcstatus INT,
  1774. @Allowuseblog INT,
  1775. @Allowinvisible INT,
  1776. @Allowtransfer INT,
  1777. @Allowsetreadperm INT,
  1778. @Allowsetattachperm INT,
  1779. @Allowhidecode INT,
  1780. @Allowhtml INT,
  1781. @Allowcusbbcode INT,
  1782. @Allownickname INT,
  1783. @Allowsigbbcode INT,
  1784. @Allowsigimgcode INT,
  1785. @Allowviewpro INT,
  1786. @Allowviewstats INT,
  1787. @Allowtrade INT,
  1788. @Allowdiggs INT,
  1789. @Disableperiodctrl INT,
  1790. @Allowdebate INT,
  1791. @Allowbonus INT,
  1792. @Minbonusprice INT,
  1793. @Maxbonusprice INT,
  1794. @Reasonpm INT,
  1795. @Maxprice SMALLINT,
  1796. @Maxpmnum SMALLINT,
  1797. @Maxsigsize SMALLINT,
  1798. @Maxattachsize INT,
  1799. @Maxsizeperday INT,
  1800. @Attachextensions CHAR(100),
  1801. @Maxspaceattachsize INT,
  1802. @Maxspacephotosize INT,
  1803. @Groupid INT
  1804. AS
  1805. UPDATE [dnt_usergroups]  
  1806. SET [radminid]=@Radminid,[grouptitle]=@Grouptitle,[creditshigher]=@Creditshigher,[creditslower]=@Creditslower,
  1807. [stars]=@Stars,[color]=@Color,[groupavatar]=@Groupavatar,[readaccess]=@Readaccess, 
  1808. [allowvisit]=@Allowvisit,[allowpost]=@Allowpost,[allowreply]=@Allowreply,[allowpostpoll]=@Allowpostpoll, 
  1809. [allowdirectpost]=@Allowdirectpost,[allowgetattach]=@Allowgetattach,[allowpostattach]=@Allowpostattach,
  1810. [allowvote]=@Allowvote,[allowmultigroups]=@Allowmultigroups,[allowsearch]=@Allowsearch,[allowavatar]=@Allowavatar,
  1811. [allowcstatus]=@Allowcstatus,[allowuseblog]=@Allowuseblog,[allowinvisible]=@Allowinvisible,
  1812. [allowtransfer]=@Allowtransfer,[allowsetreadperm]=@Allowsetreadperm,[allowsetattachperm]=@Allowsetattachperm,
  1813. [allowhidecode]=@Allowhidecode,[allowhtml]=@Allowhtml,[allowcusbbcode]=@Allowcusbbcode,
  1814. [allownickname]=@Allownickname,[allowsigbbcode]=@Allowsigbbcode,[allowsigimgcode]=@Allowsigimgcode,
  1815. [allowviewpro]=@Allowviewpro,[allowviewstats]=@Allowviewstats,[allowtrade]=@Allowtrade,[allowdiggs]=@Allowdiggs,
  1816. [disableperiodctrl]=@Disableperiodctrl,[allowdebate]=@Allowdebate,[allowbonus]=@Allowbonus,
  1817. [minbonusprice]=@Minbonusprice,[maxbonusprice]=@Maxbonusprice,[reasonpm]=@Reasonpm,[maxprice]=@Maxprice,
  1818. [maxpmnum]=@Maxpmnum,[maxsigsize]=@Maxsigsize,[maxattachsize]=@Maxattachsize,[maxsizeperday]=@Maxsizeperday,
  1819. [attachextensions]=@Attachextensions,[maxspaceattachsize]=@Maxspaceattachsize,
  1820. [maxspacephotosize]=@Maxspacephotosize  
  1821. WHERE [groupid]=@Groupid
  1822. GO
  1823. IF OBJECT_ID('dnt_getonlinegroupicontable','P') IS NOT NULL
  1824. DROP PROC [dnt_getonlinegroupicontable]
  1825. GO
  1826. CREATE PROC [dnt_getonlinegroupicontable]
  1827. AS
  1828. SELECT [groupid], [displayorder], [title], [img] FROM [dnt_onlinelist] WHERE [img] <> '' ORDER BY [displayorder]
  1829. GO
  1830. IF OBJECT_ID('dnt_getuserlistbygroupid','P') IS NOT NULL
  1831. DROP PROC [dnt_getuserlistbygroupid]
  1832. GO
  1833. CREATE PROC [dnt_getuserlistbygroupid]
  1834. @groupIdList VARCHAR(500)
  1835. AS
  1836. SELECT 
  1837. [uid],
  1838. [username],
  1839. [nickname],
  1840. [password],
  1841. [secques],
  1842. [spaceid],
  1843. [gender],
  1844. [adminid],
  1845. [groupid],
  1846. [groupexpiry],
  1847. [extgroupids],
  1848. [regip],
  1849. [joindate],
  1850. [lastip],
  1851. [lastvisit],
  1852. [lastactivity],
  1853. [lastpost],
  1854. [lastpostid],
  1855. [lastposttitle],
  1856. [posts],
  1857. [digestposts],
  1858. [oltime],
  1859. [pageviews],
  1860. [credits],
  1861. [extcredits1],
  1862. [extcredits2],
  1863. [extcredits3],
  1864. [extcredits4],
  1865. [extcredits5],
  1866. [extcredits6],
  1867. [extcredits7],
  1868. [extcredits8],
  1869. [avatarshowid],
  1870. [email],
  1871. [bday],
  1872. [sigstatus],
  1873. [tpp],
  1874. [ppp],
  1875. [templateid],
  1876. [pmsound],
  1877. [showemail],
  1878. [invisible],
  1879. [newpm],
  1880. [newpmcount],
  1881. [accessmasks],
  1882. [onlinestate],
  1883. [newsletter],
  1884. [salt]
  1885. FROM [dnt_users] WHERE [groupid] IN (@groupIdList)
  1886. GO
  1887. IF OBJECT_ID('dnt_passpost','P') IS NOT NULL 
  1888. DROP PROC [dnt_passpost]
  1889. GO
  1890. CREATE PROC [dnt_passpost]
  1891. @currentPostTableId INT,
  1892. @postcount INT,
  1893. @pidList NVARCHAR(500)
  1894. AS
  1895. DECLARE @count INT,
  1896. @begin INT,
  1897. @postdatetime DATETIME,
  1898. @poster NVARCHAR(50),
  1899. @posterid INT,
  1900. @fid INT,
  1901. @title NVARCHAR(20),
  1902. @tid INT
  1903.  
  1904. SET @begin=1
  1905. EXEC('UPDATE  [dnt_posts'+@currentPostTableId+']   SET [invisible]=0 WHERE [pid] IN ('+@pidList+')')
  1906. UPDATE  [dnt_statistics] SET [totalpost]= [totalpost] + @postcount
  1907. DECLARE @tempposttable TABLE 
  1908. (
  1909. [ROWID] INT IDENTITY(1,1),
  1910. [postdatetime] DATETIME,
  1911. [poster] NVARCHAR(50),
  1912. [posterid] INT,
  1913. [fid] INT,
  1914. [title] NVARCHAR(20),
  1915. [tid] INT
  1916. )
  1917. INSERT INTO @tempposttable 
  1918. EXEC('SELECT [postdatetime],[poster],[posterid],[fid],[title],[tid] FROM [dnt_posts'+@currentPostTableId+'] WHERE [pid] IN ('+@pidList+')')
  1919. SELECT @count=COUNT(1) FROM @tempposttable
  1920. WHILE @begin <= @count
  1921. BEGIN
  1922. SELECT @postdatetime = [postdatetime],
  1923. @poster = [poster],
  1924. @posterid = [posterid],
  1925. @fid = [fid],
  1926. @title = [title],
  1927. @tid = [tid]
  1928. FROM @tempposttable
  1929. UPDATE [dnt_forums] 
  1930. SET [posts]=[posts] + 1, 
  1931. [todayposts]=CASE WHEN datediff(day,'2008-10-22',getdate())=0 
  1932. THEN [todayposts] + 1
  1933. ELSE [todayposts] END,
  1934. [lastpost]=@postdatetime,
  1935. [lastposter]=@poster,
  1936. [lastposterid]=@posterid 
  1937. WHERE [fid]=@fid
  1938. UPDATE [dnt_users] 
  1939. SET [lastpost] = @postdatetime, 
  1940. [lastpostid] = @posterid, 
  1941. [lastposttitle] = @title, 
  1942. [posts] = [posts] + 1  
  1943. WHERE [uid] = @posterid
  1944. UPDATE [dnt_topics] 
  1945. SET [replies]=[replies]+1,
  1946. [lastposter]=@poster,
  1947. [lastposterid]=@posterid,
  1948. [lastpost]=@postdatetime 
  1949. WHERE [tid]=@tid
  1950. SET @begin = @begin + 1
  1951. END
  1952. GO
  1953. IF OBJECT_ID('dnt_getunauditnewtopic','P') IS NOT NULL
  1954. DROP PROC [dnt_getunauditnewtopic]
  1955. GO
  1956. CREATE PROC [dnt_getunauditnewtopic]
  1957. AS
  1958. SELECT 
  1959. [tid],
  1960. [fid],
  1961. [iconid],
  1962. [typeid],
  1963. [readperm],
  1964. [price],
  1965. [poster],
  1966. [posterid],
  1967. [title],
  1968. [attention],
  1969. [postdatetime],
  1970. [lastpost],
  1971. [lastpostid],
  1972. [lastposter],
  1973. [lastposterid],
  1974. [views],
  1975. [replies],
  1976. [displayorder],
  1977. [highlight],
  1978. [digest],
  1979. [rate],
  1980. [hide],
  1981. [attachment],
  1982. [moderated],
  1983. [closed],
  1984. [magic],
  1985. [identify],
  1986. [special]
  1987. FROM dnt_topics
  1988. WHERE [displayorder] = -2 OR [displayorder] = -3 
  1989. ORDER BY [tid] DESC
  1990. GO
  1991. IF OBJECT_ID('dnt_getunauditnewtopicbycondition','P') IS NOT NULL
  1992. DROP PROC [dnt_getunauditnewtopicbycondition]
  1993. GO
  1994. CREATE PROCEDURE [dnt_getunauditnewtopicbycondition]
  1995. @fidlist NVARCHAR(500),
  1996. @pagesize int,
  1997. @displayorder INT,
  1998. @pageindex int
  1999. AS
  2000. DECLARE @startRow int,
  2001. @endRow int
  2002. SET @startRow = (@pageindex - 1) * @pagesize + 1
  2003. SET @endRow = @startRow + @pagesize -1
  2004. IF @fidlist = '0'
  2005. BEGIN
  2006. SELECT 
  2007. [TOPICS].[rate], 
  2008. [TOPICS].[fid], 
  2009. [TOPICS].[tid],
  2010. [TOPICS].[iconid],
  2011. [TOPICS].[typeid],
  2012. [TOPICS].[title],
  2013. [TOPICS].[price],
  2014. [TOPICS].[hide],
  2015. [TOPICS].[readperm],
  2016. [TOPICS].[poster],
  2017. [TOPICS].[posterid],
  2018. [TOPICS].[replies],
  2019. [TOPICS].[views],
  2020. [TOPICS].[postdatetime],
  2021. [TOPICS].[lastpost],
  2022. [TOPICS].[lastposter],
  2023. [TOPICS].[lastpostid],
  2024. [TOPICS].[lastposterid],
  2025. [TOPICS].[highlight],
  2026. [TOPICS].[digest],
  2027. [TOPICS].[displayorder],
  2028. [TOPICS].[attachment],
  2029. [TOPICS].[closed],
  2030. [TOPICS].[magic],
  2031. [TOPICS].[special] 
  2032. FROM(SELECT ROW_NUMBER() OVER(ORDER BY [tid] DESC)AS ROWID,
  2033. [dnt_topics].[rate], 
  2034. [dnt_topics].[fid], 
  2035. [dnt_topics].[tid],
  2036. [dnt_topics].[iconid],
  2037. [dnt_topics].[typeid],
  2038. [dnt_topics].[title],
  2039. [dnt_topics].[price],
  2040. [dnt_topics].[hide],
  2041. [dnt_topics].[readperm],
  2042. [dnt_topics].[poster],
  2043. [dnt_topics].[posterid],
  2044. [dnt_topics].[replies],
  2045. [dnt_topics].[views],
  2046. [dnt_topics].[postdatetime],
  2047. [dnt_topics].[lastpost],
  2048. [dnt_topics].[lastposter],
  2049. [dnt_topics].[lastpostid],
  2050. [dnt_topics].[lastposterid],
  2051. [dnt_topics].[highlight],
  2052. [dnt_topics].[digest],
  2053. [dnt_topics].[displayorder],
  2054. [dnt_topics].[attachment],
  2055. [dnt_topics].[closed],
  2056. [dnt_topics].[magic],
  2057. [dnt_topics].[special] 
  2058. FROM [dnt_topics]
  2059. WHERE [displayorder] = @displayorder) AS TOPICS
  2060. WHERE ROWID BETWEEN @startRow AND @endRow
  2061. END
  2062. ELSE
  2063. BEGIN
  2064. SELECT 
  2065. [TOPICS].[rate], 
  2066. [TOPICS].[fid], 
  2067. [TOPICS].[tid],
  2068. [TOPICS].[iconid],
  2069. [TOPICS].[typeid],
  2070. [TOPICS].[title],
  2071. [TOPICS].[price],
  2072. [TOPICS].[hide],
  2073. [TOPICS].[readperm],
  2074. [TOPICS].[poster],
  2075. [TOPICS].[posterid],
  2076. [TOPICS].[replies],
  2077. [TOPICS].[views],
  2078. [TOPICS].[postdatetime],
  2079. [TOPICS].[lastpost],
  2080. [TOPICS].[lastposter],
  2081. [TOPICS].[lastpostid],
  2082. [TOPICS].[lastposterid],
  2083. [TOPICS].[highlight],
  2084. [TOPICS].[digest],
  2085. [TOPICS].[displayorder],
  2086. [TOPICS].[attachment],
  2087. [TOPICS].[closed],
  2088. [TOPICS].[magic],
  2089. [TOPICS].[special] 
  2090. FROM(SELECT ROW_NUMBER() OVER(ORDER BY [tid] DESC)AS ROWID,
  2091. [dnt_topics].[rate], 
  2092. [dnt_topics].[fid], 
  2093. [dnt_topics].[tid],
  2094. [dnt_topics].[iconid],
  2095. [dnt_topics].[typeid],
  2096. [dnt_topics].[title],
  2097. [dnt_topics].[price],
  2098. [dnt_topics].[hide],
  2099. [dnt_topics].[readperm],
  2100. [dnt_topics].[poster],
  2101. [dnt_topics].[posterid],
  2102. [dnt_topics].[replies],
  2103. [dnt_topics].[views],
  2104. [dnt_topics].[postdatetime],
  2105. [dnt_topics].[lastpost],
  2106. [dnt_topics].[lastposter],
  2107. [dnt_topics].[lastpostid],
  2108. [dnt_topics].[lastposterid],
  2109. [dnt_topics].[highlight],
  2110. [dnt_topics].[digest],
  2111. [dnt_topics].[displayorder],
  2112. [dnt_topics].[attachment],
  2113. [dnt_topics].[closed],
  2114. [dnt_topics].[magic],
  2115. [dnt_topics].[special] 
  2116. FROM [dnt_topics]
  2117. WHERE [displayorder] = @displayorder AND fid IN (@fidlist)) AS TOPICS
  2118. WHERE ROWID BETWEEN @startRow AND @endRow
  2119. END
  2120. GO
  2121. IF OBJECT_ID('dnt_getunauditpost','P') IS NOT NULL
  2122. DROP PROC [dnt_getunauditpost]
  2123. GO
  2124. CREATE PROCEDURE [dnt_getunauditpost]
  2125. @lastposter NVARCHAR(20),
  2126. @lastposterid INT
  2127. AS
  2128. UPDATE [dnt_topics] 
  2129. SET [lastposter]=@lastposter  
  2130. WHERE [lastposterid]=@lastposterid
  2131. GO
  2132. IF OBJECT_ID('dnt_updatetopicposter','P') IS NOT NULL
  2133. DROP PROC [dnt_updatetopicposter]
  2134. GO
  2135. CREATE PROCEDURE [dnt_updatetopicposter]
  2136. @poster NVARCHAR(20),
  2137. @posterid INT
  2138. AS
  2139. UPDATE [dnt_topics] 
  2140. SET [poster]=@poster 
  2141. WHERE [posterid]=@posterid
  2142. GO
  2143. IF OBJECT_ID('dnt_updatepostposter','P') IS NOT NULL
  2144. DROP PROC [dnt_updatepostposter]
  2145. GO
  2146. CREATE PROCEDURE [dnt_updatepostposter]
  2147. @poster NVARCHAR(20),
  2148. @posterid INT
  2149. AS
  2150. DECLARE @count INT,
  2151. @begin INT,
  2152. @tableid INT
  2153. SET @begin = 1
  2154. DECLARE @tempposttable TABLE 
  2155. (
  2156. [ROWID] INT IDENTITY(1,1),
  2157. [tableid] INT
  2158. )
  2159. INSERT INTO @tempposttable 
  2160. SELECT id FROM dnt_tablelist
  2161. SELECT @count=COUNT(1) FROM @tempposttable
  2162. WHILE @begin <= @count
  2163. BEGIN
  2164. SELECT  @tableid = [tableid] FROM @tempposttable WHERE [ROWID] = @begin
  2165. EXEC('UPDATE [dnt_posts' + @tableid + '] SET [poster]=''' + @poster + ''' WHERE [posterid]=' + @posterid )
  2166. SET @begin = @begin + 1
  2167. END
  2168. GO
  2169. IF OBJECT_ID('dnt_updatemoderatorname','P') IS NOT NULL
  2170. DROP PROC [dnt_updatemoderatorname]
  2171. GO
  2172. CREATE PROC [dnt_updatemoderatorname]
  2173. @oldname NVARCHAR(20),
  2174. @newname VARCHAR(20)
  2175. AS
  2176. IF @newname <> ''
  2177. UPDATE dnt_forumfields 
  2178. SET MODERATORS=REPLACE(LTRIM(RTRIM(REPLACE(' '+REPLACE(CONVERT(NVARCHAR(500),MODERATORS),',',' ')+' ',' '+@oldname+' ',' '+@newname+' '))),' ',',')
  2179. WHERE CHARINDEX(','+@oldname+',',','+CONVERT(NVARCHAR(500),MODERATORS)+',') > 0
  2180. ELSE
  2181. UPDATE dnt_forumfields 
  2182. SET MODERATORS = REPLACE(LTRIM(RTRIM(REPLACE(REPLACE(','+CONVERT(NVARCHAR(500),MODERATORS)+',',','+@oldname+',',','),',',' '))),' ',',')
  2183. WHERE CHARINDEX(','+@oldname+',',','+CONVERT(NVARCHAR(500),MODERATORS)+',') > 0
  2184. GO
  2185. IF OBJECT_ID('dnt_updateonlinelist','P') IS NOT NULL
  2186. DROP PROC [dnt_updateonlinelist]
  2187. GO
  2188. CREATE PROC [dnt_updateonlinelist]
  2189. @title NVARCHAR(50),
  2190. @groupid INT
  2191. AS
  2192. UPDATE [dnt_onlinelist] SET [title]=@title WHERE [groupid]=@groupid
  2193. GO
  2194. --此存储过程的作用是更新总帖子数
  2195. IF OBJECT_ID('dnt_resetforumsposts','P') IS NOT NULL
  2196. DROP PROC [dnt_resetforumsposts]
  2197. GO
  2198. CREATE PROC [dnt_resetforumsposts]
  2199. AS
  2200. --清空forums表中的帖子数,以便重新统计
  2201. UPDATE dnt_forums SET posts=0
  2202. DECLARE @i INT,
  2203. @maxlayer INT,
  2204. @maxtableid INT,
  2205. @tablename NVARCHAR(50)
  2206. SET @i = 1
  2207. --取分表数
  2208. SELECT @maxtableid = MAX(id) FROM dnt_tablelist
  2209. --依次处理分表
  2210. WHILE @i <= @maxtableid
  2211. BEGIN
  2212. SET @tablename = 'dnt_posts' + CONVERT(NVARCHAR(2),@i)
  2213. --如果分表不存在则继续处理下一个
  2214. IF NOT EXISTS(SELECT * FROM SYSOBJECTS WHERE id = OBJECT_ID(@tablename) AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  2215. CONTINUE
  2216. --取得每个版块在当前分表中的帖子数,累加并更新forums表中版块帖子数
  2217. EXEC('
  2218. UPDATE dnt_forums 
  2219. SET posts=posts+rightTable.fidcount 
  2220. FROM dnt_forums 
  2221. INNER JOIN (SELECT fid,COUNT(fid) fidcount FROM '+ @tablename +' GROUP BY fid) AS rightTable
  2222. ON dnt_forums.fid=rightTable.fid
  2223. WHERE dnt_forums.fid=rightTable.fid
  2224. ')
  2225. SET @i = @i + 1
  2226. END
  2227. --以下操作将子版块中的帖子总数累加并更新到父版块中
  2228. --取得版块的最大层数
  2229. SELECT @maxlayer = MAX(layer) FROM dnt_forums
  2230. --倒序更新,从最底层版块更新到最顶层
  2231. WHILE @maxlayer > 0
  2232. BEGIN
  2233. --将子版块中的帖子总数累加并更新到父版块中
  2234. UPDATE dnt_forums 
  2235. SET posts=posts+rightTable.sumposts 
  2236. FROM dnt_forums AS leftTable 
  2237. INNER JOIN (SELECT parentid,SUM(posts) sumposts FROM dnt_forums WHERE layer=@maxlayer GROUP BY parentid) AS rightTable
  2238. ON leftTable.fid=rightTable.parentid
  2239. WHERE leftTable.fid=rightTable.parentid
  2240. SET @maxlayer = @maxlayer - 1
  2241. END
  2242. GO
  2243. --此存储过程的作用是更新最后发帖
  2244. --测试代码:
  2245. --SELECT parentid,fid,lasttid,lasttitle,lastpost,lastposterid,lastposter FROM #tempTable2 ORDER BY parentid
  2246. --SELECT fid,lasttid,lasttitle,lastpost,parentid,lastposterid,lastposter FROM dnt_forums WHERE layer = 6 AND fid IN (245,256,260,259,273)
  2247. IF OBJECT_ID('dnt_resetlastpostinfo','P') IS NOT NULL
  2248. DROP PROC [dnt_resetlastpostinfo]
  2249. GO
  2250. CREATE PROC [dnt_resetlastpostinfo]
  2251. AS
  2252. --创建两个临时表#tempTable1,#tempTable2
  2253. CREATE TABLE #tempTable1 (
  2254. fid INT,
  2255. lasttid INT,
  2256. lasttitle NVARCHAR(60),
  2257. lastpost DATETIME,
  2258. parentid INT,
  2259. lastposterid INT,
  2260. lastposter NVARCHAR(30)
  2261.  )
  2262. CREATE table #tempTable2 (
  2263. fid INT,
  2264. lasttid INT,
  2265. lasttitle NVARCHAR(60),
  2266. lastpost DATETIME,
  2267. parentid INT,
  2268. lastposterid INT,
  2269. lastposter NVARCHAR(30)
  2270. )
  2271. DECLARE @maxlayer INT  -- 用来存放最大layer的变量
  2272. SELECT @maxlayer = MAX(layer) FROM dnt_forums;
  2273. --先初始化dnt_forums表中最后发帖等的信息
  2274. UPDATE dnt_forums SET lasttid = 0, lasttitle = '从未',lastpost = '1900-1-1',lastposterid=0,lastposter=''
  2275. --更新所有有主题的版块的最后发帖人等信息
  2276. UPDATE dnt_forums 
  2277. SET lasttid = rightTable.tid, lasttitle = rightTable.title, lastpost = rightTable.lastpost, lastposterid=rightTable.lastposterid, lastposter=rightTable.lastposter
  2278. FROM dnt_forums AS leftTable
  2279. INNER JOIN (SELECT fid,tid,title,lastpost,lastposter,lastposterid FROM dnt_topics WHERE tid IN( SELECT MAX(tid) FROM dnt_topics GROUP BY fid)) AS rightTable
  2280. ON leftTable.fid = rightTable.fid
  2281. WHERE leftTable.fid = rightTable.fid
  2282. WHILE @maxlayer > 0
  2283. BEGIN
  2284. --清空临时表#tempTable1,为了保证第二次循环时,表是空的
  2285. DELETE FROM #tempTable1;
  2286. --首先以dnt_forums表中的parentid字段分组,查询出每组最后回复时间最晚的记录;
  2287. --然后LEFT JOIN表dnt_forums,以两个表中parentid相等并且lastpost相等为条件,进行查询,
  2288. --并把结果插入到临时表#tempTable1中,以备临时表#tempTable2用
  2289. INSERT INTO #tempTable1 
  2290. SELECT fid,lasttid,lasttitle,a.lastpost,a.parentid,a.lastposterid,a.lastposter 
  2291. FROM (
  2292. SELECT parentid,MAX(lastpost) lastpost FROM dnt_forums a WHERE layer = @maxlayer GROUP BY parentid
  2293.  ) b 
  2294. LEFT JOIN dnt_forums a
  2295. ON a.parentid=b.parentid and a.lastpost=b.lastpost
  2296. --清空临时表#tempTable2,为了保证第二次循环时,表是空的
  2297. DELETE FROM #tempTable2;
  2298. --首先以#tempTable1表中的parentid分组,查询出组中的MAX(fid);
  2299. --然后以fid IN (子查询中查出的MAX(fid))为条件,查询出结果并插入到#tempTable2中
  2300. INSERT INTO #tempTable2 
  2301. SELECT * FROM #tempTable1
  2302. WHERE fid IN (SELECT MAX(fid) FROM #tempTable1 GROUP BY parentid,lastpost)
  2303. --根据临时表#tempTable2中的内容,更新dnt_forums表的最后发帖人等信息
  2304. UPDATE dnt_forums 
  2305. SET lastpost = CASE WHEN #tempTable2.lastpost>dnt_forums.lastpost THEN #tempTable2.lastpost
  2306.    ELSE dnt_forums.lastpost END,
  2307. lasttitle = CASE WHEN #tempTable2.lastpost>dnt_forums.lastpost THEN #tempTable2.lasttitle
  2308. ELSE dnt_forums.lasttitle END,
  2309. lasttid = CASE WHEN #tempTable2.lastpost>dnt_forums.lastpost THEN #tempTable2.lasttid
  2310. ELSE dnt_forums.lasttid END,
  2311. lastposterid = CASE WHEN #tempTable2.lastpost>dnt_forums.lastpost THEN #tempTable2.lastposterid
  2312. ELSE dnt_forums.lastposterid END,
  2313. lastposter = CASE WHEN #tempTable2.lastpost>dnt_forums.lastpost THEN #tempTable2.lastposter
  2314. ELSE dnt_forums.lastposter END
  2315. FROM dnt_forums 
  2316. INNER JOIN #tempTable2 
  2317. ON dnt_forums.fid=#tempTable2.parentid 
  2318. WHERE dnt_forums.fid=#tempTable2.parentid;
  2319. SET @maxlayer = @maxlayer - 1;
  2320. END
  2321. DROP TABLE #tempTable2;
  2322. DROP TABLE #tempTable1;
  2323. GO
  2324. /*
  2325. 此存储过程的作用:
  2326. 根据参数中传递过来的分表名更新主题的最后回复等信息
  2327. */
  2328. IF OBJECT_ID('dnt_resetLastRepliesInfoOftopics','P') IS NOT NULL
  2329. DROP PROC [dnt_resetLastRepliesInfoOftopics]
  2330. GO
  2331. CREATE PROC [dnt_resetLastRepliesInfoOftopics]
  2332. @posttable NVARCHAR(20)
  2333. AS
  2334. EXEC('
  2335. UPDATE dnt_topics 
  2336. SET dnt_topics.replies = lastPostTable.posts, 
  2337. lastpost = lastPostTable.postdatetime, 
  2338. lastposterid = lastPostTable.posterid, 
  2339. lastposter = lastPostTable.poster, 
  2340. lastpostid = lastPostTable.pid 
  2341. FROM dnt_topics
  2342. INNER JOIN  (
  2343. SELECT leftTable.tid,leftTable.posterid,leftTable.pid,leftTable.poster,leftTable.postdatetime,rightTable.posts FROM '+@posttable+' AS leftTable 
  2344. LEFT JOIN (SELECT tid,COUNT(*)-1 posts,MAX(pid) maxpid FROM '+@posttable+' GROUP BY tid) AS rightTable
  2345. ON leftTable.pid = rightTable.maxpid
  2346. WHERE leftTable.pid = rightTable.maxpid
  2347. ) AS lastPostTable
  2348. ON dnt_topics.tid = lastPostTable.tid
  2349. WHERE dnt_topics.tid = lastPostTable.tid AND dnt_topics.lastpostid <> lastPostTable.pid
  2350. ')
  2351. GO
  2352. /*
  2353. 此存储过程的作用:
  2354. 更新所有用户的精华帖数
  2355. */
  2356. IF OBJECT_ID('dnt_resetuserdigestposts','P') IS NOT NULL
  2357. DROP PROC [dnt_resetuserdigestposts]
  2358. GO
  2359. CREATE PROC [dnt_resetuserdigestposts]
  2360. AS
  2361. UPDATE dnt_users
  2362. SET [digestposts] = leftTable.topiccount 
  2363. FROM dnt_users 
  2364. INNER JOIN (SELECT COUNT(tid) topiccount,posterid FROM dnt_topics WHERE [digest] > 0 GROUP BY posterid) AS leftTable
  2365. ON dnt_users.[uid] = leftTable.posterid
  2366. WHERE dnt_users.[uid] = leftTable.posterid AND dnt_users.posts <> 0
  2367. GO
  2368. /*
  2369. 此存储过程的作用:
  2370. 根据参数中传递过来的分表名更新用户的帖子数
  2371. 后台更新所有用户帖子数时使用
  2372. */
  2373. IF OBJECT_ID('dnt_resetuserspostcount','P') IS NOT NULL
  2374. DROP PROC [dnt_resetuserspostcount]
  2375. GO
  2376. CREATE PROC [dnt_resetuserspostcount]
  2377. @posttablename NVARCHAR(50)
  2378. AS
  2379. EXEC('
  2380. UPDATE dnt_users
  2381. SET posts = posts + leftTable.postcount 
  2382. FROM dnt_users 
  2383. INNER JOIN (SELECT posterid,COUNT(pid) postcount FROM '+@posttablename+' GROUP BY posterid) AS leftTable
  2384. ON dnt_users.[uid] = leftTable.posterid
  2385. WHERE dnt_users.[uid] = leftTable.posterid
  2386. ')
  2387. GO
  2388. IF OBJECT_ID('dnt_createinvitecode','P') IS NOT NULL
  2389. DROP PROC [dnt_createinvitecode]
  2390. GO
  2391. CREATE PROCEDURE [dnt_createinvitecode]
  2392.                     @code char(8),
  2393.                     @creatorid int,
  2394.                     @creator nchar(20),
  2395.                     @createtime smalldatetime,
  2396.                     @expiretime smalldatetime,
  2397.                     @maxcount int,
  2398.                     @invitetype int
  2399.                     AS
  2400.                     
  2401.                     INSERT INTO [dnt_invitation]([invitecode],[creatorid],[creator],[createdtime],[expiretime],[maxcount],[invitetype])
  2402.                      VALUES(@code,@creatorid,@creator,@createtime,@expiretime,@maxcount,@invitetype);SELECT SCOPE_IDENTITY()
  2403. GO
  2404. IF OBJECT_ID('dnt_deleteinvitecode','P') IS NOT NULL
  2405. DROP PROC [dnt_deleteinvitecode]
  2406. GO
  2407. CREATE PROCEDURE [dnt_deleteinvitecode]
  2408. @id int
  2409. AS
  2410. BEGIN
  2411. UPDATE [dnt_invitation] SET [isdeleted]=1 WHERE [inviteid]=@id
  2412. END
  2413. GO
  2414. IF OBJECT_ID('dnt_clearexpireinvitecode','P') IS NOT NULL
  2415. DROP PROC [dnt_clearexpireinvitecode]
  2416. GO
  2417. CREATE PROCEDURE [dnt_clearexpireinvitecode]
  2418. AS
  2419. BEGIN
  2420. DELETE [dnt_invitation] WHERE [invitetype]=3 AND [createdtime]<>[expiretime] AND ([expiretime]-GETDATE())<=0;
  2421. DELETE [dnt_invitation] WHERE [isdeleted]=1 AND [createdtime]<(GETDATE()-1)
  2422. END
  2423. GO
  2424. IF OBJECT_ID('dnt_getinvitecode','P') IS NOT NULL
  2425. DROP PROC [dnt_getinvitecode]
  2426. GO
  2427. CREATE PROCEDURE [dnt_getinvitecode]
  2428. @searchtype nchar(10),
  2429. @searchkey nchar(20)
  2430. AS
  2431. BEGIN
  2432. IF @searchtype='uid'
  2433.    SELECT TOP 1 [inviteid],[invitecode],[invitetype],[createdtime],[creator],[creatorid],[expiretime],[maxcount],[successcount] 
  2434. FROM [dnt_invitation] WHERE [creatorid]=@searchkey AND [invitetype]=2 AND [isdeleted]=0 ORDER BY [inviteid] DESC
  2435. ELSE IF @searchtype='id'
  2436.    SELECT [inviteid],[invitecode],[invitetype],[createdtime],[creator],[creatorid],[expiretime],[maxcount],[successcount] FROM 
  2437. [dnt_invitation] WHERE [inviteid]=@searchkey AND [isdeleted]=0
  2438. ELSE IF @searchtype='code'
  2439.    SELECT [inviteid],[invitecode],[invitetype],[createdtime],[creator],[creatorid],[expiretime],[maxcount],[successcount] FROM 
  2440. [dnt_invitation] WHERE [invitecode]=@searchkey AND [isdeleted]=0
  2441. ELSE
  2442.    SELECT (1)
  2443. END
  2444. GO
  2445. IF OBJECT_ID('dnt_getinvitecodelistbyuid','P') IS NOT NULL
  2446. DROP PROC [dnt_getinvitecodelistbyuid]
  2447. GO
  2448. CREATE PROCEDURE [dnt_getinvitecodelistbyuid]
  2449. @creatorid int,
  2450. @pageindex int
  2451. AS
  2452. DECLARE @startRow int,
  2453. @endRow int
  2454. SET @startRow = (@pageIndex - 1) * 10 +1
  2455. SET @endRow = @startRow + 10 -1
  2456. SELECT 
  2457. [INVITATION].[inviteid],
  2458. [INVITATION].[invitecode],
  2459. [INVITATION].[invitetype],
  2460. [INVITATION].[createdtime],
  2461. [INVITATION].[creator],
  2462. [INVITATION].[creatorid],
  2463. [INVITATION].[expiretime],
  2464. [INVITATION].[maxcount],
  2465. [INVITATION].[successcount]
  2466. FROM (SELECT ROW_NUMBER() OVER(ORDER BY [inviteid] DESC)AS ROWID,
  2467. [inviteid],
  2468. [invitecode],
  2469. [invitetype],
  2470. [createdtime],
  2471. [creator],
  2472. [creatorid],
  2473. [expiretime],
  2474. [maxcount],
  2475. [successcount]
  2476. FROM [dnt_invitation]
  2477. WHERE [creatorid]=@creatorid and [invitetype]=3 AND [isdeleted]=0) AS INVITATION
  2478. WHERE ROWID BETWEEN @startRow AND @endRow
  2479. GO
  2480. IF OBJECT_ID('dnt_isinvitecodeexist','P') IS NOT NULL
  2481. DROP PROC [dnt_isinvitecodeexist]
  2482. GO
  2483. CREATE PROCEDURE [dnt_isinvitecodeexist]
  2484. @code nchar(8)
  2485. AS
  2486. BEGIN
  2487. SELECT COUNT(1) FROM [dnt_invitation] WHERE [invitecode]=@code AND [isdeleted] =0
  2488. END
  2489. GO
  2490. IF OBJECT_ID('dnt_updateinvitecodesuccesscount','P') IS NOT NULL
  2491. DROP PROC [dnt_updateinvitecodesuccesscount]
  2492. GO
  2493. CREATE PROCEDURE [dnt_updateinvitecodesuccesscount]
  2494. @id int
  2495. AS
  2496. BEGIN
  2497. UPDATE [dnt_invitation] SET [successcount]=[successcount]+1 WHERE [inviteid]=@id
  2498. END
  2499. GO
  2500. IF OBJECT_ID('dnt_getuserinvitecodecount','P') IS NOT NULL
  2501. DROP PROC [dnt_getuserinvitecodecount]
  2502. GO
  2503. CREATE PROCEDURE [dnt_getuserinvitecodecount]
  2504. @creatorid int
  2505. AS
  2506. BEGIN
  2507. SELECT COUNT(1) FROM [dnt_invitation] WHERE [creatorid]=@creatorid AND [invitetype]=3 AND [isdeleted]=0
  2508. END
  2509. GO
  2510. IF OBJECT_ID('dnt_gettodayusercreatedinvitecode','P') IS NOT NULL
  2511. DROP PROC [dnt_gettodayusercreatedinvitecode]
  2512. GO
  2513. CREATE PROCEDURE [dnt_gettodayusercreatedinvitecode]
  2514. @creatorid int
  2515. AS
  2516. BEGIN
  2517. SELECT COUNT(1) FROM [dnt_invitation] WHERE [creatorid]=@creatorid AND [invitetype]=2 AND (GETDATE()- [createdtime])<1
  2518. END
  2519. GO
  2520. IF OBJECT_ID('dnt_getattachmentlistbyaid','P') IS NOT NULL
  2521. DROP PROC [dnt_getattachmentlistbyaid]
  2522. GO
  2523. CREATE PROCEDURE [dnt_getattachmentlistbyaid]
  2524. @aidlist varchar(500)
  2525. AS
  2526. SELECT [aid], [tid], [pid], [filename] FROM [dnt_attachments] WITH (NOLOCK) WHERE [aid] IN (SELECT [item] FROM [dnt_split](@aidlist, ',') )
  2527. GO
  2528. IF OBJECT_ID('dnt_deleteattachmentbyaidlist','P') IS NOT NULL
  2529. DROP PROC [dnt_deleteattachmentbyaidlist]
  2530. GO
  2531. CREATE PROCEDURE [dnt_deleteattachmentbyaidlist]
  2532. @aidlist VARCHAR(500)
  2533. AS
  2534. EXEC('DELETE FROM [dnt_attachments] WHERE [aid] IN ('+@aidlist+')')
  2535. GO
  2536. IF OBJECT_ID('dnt_deleteattachmentbytidlist','P') IS NOT NULL
  2537. DROP PROC [dnt_deleteattachmentbytidlist]
  2538. GO
  2539. CREATE PROCEDURE [dnt_deleteattachmentbytidlist]
  2540. @tidlist VARCHAR(500)
  2541. AS
  2542. EXEC('DELETE FROM [dnt_attachments] WHERE [tid] IN ('+@tidlist+')')
  2543. GO
  2544. IF OBJECT_ID('dnt_getattachmentlistbytidlist','P') IS NOT NULL
  2545. DROP PROC [dnt_getattachmentlistbytidlist]
  2546. GO
  2547. CREATE PROCEDURE [dnt_getattachmentlistbytidlist]
  2548. @tidlist VARCHAR(500)
  2549. AS
  2550. SELECT 
  2551. [aid],
  2552. [filename] 
  2553. FROM [dnt_attachments] WITH (NOLOCK)
  2554. WHERE [tid] IN (SELECT [item]FROM [dnt_split](@tidlist, ','))
  2555. GO
  2556. IF OBJECT_ID('dnt_updateuseronlinestates','P') IS NOT NULL
  2557. DROP PROCEDURE [dnt_updateuseronlinestates]
  2558. GO
  2559. CREATE PROCEDURE [dnt_updateuseronlinestates] 
  2560. @uidlist varchar(5000) = '' 
  2561. AS
  2562. EXEC ('UPDATE [dnt_users] SET [onlinestate]=0,[lastactivity]=GETDATE() WHERE [uid] IN ('+@uidlist+')')
  2563. GO
  2564. /*
  2565. 修改时间:2009-11-23
  2566. 修改原因:将CHARINDEX替换成了IN
  2567. 测试代码:
  2568. exec [dnt_deletetopicbytidlist1] '1246471,1246472',1
  2569. */
  2570. IF OBJECT_ID('dnt_deletetopicbytidlist1','P') IS NOT NULL
  2571. DROP PROCEDURE [dnt_deletetopicbytidlist1]
  2572. GO
  2573. CREATE PROCEDURE [dnt_deletetopicbytidlist1]
  2574.     @tidlist AS VARCHAR(2000),
  2575.     @chanageposts AS BIT
  2576. AS
  2577.     DECLARE @postcount int
  2578.     DECLARE @topiccount int
  2579.     DECLARE @todaycount int
  2580.     DECLARE @sqlstr nvarchar(4000)
  2581.     DECLARE @fid varchar(2000)
  2582.     DECLARE @posterid varchar(200)
  2583.     DECLARE @tempFid int
  2584.     DECLARE @tempPosterid int
  2585.     DECLARE @tempLayer int
  2586.     DECLARE @temppostdatetime datetime
  2587.     DECLARE @tempfidlist AS VARCHAR(1000)
  2588.     SET @fid = ''
  2589.     SET @posterid = ''
  2590.     SET @postcount=0
  2591.     SET @topiccount=0
  2592.     SET @todaycount=0
  2593.     SET @tempfidlist = '';
  2594.     IF @tidlist<>''
  2595.         BEGIN
  2596.             EXEC('DECLARE cu_dnt_posts CURSOR FOR SELECT [fid],[posterid],[layer],[postdatetime] FROM [dnt_posts1] WHERE [dnt_posts1].[tid] IN ('+@tidlist+')')
  2597.             OPEN cu_dnt_posts
  2598.             FETCH NEXT FROM cu_dnt_posts into @tempFid,@tempPosterid,@tempLayer,@temppostdatetime
  2599.             WHILE @@FETCH_STATUS = 0
  2600.                 BEGIN
  2601.                     SET @postcount = @postcount + 1
  2602.                     IF @tempLayer = 0
  2603.                     BEGIN
  2604.                     SET @topiccount = @topiccount + 1
  2605.                     END
  2606.                     IF DATEDIFF(d,@temppostdatetime,GETDATE()) = 0
  2607.                     BEGIN
  2608.                     SET @todaycount = @todaycount + 1
  2609.                     END
  2610.                     IF CHARINDEX(',' + LTRIM(STR(@tempFid)) + ',',@fid + ',') = 0
  2611.                     BEGIN
  2612.                     --SET @fid = @fid + ',' + LTRIM(STR(@tempFid))
  2613.                     SELECT @tempfidlist = ISNULL([parentidlist],'') FROM [dnt_forums] WHERE [fid] = @tempFid
  2614.                     IF RTRIM(@tempfidlist)<>''
  2615.                     BEGIN
  2616.                     SET @fid = RTRIM(@fid) + ',' +  RTRIM(@tempfidlist) + ',' + CAST(@tempFid AS VARCHAR(10))
  2617.                     END
  2618.                     ELSE
  2619.                     BEGIN
  2620.                     SET @fid =RTRIM(@fid) + ',' +  CAST(@tempFid AS VARCHAR(10))
  2621.                     END
  2622.                     END
  2623.                     IF @chanageposts = 1
  2624.                     BEGIN
  2625.                     UPDATE [dnt_users] SET [posts] = [posts] - 1 WHERE [uid] = @tempPosterid
  2626.                     END
  2627.                     FETCH NEXT FROM cu_dnt_posts into @tempFid,@tempPosterid,@tempLayer,@temppostdatetime
  2628.                 END
  2629.             CLOSE cu_dnt_posts
  2630.             DEALLOCATE cu_dnt_posts
  2631.             IF LEN(@fid)>0
  2632.                 BEGIN
  2633.                     SET @fid = SUBSTRING(@fid,2,LEN(@fid)-1)
  2634.                     IF @chanageposts = 1
  2635.                     BEGIN
  2636.                     UPDATE [dnt_statistics] SET [totaltopic]=[totaltopic] - @topiccount, [totalpost]=[totalpost] - @postcount
  2637.                     EXEC('UPDATE [dnt_forums] 
  2638.                     SET [posts]=[posts] - ' + @postcount + ',  
  2639.                     [topics]=[topics] - ' + @topiccount + ', 
  2640.                     [todayposts] = [todayposts] - ' + @todaycount + ' 
  2641.                     WHERE [fid] IN ('+@fid+')')
  2642.                     END
  2643.                     EXEC('DELETE FROM [dnt_favorites] WHERE [tid] IN ('+@tidlist+') AND [typeid]=0')
  2644.                     EXEC('DELETE FROM [dnt_polls] WHERE [tid] IN ('+@tidlist+')')
  2645.                     EXEC('DELETE FROM [dnt_posts1] WHERE [tid] IN ('+@tidlist+')')
  2646.                     EXEC('DELETE FROM [dnt_mytopics] WHERE [tid] IN ('+@tidlist+')')
  2647.                 END
  2648.             EXEC('DELETE FROM [dnt_topics] WHERE [closed] IN ('+@tidlist+') OR [tid] IN ('+@tidlist+')')
  2649.             EXEC('UPDATE [dnt_tags] SET [count]=[count]-1, [fcount]=[fcount]-1 WHERE [tagid] IN (SELECT [tagid] FROM [dnt_topictags] WHERE [tid] IN ('+@tidlist+'))') 
  2650.             EXEC('DELETE FROM [dnt_topictags] WHERE [tid] IN ('+@tidlist+')')
  2651.             EXEC('DELETE FROM [dnt_topictagcaches] WHERE [tid] IN ('+@tidlist+') OR [linktid] IN ('+@tidlist+')')
  2652. END
  2653. GO
  2654. /*修改存储过程的名字*/
  2655. IF OBJECT_ID('dnt_getattachmentlistbypid','P') IS NOT NULL
  2656. DROP PROC [dnt_getattachmentlistbypid]
  2657. GO
  2658. IF OBJECT_ID('dnt_getattachmentlistbypidlist','P') IS NOT NULL
  2659. DROP PROC [dnt_getattachmentlistbypidlist]
  2660. GO
  2661. CREATE PROCEDURE [dnt_getattachmentlistbypidlist]
  2662. @pidlist varchar(500)
  2663. AS
  2664. SELECT 
  2665. [aid],
  2666. [uid],
  2667. [tid],
  2668. [pid],
  2669. [postdatetime],
  2670. [readperm],
  2671. [filename],
  2672. [description],
  2673. [filetype],
  2674. [filesize],
  2675. [attachment],
  2676. [downloads],
  2677. [attachprice],
  2678. [width],
  2679. [height] 
  2680. FROM [dnt_attachments] WITH (NOLOCK)
  2681. WHERE [dnt_attachments].[pid] IN (SELECT [item]FROM [dnt_split](@pidlist, ',') )
  2682. GO
  2683. /*修改存储过程的名字*/
  2684. IF OBJECT_ID('dnt_getattachenmtlistbypid','P') IS NOT NULL
  2685. DROP PROC [dnt_getattachenmtlistbypid]
  2686. GO
  2687. IF OBJECT_ID('dnt_getattachmentlistbypid','P') IS NOT NULL
  2688. DROP PROC [dnt_getattachmentlistbypid]
  2689. GO
  2690. CREATE PROCEDURE [dnt_getattachmentlistbypid]
  2691. @pid INT
  2692. AS
  2693. SELECT 
  2694. [aid],
  2695. [uid],
  2696. [tid],
  2697. [pid],
  2698. [postdatetime],
  2699. [readperm],
  2700. [filename],
  2701. [description],
  2702. [filetype],
  2703. [filesize],
  2704. [attachment],
  2705. [downloads],
  2706. [attachprice],
  2707. [width],
  2708. [height] 
  2709. FROM [dnt_attachments] 
  2710. WHERE [pid]=@pid
  2711. GO
  2712. IF OBJECT_ID('dnt_getindexforumlist','P') IS NOT NULL
  2713. DROP PROC [dnt_getindexforumlist]
  2714. GO
  2715. CREATE PROCEDURE [dnt_getindexforumlist]
  2716. AS
  2717. SELECT CASE WHEN DATEDIFF(n, [lastpost], GETDATE())<600 THEN 'new' ELSE 'old' END AS [havenew],
  2718. [dnt_forums].[allowbbcode],
  2719. [dnt_forums].[allowblog],
  2720. [dnt_forums].[alloweditrules],
  2721. [dnt_forums].[allowhtml],
  2722. [dnt_forums].[allowimgcode],
  2723. [dnt_forums].[allowpostspecial],
  2724. [dnt_forums].[allowrss],
  2725. [dnt_forums].[allowsmilies],
  2726. [dnt_forums].[allowspecialonly],
  2727. [dnt_forums].[allowtag],
  2728. [dnt_forums].[allowthumbnail],
  2729. [dnt_forums].[autoclose],
  2730. [dnt_forums].[colcount],
  2731. [dnt_forums].[curtopics],
  2732. [dnt_forums].[disablewatermark],
  2733. [dnt_forums].[displayorder],
  2734. [dnt_forums].[fid],
  2735. [dnt_forums].[inheritedmod],
  2736. [dnt_forums].[istrade],
  2737. [dnt_forums].[jammer],
  2738. [dnt_forums].[lastpost],
  2739. [dnt_forums].[lastposter],
  2740. [dnt_forums].[lastposterid],
  2741. [dnt_forums].[lasttid],
  2742. [dnt_forums].[lasttitle],
  2743. [dnt_forums].[layer],
  2744. [dnt_forums].[modnewposts],
  2745. [dnt_forums].[name],
  2746. [dnt_forums].[parentid],
  2747. [dnt_forums].[parentidlist],
  2748. [dnt_forums].[pathlist],
  2749. [dnt_forums].[posts],
  2750. [dnt_forums].[recyclebin],
  2751. [dnt_forums].[status],
  2752. [dnt_forums].[subforumcount],
  2753. [dnt_forums].[templateid],
  2754. [dnt_forums].[todayposts],
  2755. [dnt_forums].[topics],
  2756. [dnt_forumfields].[applytopictype],
  2757. [dnt_forumfields].[attachextensions],
  2758. [dnt_forumfields].[description],
  2759. [dnt_forumfields].[fid],
  2760. [dnt_forumfields].[getattachperm],
  2761. [dnt_forumfields].[icon],
  2762. [dnt_forumfields].[moderators],
  2763. [dnt_forumfields].[password],
  2764. [dnt_forumfields].[permuserlist],
  2765. [dnt_forumfields].[postattachperm],
  2766. [dnt_forumfields].[postbytopictype],
  2767. [dnt_forumfields].[postcredits],
  2768. [dnt_forumfields].[postperm],
  2769. [dnt_forumfields].[redirect],
  2770. [dnt_forumfields].[replycredits],
  2771. [dnt_forumfields].[replyperm],
  2772. [dnt_forumfields].[rewritename],
  2773. [dnt_forumfields].[rules],
  2774. [dnt_forumfields].[seodescription],
  2775. [dnt_forumfields].[seokeywords],
  2776. [dnt_forumfields].[topictypeprefix],
  2777. [dnt_forumfields].[topictypes],
  2778. [dnt_forumfields].[viewbytopictype],
  2779. [dnt_forumfields].[viewperm]
  2780. FROM [dnt_forums] 
  2781. LEFT JOIN [dnt_forumfields] ON [dnt_forums].[fid]=[dnt_forumfields].[fid] 
  2782. WHERE [dnt_forums].[status] > 0 AND [layer] <= 1 
  2783. AND [dnt_forums].[parentid] NOT IN (SELECT [fid] FROM [dnt_forums] WHERE [status] < 1 AND [layer] = 0) ORDER BY [displayorder]
  2784. GO
  2785. IF OBJECT_ID('dnt_resetforumstopics','P') IS NOT NULL
  2786. DROP PROC [dnt_resetforumstopics]
  2787. GO
  2788. CREATE PROC [dnt_resetforumstopics]
  2789. AS
  2790. --更新所有版块的主题数,不包含子版块
  2791. UPDATE dnt_forums 
  2792. SET curtopics=rightTable.sumtopics,topics = rightTable.sumtopics
  2793. FROM dnt_forums 
  2794. INNER JOIN (SELECT fid,count(tid) sumtopics FROM dnt_topics GROUP BY fid) AS rightTable
  2795. ON dnt_forums.fid=rightTable.fid
  2796. WHERE dnt_forums.fid=rightTable.fid
  2797. DECLARE @maxlayer INT
  2798. SELECT @maxlayer = MAX(layer) FROM dnt_forums
  2799. --倒序更新,从最底层版块更新到最顶层
  2800. WHILE @maxlayer > 0
  2801. BEGIN
  2802. --将子版块中的帖子总数累加并更新到父版块中
  2803. UPDATE dnt_forums 
  2804. SET topics=topics+rightTable.sumtopics 
  2805. FROM dnt_forums AS leftTable 
  2806. INNER JOIN (SELECT parentid,SUM(topics) sumtopics FROM dnt_forums WHERE layer=@maxlayer GROUP BY parentid) AS rightTable
  2807. ON leftTable.fid=rightTable.parentid
  2808. WHERE leftTable.fid=rightTable.parentid
  2809. SET @maxlayer = @maxlayer - 1
  2810. END
  2811. GO
  2812. if exists (select * from sysobjects where id = object_id(N'[dnt_createorder]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2813. drop procedure [dnt_createorder]
  2814. GO
  2815. CREATE PROCEDURE [dnt_createorder]
  2816. @ordercode char(32),
  2817. @uid int,
  2818. @buyer char(20),
  2819. @paytype tinyint,
  2820. @price decimal(18,2),
  2821. @orderstatus tinyint,
  2822. @credit tinyint,
  2823. @amount int
  2824. AS
  2825. BEGIN
  2826. INSERT INTO [dnt_orders]([ordercode],[uid],[buyer],[paytype],[price],[orderstatus],
  2827. [credit],[amount]) VALUES(@ordercode,@uid,@buyer,@paytype,@price,@orderstatus,@credit,@amount)
  2828. END
  2829. GO
  2830. if exists (select * from sysobjects where id = object_id(N'[dnt_getorderbyordercode]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2831. drop procedure [dnt_getorderbyordercode]
  2832. GO
  2833. CREATE PROCEDURE [dnt_getorderbyordercode]
  2834. @ordercode char(32)
  2835. AS
  2836. BEGIN
  2837. SELECT [orderid],[ordercode],[uid],[buyer],[paytype],[tradeno],[price],[orderstatus],[createdtime],[confirmedtime]
  2838. ,[credit],[amount] FROM [dnt_orders] WHERE [ordercode]=@ordercode
  2839. END
  2840. GO
  2841. if exists (select * from sysobjects where id = object_id(N'[dnt_getorderlist]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2842. drop procedure [dnt_getorderlist]
  2843. GO
  2844. CREATE PROCEDURE [dnt_getorderlist]
  2845. @searchcondition varchar(1000)
  2846. AS
  2847. BEGIN
  2848. DECLARE @script VARCHAR(1000)
  2849. SET @script= 'SELECT TOP 20 [orderid],[ordercode],[uid],[buyer],[paytype],[tradeno],[price],[orderstatus],[createdtime],[confirmedtime]
  2850. ,[credit],[amount] FROM [dnt_orders] '+@searchcondition+' ORDER BY [orderid] DESC'
  2851. EXEC(@script)
  2852. END
  2853. GO
  2854. if exists (select * from sysobjects where id = object_id(N'[dnt_getorderscount]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2855. drop procedure [dnt_getorderscount]
  2856. GO
  2857. CREATE PROCEDURE [dnt_getorderscount]
  2858. @searchcondition varchar(1000)
  2859. AS
  2860. BEGIN
  2861. DECLARE @script VARCHAR(1000)
  2862. SET @script= 'SELECT COUNT([orderid]) FROM [dnt_orders] '+@searchcondition
  2863. EXEC(@script)
  2864. END
  2865. GO
  2866. if exists (select * from sysobjects where id = object_id(N'[dnt_updateorderinfo]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2867. drop procedure [dnt_updateorderinfo]
  2868. GO
  2869. CREATE PROCEDURE [dnt_updateorderinfo]
  2870. @orderid int,
  2871. @tradeno char(32),
  2872. @orderstatus tinyint,
  2873. @confirmedtime smalldatetime
  2874. AS
  2875. BEGIN
  2876.     UPDATE [dnt_orders] SET [tradeno]=@tradeno,[orderstatus]=@orderstatus,[confirmedtime]=@confirmedtime WHERE [orderid]=@orderid
  2877. END
  2878. GO
  2879. if exists (select * from sysobjects where id = object_id(N'[dnt_clearexpirecreditorders]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2880. drop procedure [dnt_clearexpirecreditorders]
  2881. GO
  2882. CREATE PROCEDURE [dnt_clearexpirecreditorders]
  2883. AS
  2884. BEGIN
  2885.    DELETE [dnt_orders] WHERE [orderstatus] < 1 AND [createdtime] < (GETDATE()-15)
  2886. END
  2887. GO
  2888. IF OBJECT_ID('dnt_resettodayposts','P') IS NOT NULL
  2889. DROP PROC [dnt_resettodayposts]
  2890. GO
  2891. CREATE PROC [dnt_resettodayposts]
  2892. AS
  2893. UPDATE dnt_forums SET todayposts = 0;
  2894. DECLARE @tableid int;
  2895. SELECT @tableid = MAX(id) FROM dnt_tablelist;
  2896. EXEC('
  2897. UPDATE dnt_forums 
  2898. SET todayposts=rightTable.pidcount 
  2899. FROM dnt_forums 
  2900. INNER JOIN (SELECT fid,COUNT(pid) pidcount FROM dnt_posts'+ @tableid +' WHERE DATEDIFF(DAY,postdatetime,GETDATE())=0 GROUP BY fid ) AS rightTable
  2901. ON dnt_forums.fid=rightTable.fid
  2902. WHERE dnt_forums.fid=rightTable.fid
  2903. ')
  2904. GO
  2905. DECLARE @maxlayer INT
  2906. SELECT @maxlayer = MAX(layer) FROM dnt_forums
  2907. WHILE @maxlayer > 0
  2908. BEGIN
  2909. UPDATE dnt_forums 
  2910. SET todayposts=todayposts+rightTable.sumposts 
  2911. FROM dnt_forums AS leftTable 
  2912. INNER JOIN (SELECT parentid,SUM(todayposts) sumposts FROM dnt_forums WHERE layer=@maxlayer GROUP BY parentid) AS rightTable
  2913. ON leftTable.fid=rightTable.parentid
  2914. WHERE leftTable.fid=rightTable.parentid
  2915. SET @maxlayer = @maxlayer - 1
  2916. END
  2917. GO
  2918. IF OBJECT_ID('dnt_addparentforumtopics','P') IS NOT NULL
  2919. DROP PROC [dnt_addparentforumtopics]
  2920. GO
  2921. CREATE PROCEDURE [dnt_addparentforumtopics]
  2922. @topics int,
  2923. @fpidlist nvarchar(100)
  2924. AS
  2925.    UPDATE [dnt_forums] SET [topics] = [topics] + @topics WHERE [fid] IN (SELECT [item]FROM [dnt_split](@fpidlist, ',') )
  2926. GO
  2927. IF OBJECT_ID('dnt_updateusercredits','P') IS NOT NULL
  2928. DROP PROC [dnt_updateusercredits]
  2929. GO
  2930. CREATE PROCEDURE [dnt_updateusercredits]
  2931. @uid INT
  2932. AS
  2933. UPDATE [dnt_users] SET [credits] = extcredits1 + posts + digestposts* 5 WHERE [uid] = @uid
  2934. GO
  2935. IF OBJECT_ID('[dnt_gethottopicscount]','P')  IS NOT NULL
  2936. DROP PROC [dnt_gethottopicscount]
  2937. GO
  2938. CREATE PROCEDURE [dnt_gethottopicscount]
  2939. @fid int,
  2940. @timebetween int
  2941. AS
  2942. DECLARE @strSQL varchar(4000)
  2943. DECLARE @strSQLByFid nvarchar(200)
  2944. DECLARE @strSQLByDate nvarchar(200)
  2945. DECLARE @pagetop int
  2946. IF @fid<>0
  2947. SET @strSQLByFid=' AND [fid]='+STR(@fid)+'' 
  2948. IF @timebetween<>0
  2949. SET @strSQLByDate=' AND DATEDIFF(DAY,[postdatetime],GETDATE())<=' + STR(@timebetween)
  2950. SET @strSQL = 'SELECT COUNT(1) FROM [dnt_topics] WHERE 1=1 '+@strSQLByFid+@strSQLByDate
  2951. EXEC(@strSQL)
  2952. GO
  2953. IF OBJECT_ID('[dnt_gethottopicslist]','P')  IS NOT NULL
  2954. DROP PROC [dnt_gethottopicslist]
  2955. GO
  2956. CREATE PROCEDURE [dnt_gethottopicslist]
  2957. @pagesize int,
  2958. @pageindex int, 
  2959. @fid int,
  2960. @showtype varchar(100) , 
  2961. @timebetween int
  2962. AS
  2963. DECLARE @strSQL varchar(4000)
  2964. DECLARE @strSQLByFid nvarchar(200)=''
  2965. DECLARE @strSQLByDate nvarchar(200)=''
  2966. DECLARE @pagetop int
  2967. SET @pagetop = (@pageindex-1)*@pagesize
  2968. IF @fid<>0
  2969. BEGIN
  2970. SET @strSQLByFid='AND t.[fid]='+STR(@fid)
  2971. END
  2972. IF @timebetween<>0
  2973. SET @strSQLByDate=' AND DATEDIFF(DAY,[postdatetime],GETDATE())<=' + STR(@timebetween)
  2974. IF @pageindex=1
  2975. BEGIN
  2976. SET @strSQL = 'SELECT TOP ' + STR(@pagesize) +'  [t].[tid],[t].[fid],[t].[iconid],[t].[typeid],
  2977. [t].[readperm],[t].[price],[t].[poster],[t].[posterid],[t].[title],
  2978. [t].[attention],[t].[postdatetime],[t].[lastpost],[t].[lastpostid],[t].[lastposter],[t].[lastposterid],
  2979. [t].[views],[t].[replies],[t].[displayorder],[t].[highlight],[t].[digest],[t].[rate],[t].[hide],
  2980. [t].[attachment],[t].[moderated],[t].[closed],[t].[magic],[t].[identify],[t].[special],
  2981. f.[name] FROM [dnt_topics] t LEFT JOIN [dnt_forums] f ON t.[fid] = f.[fid] 
  2982. WHERE 1=1 '+@strSQLByFid+@strSQLByDate+' ORDER BY ['+@showtype+'] DESC'
  2983. END
  2984. ELSE
  2985. BEGIN
  2986. SET @strSQL = 'SELECT TOP ' + STR(@pagesize) +' [t].[tid],[t].[fid],[t].[iconid],[t].[typeid],[t].[readperm],[t].[price],
  2987. [t].[poster],[t].[posterid],[t].[title],[t].[attention],[t].[postdatetime],[t].[lastpost],[t].[lastpostid],
  2988. [t].[lastposter],[t].[lastposterid],[t].[views],[t].[replies],[t].[displayorder],[t].[highlight],[t].[digest],
  2989. [t].[rate],[t].[hide],[t].[attachment],[t].[moderated],[t].[closed],[t].[magic],[t].[identify],[t].[special],
  2990. f.[name] FROM [dnt_topics] t LEFT JOIN [dnt_forums] f ON t.[fid] = f.[fid] 
  2991. WHERE 1=1 ' +@strSQLByFid +@strSQLByDate+' AND [tid] NOT IN (SELECT TOP '+ STR(@pagetop)+' [tid] FROM [dnt_topics] 
  2992. WHERE 1=1 ' +@strSQLByFid +@strSQLByDate+' ORDER BY ['+@showtype+'] DESC) ORDER BY ['+@showtype+'] DESC'
  2993. END
  2994. EXEC(@strSQL)