Email Reminder for inactive users v2.2.0

Like others before me, I've been using this mod quite a while on previous versions of vBulletin. Since updates and support for older 
versions had stopped, I figured I would make my own modifications and help others that have enjoyed it as well. I want to add back 
in some of the previous functionality that has been left out as well as add some new functionality. This mod for the most part 
picks up where the 3.7.x version leaves off.  

What does it do? 
=====================================
This mod will basically send out reminder emails to inactive members based on their last activity date to encourage them to come back to your site.

Features
The following features are updatable through the AdminCP.
=====================================
* Turn Product on/off.

* Set the number of days a user can be inactive (grace period) before email is sent.
  Example: Inactivity Graceperiod is set for 60 days. On day 61, member Bob will begin receiving reminder emails.
  
* Send Email Once. 
  If this is set, when members become inactive they will receive one reminder only. 

* Set how often an reminder email is sent after an inactive member has received their first reminder. 
  Example: Inactivity Grace period is set for 60 days, and Reminder Email frequency is set for 30 days. 
  On day 61, member Bob will receive his first reminder email letting him know he has been inactive for 
  over 60 days asking him to come back to see your new content. If Bob, continues to be inactive, Bob will 
  receive reminder emails based on the number of days you have the email frequency set to. If set to 30 days,
  members will receive reminders every 30 days after their first reminder.

* Set reminder email format - TEXT or HTML.
  
* Set the reminder email subject. (phrased)

* Set the reminder email body. (phrased)

* Set the usergroups to be sent a reminder email.

* Set Userids to exclude.

* Edit number of emails send totally (Max Reminders) 
  Example: If the Send Once option is set to false, and this option is set to 50. Inactive members will only receive 50 reminders.

* Keep a log of all inactive users contacted

* Opt-Out Feature for members - Include an opt-out link in reminder email. (Thanks to Gene Steinberg)

Install Instructions
--------------------------
VERSION 2.x and UP will not work on older releases of VB. This was written specifically for VB4x
*******
*** MOST IMPORTANT BEFORE YOU INSTALL THIS, IF YOU HAVE A PREVIOUS VERSION INSTALLED
*** I STRONGLY RECOMMEND THAT YOU BACK UP YOUR CUSTOM REMINDER MESSAGE SUBJECT AND MESSAGE BODY
*** THIS MOD WILL OVER WRITE THEM. ALSO, IN VERSION 2.x, REMINDER MESSAGE CONTENTS HAS BEEN 
*** MOVED TO USING VBPHRASES. LOOK IN THE INSTALL.TXT FILE WITH THIS UPLOAD FOR A LIST OF PHRASES
*** USED IN THIS MOD.
 
1. Upload file in the upload folder to your server.
2. In your AdminCP 
	a. If you've installed one of the old versions, uninstall it.
	b. Go to Plugs & Products -> Product Manager -> Add New Product.
	c. Import the product xml from the zip file.
3. Go to Vbulletin "Settings" -> Options -> Inactivity Reminder Emails
4. Configure as needed.

Note: This mod installs a plugin that adds a link in your footer, however 
it can be disabled via the AdminCP. If you find this mod useful, please don't disable this option.

Update 
=======================================
UpDate 2.2.0
* Removed logic to base inactivity on Last Post or Last Visit date. Inactivity is now based on 
Last Activity Date. 
* Removed option to select what to base inactivity on from the mod settings screen. 
* Fixed a couple typos in SQL update queries.
* Exporting the following additional values which can be used in reminder email templates if desired:
  $lastvisit 	- Formatted Date/Time Value - members last visit to the site.
  $lastactivity - Formatted Date/Time Value - members last activity on the site.
  $lastpost	- Formatted Date/Time Value - members last post date on the site.
  $lastreminder - Formatted Date/Time Value - Date member was sent last reminder email.
  $days_since_lastpost - Number of days since member last posted.
  $days_since_lastreminder - number of days since last reminder was sent.

Please let me know if you would like other values made available. 

Update 2.1.5

* Full Rewrite 
 
* Mod will no longer has the option of adding a footer credit to the end of 
  your website nor will it add a footer credit to outgoing emails. Enable/Disable options
  for on the mod settings screen in the AdminCP have also been removed.

