Newsletter Plugin v3.02 - Additional Functionality

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

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 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 Daryl - September 4, 2015 - edited: September 4, 2015

Hi Ragi,

With the current dropdown, only the last message is displayed.

- This is because we're only getting one record as per this line:

$latestNewsletter = @$_nlb_messages[0]; // get first record

To display all the messages under the selected newsletter, you should loop through $_nlb_messages and display each record. Displaying the $latestNewsletter record will only display the latest record.

If you need a second dropdown for selecting which message to display, loop through $_nlb_messages and display each as <option> of a drop down select field. For example:

<?php if ($_nlb_messages): ?>
 <select name="message_num">
   <option value="">--</option>
   <?php foreach($_nlb_messages as $message): ?>
     <option value="<?php echo htmlencode($message['num']); ?>" <?php selectedIf($message['num'], @$_REQUEST['message_num']); ?>>
       <?php echo htmlencode($message['subject']); ?>
     </option>
   <?php endforeach; ?>
 </select>
<?php endif; ?>

And then add another clause to your 'where' statement to filter the results by  'num' of the selected message. For example:

$whereMessageNumIs = 'TRUE';
if (@$_REQUEST['message_num']){
 $whereMessageNumIs = " num = '".mysql_escape($_REQUEST['message_num'])."'";
}
list($_nlb_messages, $_nlb_messagesMetaData) = getRecords(array(
  'tableName'   => '_nlb_messages',
  //...
  'where'    => "to_list = '" . coalesce(mysql_escape(@$_REQUEST['to_list']), '2') . "' AND " . $whereMessageNumIs,
));

For readability, you might want to add the to_list filter to a where variable as well. For example:

$where = 'TRUE';
if (@$_REQUEST['to_list']){
 $where .= " AND to_list = '".mysql_escape($_REQUEST['to_list'])."'";
}
if (@$_REQUEST['message_num']){
 $where .= " AND num = '".mysql_escape($_REQUEST['message_num'])."'";
}
list($_nlb_messages, $_nlb_messagesMetaData) = getRecords(array(
  'tableName'   => '_nlb_messages',
  //...
  'where'       => $where,
));

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

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