Newsletter Plugin v3.02 - Additional Functionality

By northernpenguin - September 4, 2015

Daryl:  Not sure what is actually happening.  This is the code I am using:

At the top of the file:

<?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 newsletter
    $whereMessageNumIs = 'TRUE';
    
if (@$_REQUEST['message_num']){
 $whereMessageNumIs = " num = '".mysql_escape($_REQUEST['message_num'])."'";
}

list($_nlb_messages, $_nlb_messagesMetaData) = getRecords(array(
  'tableName'   => '_nlb_messages',
  'loadUploads' => true,
  'allowSearch' => false,
  'where'    => "to_list = '" . coalesce(mysql_escape(@$_REQUEST['to_list'], '2')) . "' AND " . $whereMessageNumIs,
));

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

?>

The dropdown & newsletter display:

<table cellspacing="2" cellpadding="4">
 <tr>
  <td valign="top">

    <b><?php echo htmlencode($message['subject']) ?></b><br/>
    <?php echo $message['html']; ?><br/>

  </td>
  <td valign="top">

    <h2>Weekly Message</h2>

<?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; ?>
</td>
</tr>
</table>

results:  a blank webpage (see attached).

I am trying o debug, but no clue so far.

--
northernpenguin
Northern Penguin Technologies

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

By Daryl - September 4, 2015

Try changing the 'where' line to: 

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

Daryl Maximo
PHP Programmer - interactivetools.com

By northernpenguin - September 4, 2015

Funny, one step forward!  Got the dropdown....but its blank!  See attached.

--
northernpenguin
Northern Penguin Technologies

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

By northernpenguin - September 4, 2015

Daryl:  After a bit more testing I have been able to display what I originally thought was the 1st message.... its not, its the template!  Nothing in my code should be displaying the template alone (see screen shot).  It still only displays 1 message, but shows nothing in dropdown.

Here is my 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 newsletter
    $whereMessageNumIs = 'TRUE';

if (@$_REQUEST['message_num']){
 $whereMessageNumIs = " num = '".mysql_escape($_REQUEST['message_num'])."'";
}

list($_nlb_messages, $_nlb_messagesMetaData) = getRecords(array(
  'tableName'   => '_nlb_messages',
  'loadUploads' => true,
  'allowSearch' => false,
  'where'    => "to_list = '" . coalesce(mysql_escape(@$_REQUEST['to_list']), '2') . "' AND " . $whereMessageNumIs,
//    'debugSql'            => true,
));

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

?>

<table cellspacing="2" cellpadding="4">
 <tr>
  <td valign="top">

<?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; ?>
</td>
  <td valign="top">

    <b><?php echo htmlencode($message['subject']) ?></b><br/>
    <?php echo $message['html']; ?><br/>

  </td>

</tr>
</table>

--
northernpenguin
Northern Penguin Technologies

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

By Daryl - September 9, 2015

Hi Ragi,

You're missing a ">" on your <option> tag:

<option value="<?php echo htmlencode($message['num']); ?>" <?php selectedIf($message['num'], @$_REQUEST['message_num']); ?>>

For displaying the messages, I'd check the values of $_nlb_messages first to confirm if it has any records in it and if the where clause that we added is correct by adding this code after the getRecords() function:

showme($_nlb_messages);

 And then I'd check if I'm looping through $_nlb_messages and display each records - pulling values from the correct array keys. The dropdown fields should take care of the filtering since you've already added the field and the where clause for '_nlb_messages'

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

By northernpenguin - September 10, 2015

Daryl:  Thanks, that worked out great!  I do have a couple of questions for you:

1.  I have hard coded the "Weekly Messages" list to show in the file weeklyMessage.php.  However, it always displays the first message in the list, not the latest.  How can I get it to always display the latest first?

2.  For some reason the "Reset" button doesn't seem to work.  On the browser (Chrome), the button border turns blue when I click it (and stays that way), but no reset occurs.  Any ideas?

Thanks!

Ragi

--
northernpenguin
Northern Penguin Technologies

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

By Daryl - September 11, 2015

Hi Ragi,

1.  I have hard coded the "Weekly Messages" list to show in the file weeklyMessage.php.  However, it always displays the first message in the list, not the latest.  How can I get it to always display the latest first?

- You can use orderBy to sort the records, for example:

  list($_nlb_messagesRecords, $_nlb_messagesMetaData) = getRecords(array(
    'tableName'   => '_nlb_messages',
    'orderBy'     => 'sent_date DESC',
  ));

2.  For some reason the "Reset" button doesn't seem to work.  On the browser (Chrome), the button border turns blue when I click it (and stays that way), but no reset occurs.  Any ideas?

- Can you send me a link so I can take a look?

Thanks,

Daryl Maximo
PHP Programmer - interactivetools.com

By northernpenguin - September 11, 2015

Hi Daryl

i should have thought of the orderBy!

you can se the reset on the http://706aircadets.ca/weeklyMessage.php

--
northernpenguin
Northern Penguin Technologies

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

By northernpenguin - September 11, 2015

Thanks Daryl!

--
northernpenguin
Northern Penguin Technologies

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