Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: margarett on May 16, 2007, 06:43:09 PM

Title: Private message warning
Post by: margarett on May 16, 2007, 06:43:09 PM
Hi all.

Is there a way to have on index.template.php (or BoardIndex.template.php) a warning if the user is reaching is limit of PMs?

For instance, a usergroup has 20 PMs limit, and I would like to warn them on 18 or more PMs.

Thanks ;)
Title: Re: Private message warning
Post by: kerrang! on May 16, 2007, 09:29:01 PM
I've seen this feature although I haven't found it myself either. If anyone knows how to do this I would be very greatful if you could point me in the right direction.

Kerrang =)
Title: Re: Private message warning
Post by: margarett on May 25, 2007, 07:58:41 AM
Hi all.

Well, I made some coding experiences, and I *THINK* I know how to do it, just need to test it better.

My problem is, using firefox I can open the page, and find no major delay, but using IE the page takes forever to load, until it stops with an "excess memory allocated" error. I know this is a server limitation, but why does it only happens on IE?
Title: Re: Private message warning
Post by: margarett on June 15, 2007, 04:52:21 AM
Hi again.

I finally managed to get this to work. If someone wishes to make this a MOD, you are welcome.
Anyway, I picked a function from "PersonalMessages.php", modified it a bit, and then all what's needed is a very small amount of code.

So, here it goes:

Find:

/* Show sticky and lock status seperate from topic icons? Leave true, icons don't exist for false.*/
$settings['seperate_sticky_lock'] = true;
}


After, add:
function PMIndex()
{
global $txt, $scripturl, $sourcedir, $context, $user_info, $user_settings, $db_prefix, $ID_MEMBER;


// Load up the members maximum message capacity.
if (!$user_info['is_admin'])
{
// !!! Why do we do this?  It seems like if they have any limit we should use it.
$request = db_query("
SELECT MAX(maxMessages) AS topLimit, MIN(maxMessages) AS bottomLimit
FROM {$db_prefix}membergroups
WHERE ID_GROUP IN (" . implode(', ', $user_info['groups']) . ')', __FILE__, __LINE__);
list ($maxMessage, $minMessage) = mysql_fetch_row($request);
mysql_free_result($request);

$context['message_limit'] = $minMessage == 0 ? 0 : $maxMessage;
}
else
$context['message_limit'] = 0;
}


Find:
<body>';

After, add:

PMIndex();

if ($context['user']['is_logged'] && $context['allow_pm'] && $context['message_limit'] > 0)
{
$aux_calc = $context['message_limit'] - $context['user']['messages'];
if (($aux_calc <= 2) && ($aux_calc != 0))
echo' <div align="center"; style="font-size: 20pt; color: #ffffff">PM BOX ALMOST FULL</div>';
elseif ($aux_calc == 0 )
echo' <div align="center"; style="font-size: 20pt; color: #ffffff">PM BOX FULL!</div>';

}


You can add those text strings to languages, etc etc... In my case, I do not need different languages, so I made it this way.

This was tested in IE6 and FF, but I belive it should work everywhere.

As for the previous error with IE and that excess memory error, in this new hosting it is not a problem.