Newsletter Plugin v3.02 - Additional Functionality

By northernpenguin - August 26, 2015

I have a client who is using the latest version of CMSB and Newsletter plugin v3.02.  The client has 3 active newsletters, each with a different group of subscribers.  The requirement is to display each newsletter on a separate Archive page.

Is there an easy way to do that?

Ragi

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

By Toledoh - August 26, 2015

Hey Ragi,

Wouldn't it be easiest to set up the search for the editor, something like 

Subscriber List|to_list|match

Then at the tope of the page, they just select which group to display?

Cheers,

Tim (toledoh.com.au)

By Dave - August 26, 2015

Hi Ragi, 

If you're talking about the "Newsletter Archive" viewer page then that's exactly what we're doing on our page here:
https://www.interactivetools.com/news/archive.php?145

We've got multiple newsletters: Our main newsletter, our beta announcements list, etc. 

What we do is just filter on the 'to_list' field Tim suggested, but in the viewer code, something like this:

'where' => " to_list = 1 ", 

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com

By northernpenguin - August 26, 2015

Dave:  I tried what you suggested and it sort of worked!  I created 2 test archive newsletter per list and figured which one was 1, 2 and 3. Then I entered the 'where' as you suggested in the viewer code.

Now the archive.php file will only display the latest newsletter from the list I wanted to display.  I have attached the basic file I am using.

So, two issues:

(1)  I still need to be able to pick and choose which newsletter I want to see from the list; and

(2)  the list of newsletters need to be somehow filtered so that I only see the pertinent newsletters.

Make sense?

Ragi

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke
Attachments:

test.php 4K

By Daryl - September 1, 2015

Hi Ragi,

If you need to be able to select which newsletter to display, you'll need a form with a dropdown list option for selecting a newsletter list. 

For example:

<?php
$newsLetterLists = mysql_select('_nlb_lists'); // mailing lists
?>

<?php if ($newsLetterLists): ?>
  <form method="get" action="?">
    <select name="to_list">
      <option value="">--</option>
      <?php foreach($newsLetterLists as $list): ?>
        <option value="<?php echo htmlencode($list['num']); ?>" <?php selectedIf($list['num'], @$_REQUEST['to_list']); ?>>
          <?php echo htmlencode($list['name']); ?>
        </option>
      <?php endforeach; ?>
    </select>
    <button type="submit" name="submitForm" value="1">Submit</button>
  </form>
<?php endif; ?>

Or a newsletter list menu:

<?php
$newsLetterLists = mysql_select('_nlb_lists');
?>

<?php if ($newsLetterLists): ?>
  <ul>
    <?php foreach($newsLetterLists as $list): ?>
      <li>
        <a href="?to_list=<?php echo htmlencode($list['num']); ?>">
          <?php echo htmlencode($list['name']); ?>
        </a>
      </li>
    <?php endforeach; ?>
  </ul>
<?php endif; ?>

And then change this line:

'where' => " to_list = 1 ", 

To:

'where' => "to_list = '" . coalesce(mysql_escape(@$_REQUEST['to_list'), '2') . "'",

Note: the coalesce() function works like MYSQL COALESCE which returns the first argument if the first argument is true(if exist), and will return the last argument if false. In the example above, if the user haven't selected a 'to_list', 'to_list' num 2 will be displayed. Kinda works like the to_list num 2 is the default list to display.

And for adding more filters, you can add more fields in the form and update the 'where' value base on the new fields.

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

By northernpenguin - September 1, 2015 - edited: September 1, 2015

Daryl:  I made some corrections to your code:

<?php include 'common/includes/php_header.inc'; ?>
<?php
  // error checking
  if (!@$GLOBALS['NEWSLETTER_BUILDER_PLUGIN']) { die("You must activate the newsletter plugin to see this page."); }

  // load newsletters settings and archives
  global $newsletterSettings;
  $newsletterSettings  = mysql_get('_nlb_settings', 1);
  $archivedNewsletters = mysql_select('_nlb_messages', "send IN ('all','archive') ORDER BY sent_date DESC");

  // load latest newsletter
  list($_nlb_messages, $_nlb_messagesMetaData) = getRecords(array(
    'tableName'   => '_nlb_messages',
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
    'where'    => "to_list = '" . coalesce(mysql_escape(@$_REQUEST['to_list'], '2')) . "'",
  ));
  $latestNewsletter = @$_nlb_messages[0]; // get first record
  if (!$latestNewsletter) { dieWith404("Couldn't find newsletter!"); } // show error message if no record found

  // replace placeholders
  $archivedNewsletters = nlb_viewers_replacePlaceholders($archivedNewsletters);
  $latestNewsletter    = nlb_viewers_replacePlaceholders($latestNewsletter);

?>

For some reason its not finding the newsletters.  It dies at the error message (in blue).

Any ideas?

P.S.  There are 3 templates & 6 newsletters in the queue.

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

By Daryl - September 2, 2015

Hi Ragi,

Sorry about the typo.

Can you try this to change the 'where' line to:

'where'    => "to_list = '" . coalesce(mysql_escape(@$_REQUEST['to_list']), '2') . "'",

Daryl Maximo
PHP Programmer - interactivetools.com

By northernpenguin - September 2, 2015 - edited: September 2, 2015

Daryl:  That worked!  Now I have a dropdown which lets me choose and see the latest newsletter.  How do I add a second dropdown to display the actual messages available for each newsletter?

For example, I have 3 lists, each of which currently has 2 messages.  With the current dropdown, only the last message is displayed.  I would like the user to choose which one to display.

P.S.  I just noticed that the following message gets printed on the webpage:

"category is selected!"

Not sure why.  Any ideas?

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

By northernpenguin - September 4, 2015

Thanks Daryl.  I will give that a try right now.

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke