<?php // no direct access
defined('_JEXEC') or die('Restricted access');

?>
<div class="nspro componentheading"><?php print JText::_('Newsletter View'); ?></div><br/>
<?php

$db =& JFactory::getDBO();

$query = 'SELECT * FROM `#__nspro_newsletter_attachments` AS atm LEFT JOIN `#__nspro_newsletters` AS ns ON atm.newsletter_id=ns.id WHERE ns.sent="1" ORDER BY atm.id';
$db->setQuery($query);
$mattachments = $db->loadObjectList();

$db->setQuery('SELECT * FROM `#__nspro_newsletters` WHERE `sent` = "1"');
$mNewsletters = $db->loadObjectList();

if (count($mNewsletters) > 0) {
  $found = false;
  foreach ($mNewsletters as $mnl) {
    if ($mnl->id == $_GET['nid']) {
      $found = true;
      print '<table cellpadding="2" class="nspro nsprotable">';
      print '<tr><td>' . JText::_('ID') . '</td><td>' . $mnl->id . '</td></tr>';
      print '<tr><td>' . JText::_('Subject') . '</td><td>' . $mnl->subject . '</td></tr>';
      print '<tr><td>' . JText::_('Date and Time Sent') . '</td><td>' . $mnl->datetime . '</td></tr>';

      $mybase = JString::str_ireplace('/administrator/', '/', JURI::base());
      $myLink = $mybase.'index.php?option=com_nspro&layout=confirmunsub'.'&u='.md5('Guest Email');
      $myFTFLink = $mybase.'index.php?option=com_nspro&task=forwardtofriend&nid=' . $mnl->id;
      $mMessage = JString::str_ireplace('{unsubscribe_link}', $myLink, $mnl->message);
      $mMessage = JString::str_ireplace('{subscriber_name}', 'Guest', $mMessage);
      $mMessage = JString::str_ireplace('{subscriber_email}', 'Guest Email', $mMessage);
      $mMessage = JString::str_ireplace('{forward_to_friend_link}', '<a href="'. $myFTFLink .'">', $mMessage);
      $mMessage = JString::str_ireplace('{/forward_to_friend_link}', '</a>', $mMessage);
      $mMessage = JString::str_ireplace('{unsub_quick}', '<a href="'. $myLink .'">', $mMessage);
      $mMessage = JString::str_ireplace('{/unsub_quick}', '</a>', $mMessage);
      print '<tr><td valign="top">' . JText::_('Message') . '</td><td><div id="nspro_message">' . $mMessage . '</div></td></tr>';
      print '</table>';
      break;
    }
  }
  if (!$found) {
    print JText::_('No Newsletter found.');
  }
}
else {
  print JText::_('No Newsletters found.');
}

?>

