Ok, so I am using a CMS (Xoops) and am trying to code a popup alert for new private messages.

I have it all figured out except for a couple things.

1) this popup pops up on any page load, and I would like it to only pop up once after the user logs in, or once after a new meesage is recieved. Any ideas?

2) I realize this is not a php question, but if you could help I would appreciate it. How can I get the pop up to center screen?

I have this script

<SCRIPT language="JavaScript1.2">
function poponload()
{
testwindow= window.open ("alert.php", "Private Messeges",
    "width=250,height=50");
testwindow.moveTo(0,0);
}
</SCRIPT>

linked to load like this

<{if $xoops_isuser}><{insert name="pms"}><{/if}>
<{if $msgcount > 0}>
<body onLoad="javascript: poponload()"><{else}><body><{/if}>

and here is my alert.php file

<?
include_once "mainfile.php";
echo "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"http://localhost/xoops2/themes/Le Mank Theme/style.css\" />";//edit this to point to your style.css file

GLOBAL $xoopsUser;
$pm_handler =& xoops_gethandler('privmessage');
$uid = $xoopsUser->getVar('uid');
$criteria = new CriteriaCompo(new Criteria('read_msg', 0));
$criteria->add(new Criteria('to_userid', $uid));
$msgcount = $pm_handler->getCount($criteria);

echo "<table id=\"alert\"><tr><td id=\"alert\"><center>";

if ($msgcount > 1)
{
echo "You Have '$msgcount' New Messages!</br>";
}
else
{
echo "You Have '$msgcount' New Message!</br>";
}

echo "<a href=\"javascript:window.close();\" onclick=\"opener.location='viewpmsg.php'\">Go To Inbox</a></br><a href=\"javascript:window.close();\">Cancel</a></center></td></tr></table>";

?>

Thanks for any help.
Steve

    This is not a PHP question...but I'll give you something to work off of.

    First of all, you'd be better off using a JavaScript alert() because that will always show. The way you are doing it, it will get blocked by pop-up blockers.

    It's simple to make it only show once with PHP. When the visitor visits, if they have any messages, then you print the JavaScript that pops up and alerts them. At the same time, it sets a cookie that says that it has sent the popup. Then, every time the page loads if it sees the cookie it knows it has already poped up. Look up 'PHP cookies' on Google.

    Hope this sets you in the right direction.

      Thanks guys/gals.

      I believe I got it, and it is in the mass testing phase now.

      Thanks again,
      Steve

        Write a Reply...