<?php

// count up the number of new mails the user has!

$newmails = 0;
$notify = 0;
$result = mysql_query( "SELECT * FROM $pmtable WHERE strTo = '$gfcookie[1]'" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ( $a_row->intRead == 0 )
    {
        $newmails++;
    }
    if ( $a_row->intNotified == 0 )
    {
        $notify++;
    }

}

if ($notify == 1)
{
    ?>

    <script type="text/javascript">
    var name = confirm("You have 1 new private message in your inbox. Click OK to go to your inbox, or cancel to continue.")
    if (name == true)
    {
    window.location="inbox.php"
    }
    </script>

    <?php


}

if ($notify > 1)
{
    ?>
    <script type="text/javascript">
    var name = confirm("You have <?php print "$notify"; ?> new private messages in your inbox. Click OK to go to your inbox, or cancel to continue.")
    if (name == true)
    {
    window.location="inbox.php"
    }
    </script>
    <?php
}

$query = "UPDATE $pmtable SET intNotified = '1' WHERE strTo = '$gfcookie[1]'";
mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );



if ( $newmails == 1 )
{
    print "<p align=center style=\"margin-top: 0; margin-bottom: 0\"><font size=2 face=$font><a href=\"inbox.php\">You have 1 new private message!</a></p>";
}
else
{
    if ( $newmails > 1 )
    {
        print "<p align=center style=\"margin-top: 0; margin-bottom: 0\"><font size=2 face=$font><a href=\"inbox.php\">You have $newmails new private messages!</a></p>";
    }
}

?>