Set subscribe to forum by default

Mods, snippets and styles postet and supported by the users
Forum rules
As the forum title says this is for User Contributions
Post a support request in this forum and you will be banned!
Locked
Blue Blood
BBCoder II
BBCoder II
Posts: 20
Joined: 19 Oct 2011, 01:31
BBCodes: 12

Set subscribe to forum by default

Post by Blue Blood »

I had a client that needed all members to be automatically set to subscribe to all forums by default.
So here is the code I came up with.

OPEN includes/functions_user.php
FIND

Code: Select all

	$user_id = $db->sql_nextid();
AFTER-ADD

Code: Select all

// BB Subscribe to forum by default ------------------------------------------
	$sql = 'SELECT forum_id from '.FORUMS_TABLE;
	$result=$db->sql_query($sql);
	while ($row = $db->sql_fetchrow($result)){
		$arrForum[]=(int)$row['forum_id'];
	}
	foreach($arrForum as $forumId){
		$sql = 'INSERT INTO '.FORUMS_WATCH_TABLE.' (`forum_id`,`user_id`,`notify_status`) VALUES ('.$forumId.','.$user_id.',0)';
		$db->sql_query($sql);
	}
// BB Subscribe to forum by default ------------------------------------------
Now to fix all existing members
Insert this in your DB. You may have to change the prefix phpbb_

Code: Select all

insert into phpbb_forums_watch (user_id, forum_id, notify_status)
SELECT u.user_id, f.forum_id, 0 notify_status
FROM phpbb_users u, forums f
where u.user_type=0
and not exists (select 1 from phpbb_forums_watch fw where fw.user_id=u.user_id and fw.forum_id=f.forum_id)
Locked