News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1181760128:v:use_geshi-1:v:type-php

Started by SleePy, Jun 13, 2007, 06:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SleePy

function ExportMessages()
{
   global $db_prefix, $ID_MEMBER, $scripturl, $user_info;
   // Find all Messages to export...
//          AND FIND_IN_SET('-1', pmr.labels)
   $request = db_query("
      SELECT pm.ID_PM, pm.ID_MEMBER_FROM, mem_to.RealName, pm.msgtime, pm.subject, pm.body, pmr.labels, mem_to.messageLabels
      FROM ({$db_prefix}personal_messages AS pm, {$db_prefix}pm_recipients AS pmr)
            LEFT JOIN {$db_prefix}members AS mem_to ON (mem_to.ID_MEMBER = pmr.ID_MEMBER)
      WHERE pmr.ID_PM = pm.ID_PM
         AND pmr.ID_MEMBER = $ID_MEMBER
         AND pmr.deleted = 0
      ORDER BY pmr.ID_PM ASC", __FILE__, __LINE__);

   // Load the ID_PMs and ID_MEMBERs and initialize recipients.
   $pms = array();
   $recipients = array();
   $pmessages = array();
   while ($row = mysql_fetch_assoc($request))
   {
      if (!isset($recipients[$row['ID_PM']]))
      {
         // We need this to get the recipients.
         $pms[] = $row['ID_PM'];

         // This is the main stuff though.
         $pmessages[$row['ID_PM']] = array(
            'id' => $row['ID_PM'],
            'from' => array(
               'id' => $row['ID_MEMBER_FROM'],
               'name' => $row['RealName'],
               ),
            'recipients' => array(
               'to' => array(),
               'bbc' => array(),
               ),
            'labels' => explode(',', $row['labels']),
            'sent' => $row['msgtime'],
            'subject' => $row['subject'],
            'body' => $row['body'],
            );
      }

      // Stop Repeating ourselves.
      if(isset($templables))
         $templables = explode(',', $row['messageLabels']);
   }
   mysql_free_result($request);

   if (!empty($pms))
   {
      // Get recipients (don't include bcc-recipients for your inbox, you're not supposed to know :P).
      $request = db_query("
         SELECT pmr.ID_PM, mem_to.ID_MEMBER AS ID_MEMBER_TO, mem_to.realName AS toName, pmr.bcc, pmr.labels, pmr.is_read
         FROM {$db_prefix}pm_recipients AS pmr
            LEFT JOIN {$db_prefix}members AS mem_to ON (mem_to.ID_MEMBER = pmr.ID_MEMBER)
         WHERE pmr.ID_PM IN (" . implode(', ', $pms) . ")", __FILE__, __LINE__);
      $context['message_labels'] = array();
      $context['message_replied'] = array();
      while ($row = mysql_fetch_assoc($request))
      {
         if (empty($row['bcc']))
            $pmessages[$row['ID_PM']]['recipients'][empty($row['bcc']) ? 'to' : 'bcc'][] = array (
               'id' => $row['ID_MEMBER_TO'],
               'name' => $row['toName'],
               );
      }

      mysql_free_result($request);
   }
   echo 'pmessages
', print_r($pmessages), '
';
}
No siggy! :D