Set subscribe to forum by default

Modifications for phpBB3.
Try the Mods here and share Your own Mods
Forum rules
You dont have to use ModX or make your mod AutoMod compatible. A simple textfile is fine
But if you post Mods here You also have to give support

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)