Deleting Unread PM's When Sender Saves The Message

Started by Rich, September 03, 2014, 08:32:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rich

This should fix it for TBDev 09 & U-232 (the Non-Memcache version)

Find
Code (php) Select

if ($pm_id)
        {
          // Delete a single message
          $res = mysql_query("select * FROM messages WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
          $message = mysql_fetch_assoc($res);
         
          if ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'no')
          {
            mysql_query("DELETE FROM messages WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
          }
          elseif ($message['sender'] == $CURUSER['id'] && $message['location'] == PM_DELETED)
          {
            mysql_query("DELETE FROM messages WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
          }
          elseif ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'yes')
          {
            mysql_query("UPDATE messages SET location=0 WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
          }
          elseif ($message['sender'] == $CURUSER['id'] && $message['location'] != PM_DELETED)
          {
            mysql_query("UPDATE messages SET saved='no' WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
          }
        }
        else
        {
          // Delete multiple messages
          foreach ($pm_messages as $id)
          {
            $res = mysql_query("select * FROM messages WHERE id=" . sqlesc((int) $id));
            $message = mysql_fetch_assoc($res);
           
            if ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'no')
            {
              mysql_query("DELETE FROM messages WHERE id=" . sqlesc((int) $id)) or sqlerr(__FILE__,__LINE__);
            }
            elseif ($message['sender'] == $CURUSER['id'] && $message['location'] == PM_DELETED)
            {
              mysql_query("DELETE FROM messages WHERE id=" . sqlesc((int) $id)) or sqlerr(__FILE__,__LINE__);
            }
            elseif ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'yes')
            {
              mysql_query("UPDATE messages SET location=0 WHERE id=" . sqlesc((int) $id)) or sqlerr(__FILE__,__LINE__);
            }
            elseif ($message['sender'] == $CURUSER['id'] && $message['location'] != PM_DELETED)
            {
              mysql_query("UPDATE messages SET saved='no' WHERE id=" . sqlesc((int) $id)) or sqlerr(__FILE__,__LINE__);
            }
          }
        }


Replace
Code (php) Select

if ($pm_id)
        {
            //-- Delete A Single Message --//
            $res = sql_query("SELECT *
                              FROM messages
                              WHERE id = " . sqlesc($pm_id)) or sqlerr(__FILE__, __LINE__);

            $message = mysql_fetch_assoc($res);

            if ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'no' || $message['sender'] == $CURUSER['id'] && $message['location'] == PM_DELETED)
            {
                sql_query("DELETE FROM messages
                           WHERE id = $id") or sqlerr(__FILE__, __LINE__);
            }
            elseif ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'yes')
            {
                sql_query("UPDATE messages
                           SET location = 0, unread = 'no'
                           WHERE id = $id") or sqlerr(__FILE__, __LINE__);
            }
            elseif ($message['sender'] == $CURUSER['id'] && $message['location'] != PM_DELETED)
            {
                sql_query("UPDATE messages
                           SET saved = 'no'
                           WHERE id = $id") or sqlerr(__FILE__, __LINE__);
            }
        }
        else
        {
            //-- Delete Multiple Messages --//
            foreach ($pm_messages
                     AS
                     $id)
            {
                $res = sql_query("SELECT *
                                  FROM messages
                                  WHERE id = " . sqlesc((int) $id));

                $message = mysql_fetch_assoc($res);

                if ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'no' || $message['sender'] == $CURUSER['id'] && $message['location'] == PM_DELETED)
                {
                    sql_query("DELETE FROM messages
                               WHERE id = $id") or sqlerr(__FILE__, __LINE__);
                }
                elseif ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'yes')
                {
                    sql_query("UPDATE messages
                               SET location = 0, unread = 'no'
                               WHERE id = $id") or sqlerr(__FILE__, __LINE__);
                }
                elseif ($message['sender'] == $CURUSER['id'] && $message['location'] != PM_DELETED)
                {
                    sql_query("UPDATE messages
                               SET saved = 'no'
                               WHERE id = $id") or sqlerr(__FILE__, __LINE__);
                }
            }
        }

xamalis

There is a bug there...its an memcached logic error
We have to delete users messages  values

So replace:
$mc1->delete_value('inbox_new_'.$pm_id);
$mc1->delete_value('inbox_new_sb_'.$pm_id);


With:
$mc1->delete_value('inbox_new_'.$message['receiver']);
$mc1->delete_value('inbox_new_sb_'.$message['receiver']);

Tundracanine

dont make sence unless you using like an way older version lol in
v3 and v4 its this only different is in v4 it uses language vars..
pm_system\delete.php
<?php
//=== don't allow direct access
if (!defined('BUNNY_PM_SYSTEM')) {
    
$HTMLOUT '';
    
$HTMLOUT.= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <title>ERROR</title>
        </head><body>
        <h1 style="text-align:center;">ERROR</h1>
        <p style="text-align:center;">How did you get here? silly rabbit Trix are for kids!.</p>
        </body></html>'
;
    echo 
$HTMLOUT;
    exit();
}
//=== Delete a single message first make sure it's not an unread urgent staff message
$res sql_query('SELECT receiver, sender, urgent, unread, saved, location FROM messages WHERE id='.sqlesc($pm_id)) or sqlerr(__FILE____LINE__);
$message mysqli_fetch_assoc($res);
//=== make sure they aren't deleting a staff message...
if ($message['receiver'] == $CURUSER['id'] && $message['urgent'] == 'yes' && $message['unread'] == 'yes'stderr('Error''You MUST read this message before you delete it!!!  <a class="altlink" href="pm_system.php?action=view_message&id='.$pm_id.'">BACK</a> to message.');
//=== make sure message isn't saved before deleting it, or just update location
if ($message['receiver'] == $CURUSER['id'/* && $message['saved'] == 'no'*/ || $message['sender'] == $CURUSER['id'] && $message['location'] == PM_DELETED) {
    
sql_query('DELETE FROM messages WHERE id='.sqlesc($pm_id)) or sqlerr(__FILE____LINE__);
    
$mc1->delete_value('inbox_new_'.$pm_id);
    
$mc1->delete_value('inbox_new_sb_'.$pm_id);
} elseif (
$message['receiver'] == $CURUSER['id'/* && $message['saved'] == 'yes'*/) {
    
sql_query('UPDATE messages SET location=0, unread=\'no\' WHERE id='.sqlesc($pm_id)) or sqlerr(__FILE____LINE__);
    
$mc1->delete_value('inbox_new_'.$pm_id);
    
$mc1->delete_value('inbox_new_sb_'.$pm_id);
} elseif (
$message['sender'] == $CURUSER['id'] && $message['location'] != PM_DELETED) {
    
sql_query('UPDATE messages SET saved=\'no\' WHERE id='.sqlesc($id)) or sqlerr(__FILE____LINE__);
    
$mc1->delete_value('inbox_new_'.$id);
    
$mc1->delete_value('inbox_new_sb_'.$id);
}
//=== see if it worked :D
if (mysqli_affected_rows($GLOBALS["___mysqli_ston"]) === 0stderr('Error''Message could not be deleted! <a class="altlink" href="pm_system.php?action=view_message&id='.$pm_id.'>BACK</a> to message.');
header('Location: pm_system.php?action=view_mailbox&deleted=1');
die();
?>


it clearly has memcache deletes in it..
If wanting support help please put bare min info like
Os:
U-232 Version:
Php Version:
Tracker type: like xbt or php
Saves on asking more questions just so people can help someone.

Rich

It may solve the issue with U-232 v2 and above but not for versions below, that don't make use of memcache.

Will look further into it.

cm27

I know once I flush memcahe or let it flushit self it gos away no matter what one I use .. I hope it helps yeah.
Never fall to those that just sit there.. Always look for the way to the top even if you have to code it your self and mistakes and all... quote from BonZO...

Rich

If a member sends you a PM and they Save & Send it and the receiver Deletes the message without reading it, the message is deleted, but it still show's on the Statusbar / Current Site Alerts that you have an unread PM.

This affects TBDev '09 all the way up to U-232 v3, I've not tested it on v4.