* New Reminder Optout: Currently this is only accessable from emails being sent out.
  Please let members know that they may receive one more email at which time they can 
  choose to optout/unsubscribe by clicking on the embedded link or copying/paste it into
  their browser. 

* Logic used to determine when emails are sent out has been corrected. I'm basically 
  subtracting the current date from the last visit date or the last post date 
  (depending on how you have it set in the mod settings screen) to get the number of
  days it's been. That number is then compared with the grace period setting along with
  the other settings in the mod settings screen. 

  For instance: This query snippet will get the number of days since the last post date.
  TIMESTAMPDIFF(DAY, FROM_UNIXTIME(lastpost), FROM_UNIXTIME(UNIX_TIMESTAMP()))

  Mod will process members who have become inactive and never received a reminder first.
  It will then process members who are still inactive and have not received a reminder since 
  they received their previous reminder based on the frequency set in the mod settings screen.

* Issues when emails were sent out had the incorrect "From" address and listed the host domain name.
  This should be resolved now.

* Issue regarding special characters in the usernames trying to be added to the database has been resolve.

* New data fields have been implimented for keeping track of when reminders are sent out and how 
  many a member has received. If you have a had this mod installed since version 1.1.4, it will look for
  those fields and rename them so you do not loose previous data in those fields, otherwise new fields will
  be added.

* I've added the ability to turn off the admin report. In this version, if it is enabled, you may receive 
  2 reports.  One report for members that have never received a reminder and one for members who haven't received
  a reminder since the last reminder based on the frequencey setting in the mod settings screen,

* Reminder's sender and email address are correctly determined now. Should now reflect site name with the webmasteremail address 
  as the reply to.

* There may be other things fixed. Just no way of really tracking them yet. You should see my office. I have sticky notes all over 
  the place. LOL  j/k  :)


 
=========================================================
Update 2.1.1 (3/30/2010) - Bug Fix
* FIX - Removed extra where clause in query where scheduled task script was performing an update when inactive reminders where based on last post count.
* FIX - Email Phrase Templates - Changed $bburl variable to $forumurl to correct a broken unsubscribe link. 
* NEW - Includes tool to reset the date and count of reminder emails that were previously sent to users. This tool is mainly for testing purposes. 

==========================================================
Update 2.1.0 (3/26/2010) - Bug Fixs and some new features
* Edit number of emails send totally
* Choose whether inactivity is based on members "Last Post" or their "Last Activity"
* Keep a log of all inactive users contacted
* Opt-Out Feature for members - Include an opt-out link in reminder email. (Thanks to Gene Steinberg) 
* Added a link to the bottom of the default email template phrases that members can use to unsubscribe from reminder emails.

==========================================================
Update 2.0.1 (03/15/2010 9:00pm) - Bug Fix 
* FIX - Issue related to processing users in a batch
configuration. Mod was checking for a field length 
greater than zero instead of a numeric value greater
than zero. 

==========================================================
Update 2.0.0 (03/15/2010)
* NEW - Complete rewrite of addon 
* NEW - Can specify number of users to process at one time. 
* NEW - Send reminder emails in either text or html format.
* NEW - Email subject and message body is vbphrased.

Update 1.1.4 (03/05/2010)
* FIX - Would continue to send out email more often than specified intervals
        due to incorrect setting in cron job.
* NEW - Exclude userids from processing. 


Todo:
=====================================
* Multiple Email Templates

* Detect bounced email, mark it as bounced so the user is not to be contacted again so as to avoid spam, 
  and then move that user into a seperate usergroup.

* Automatically send a message to the member via PM about the bounced email problem. That way if and when they login, 
  they know there's a problem and can write to site admin with their new email address. (Thanks to Gene Steinberg)

* Specify alternative emails to send to reduce repetition


If you have any other features that you would like to have added, please let me know.


Credits & Previous Updates
======================================

Updates and fixes that have been carried over from version 1.1.3 can be found at the link below.
http://www.vbulletin.org/forum/showthread.php?t=180025&highlight=email+reminder

I also want to give full credit thanks to the developers of the previous versions 1.0.6 to 1.1.3 from which this was derived:

C Braithwaite 
http://www.vbulletin.org/forum/member.php?u=126221
robertjandreu
http://www.vbulletin.org/forum/member.php?u=230904


