SOLVED Exclude banned Calendar Bdays?


Subject: Exclude banned Calendar Bdays?
Hey all,

I picked up an old project again and I don't really see how I can exclude birthdays of banned users from showing up.

The function file content I'm looking at is this part:
Code: [Download] [Hide] [Select]
/* Generates the list of birthdays for the given date
*/
function generate_birthday_list( $day, $month, $year )
{
global $db, $user, $config;

$birthday_list = "";
if ($config['load_birthdays'] && $config['allow_birthdays'])
{
$sql = 'SELECT user_id, username, user_colour, user_birthday
FROM ' . USERS_TABLE . "
WHERE user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', $day, $month)) . "%'
AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
// TBD TRANSLATION ISSUE HERE!!!
$birthday_list .= (($birthday_list != '') ? ', ' : '') . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
if ($age = (int) substr($row['user_birthday'], -4))
{
// TBD TRANSLATION ISSUE HERE!!!
$birthday_list .= ' (' . ($year - $age) . ')';
}
}
if( $birthday_list != "" )
{
// TBD TRANSLATION ISSUE HERE!!!
$birthday_list = $user->lang['BIRTHDAYS'].": ". $birthday_list;
}
$db->sql_freeresult($result);
}

return $birthday_list;
}


I did manage to exclude them from showing in my portals but the code used there is quite different :(

If anyone has any idea it would make me very happy because this calendar mod has been abandoned a long time ago.

Subject: Re: Exclude banned Calendar Bdays?
Well, I am not the best with php but can you play with this

Code: [Download] [Hide] [Select]
AND user_active = 1


Because banned users should have 0 , I guess

Profile PM  
Subject: Re: Exclude banned Calendar Bdays?
Thanks for the suggestion Steffen but this won't work on phpbb .. as far as I know this does not exist in my DB

Subject: Re: Exclude banned Calendar Bdays?
Hehehe, on phpBB3 you should have a look into phpbb_banlist => ban_userid

But I dont know how to change your code :(

EDIT: Maybe you can combine with this mod

Hide Banned Members From Memberlist on phpBB

OPEN memberlist.php
FIND
Code: [Download] [Hide] [Select]
// Get us some users :D

Add before
Code: [Download] [Hide] [Select]
//Begin: banned users hidden in memberlist_body
$sql = 'SELECT ban_userid
FROM ' . BANLIST_TABLE . '
WHERE ban_userid <> 0
AND (ban_end >= ' . time() . ' OR ban_end = 0)';
$result = $db->sql_query($sql);

$ban_list[] = array(0);
while ($row = $db->sql_fetchrow($result))
{
$ban_list[] = $row['ban_userid'];
}
$db->sql_freeresult($result);
//End: banned users hidden in memberlist_body


FIND
Code: [Download] [Hide] [Select]
$user_list[] = (int) $row['user_id'];

REPLACE WITH
Code: [Download] [Hide] [Select]
if (!in_array((int) $row['user_id'], $ban_list))//ban_list test line
{
$user_list[] = (int) $row['user_id'];
}

Profile PM  
Subject: Re: Exclude banned Calendar Bdays?
Thanks for the suggestion Steffen, however after looking at your suggestion I took another look at what I did to the portal in the past and maybe I got it fixed now ... the calendar looks a lot cleaner now but not completely missing birthdays.

I still have to test and investigate but I was so excited that I wanted to reply :LOL:

It would be great if anyone could tell me "yeah correct" or "no stupid!" so below is what I the changed code....

Code: [Download] [Hide]
  1. /* Generates the list of birthdays for the given date 
  2. */ 
  3. function generate_birthday_list( $day, $month, $year ) 
  4. global $db, $user, $config; 
  5.  
  6. $birthday_list = ""; 
  7. if ($config['load_birthdays'] && $config['allow_birthdays']) 
  8. $sql = 'SELECT user_id, username, user_colour, user_birthday 
  9. FROM ' . USERS_TABLE . ' 
  10. LEFT JOIN ' . BANLIST_TABLE . " b ON (user_id = b.ban_userid) 
  11. WHERE (b.ban_id IS NULL 
  12. OR b.ban_exclude = 1) 
  13. AND user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', $day, $month)) . "%' 
  14. AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')'; 
  15. $result = $db->sql_query($sql); 
  16. while ($row = $db->sql_fetchrow($result)) 
  17. // TBD TRANSLATION ISSUE HERE!!! 
  18. $birthday_list .= (($birthday_list != '') ? ', ' : '') . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']); 
  19. if ($age = (int) substr($row['user_birthday'], -4)) 
  20. // TBD TRANSLATION ISSUE HERE!!! 
  21. $birthday_list .= ' (' . ($year - $age) . ')'; 
  22. if( $birthday_list != "" ) 
  23. // TBD TRANSLATION ISSUE HERE!!! 
  24. $birthday_list = $user->lang['BIRTHDAYS'].": ". $birthday_list; 
  25. $db->sql_freeresult($result); 
  26.  
  27. return $birthday_list; 


changes:
- in line 5 I replaced the " by a '
- line 6, 7 and 8 are newly added
- in line 9 I replaced the WHERE into an AND

I truly can't believe I didn't goof anything up so please anyone judge it :LOL:

Subject: Re: Exclude Banned Calendar Bdays?
$sql = 'SELECT user_id, username, user_colour, user_birthday
FROM ' . USERS_TABLE . '
LEFT JOIN ' . BANLIST_TABLE . " b ON (user_id = b.ban_userid)
WHERE (b.ban_id IS NULL
OR b.ban_exclude = 1)
AND user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', $day, $month)) . "%'
AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';

maybe just
AND user_id NOT in (SELECT ban_userid FROM " . BANLIST_TABLE . ")
I don't have mysql here, so I can't "explain" queries but I think your one is better.

Profile PM  
Subject: Re: Exclude banned Calendar Bdays?
Thanks for another suggestion Informpro, yours does look alittle more "straight to the point"

If my own try starts showing flaws I will certainly try your idea!

Stuff I mostly doubt are in the use of the quotes and double quotes, I know almost nothing about all this stuff .. it's all just copy, paste, try to adjust and wait for errors to pop up for me TBH :wink:

Subject: Re: Exclude Banned Calendar Bdays?
There's actually too many way to achieve that. If you can run EXPLAIN on these queries, you'll have a better idea of the performance impact. You could also select in before (=> (SELECT bla FROM ...) as B), etc, etc.

Profile PM  
Subject: Re: Exclude banned Calendar Bdays?
I'll mark this solved before I get even more confused :LOL:

Thanks for all your replies guys :wink:


Page 1 of 1


  
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events

   

This is a "Lo-Fi" version of our main content. To view the full version with more information, formatting and images, please click here.

Powered by Icy Phoenix based on phpBB
Generation Time: 0.2992s (PHP: 7% SQL: 93%)
SQL queries: 10 - Debug Off - GZIP Enabled