Skip to content

Commit

Permalink
Added smart path to cron script and functions. Reminder script tested…
Browse files Browse the repository at this point in the history
… and functional, but seems to lock up after 10-40 emails.
  • Loading branch information
Matthaus Litteken authored and Matthaus Litteken committed Dec 15, 2009
1 parent bd92474 commit eeb67b6
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 60 deletions.
3 changes: 2 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************

Features/Script Specifics
- Update payment plan on payment before setting next payment date.
- User management tab
- Reports including contact list generator, mailing labels, and more.
- Thickbox receipt pop up for main tab.
- Cron update script to turn off and email late owners
- Cron script to email owners before and after next payment is due.
- Cron script to backup the db nightly
- Export script to backup db
- Log viewer and log table for cron script changes...
- Notify on lack of email addresses...

Higher Level Specifics
- User level definitions
Expand Down
68 changes: 42 additions & 26 deletions cron/reminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
session_start();
require_once('../includes/config.php');
require_once('../includes/functions.php');
$baseDir = (substr(__DIR__, -1) == '/' ? substr(__DIR__, 0, -1) : __DIR__);
$baseDir = substr(__DIR__, 0, strrpos($baseDir, '/'));

require_once($baseDir . '/includes/config.php');
require_once($baseDir . '/includes/functions.php');
require_once('Mail.php');

$from = sprintf('%s <%s>', $_SESSION['reminderFrom'], $_SESSION['reminderEmail']);
Expand All @@ -30,10 +33,9 @@
$pass = $_SESSION['smtpPass'];

$to = ' <mlitteken@gmail.com>';
$subject = 'reminder message';

$search = array('[firstName]', '[lastName]', '[dueDate]', '[balance]', '[paymentPlan]');

$count = 0;

// First inactives...owners who will be made inactive...
$inactiveQ = sprintf(
Expand All @@ -50,14 +52,25 @@
$inactiveR = mysqli_query($DBS['comet'], $inactiveQ);

$inactiveMsg = $_SESSION['inactiveMsg'];
$inactiveSubject = $_SESSION['inactiveSubject'];

if (!$inactiveR)
printf('Error: %s, Query: %s', mysqli_error($DBS['comet']), $inactiveQ);

while (list($email, $first, $last, $sPrice, $planAmount, $paid, $nextDue, $daysLate) = mysqli_fetch_row($inactiveR)) {
$replace = array($first, $last, $nextDue, '$' . number_format($sPrice-$paid, 2), '$' . $planAmount);
$newTo = $first . ' ' . $last . $to;
$body = str_replace($search, $replace, $inactiveMsg);
echo $body . "\n";

$return = cometMail($newTo, $from, $inactiveSubject, $body, $type = 'reminder');

if ($return == 0) {
$count++;
echo "Successfully sent inactive email #$count\n";
} else {
echo $return;
}
}

// Then coming due...reminder that they should make a payment...
Expand All @@ -71,18 +84,29 @@
WHERE o.memType IN (1,2,3)
AND o.personNum = 1
GROUP BY cardNo
HAVING diff BETWEEN -20 AND -%u', $_SESSION['comingDueDays']);
HAVING diff = -%u', $_SESSION['comingDueDays']);
$comingDueR = mysqli_query($DBS['comet'], $comingDueQ);

$comingDueMsg = $_SESSION['comingDueMsg'];
$comingDueSubject = $_SESSION['comingDueSubject'];

if (!$comingDueR)
printf('Error: %s, Query: %s', mysqli_error($DBS['comet']), $comingDueQ);

while (list($email, $first, $last, $sPrice, $planAmount, $paid, $nextDue, $daysLate) = mysqli_fetch_row($comingDueR)) {
$replace = array($first, $last, $nextDue, '$' . number_format($sPrice-$paid, 2), '$' . $planAmount);
$newTo = $first . ' ' . $last . $to;
$body = str_replace($search, $replace, $comingDueMsg);
echo $body . "\n";

$return = cometMail($newTo, $from, $comingDueSubject, $body, $type = 'reminder');

if ($return == 0) {
$count++;
echo "Successfully sent coming due email #$count\n";
} else {
echo $return;
}
}

// Then past due...reminder that they will be put on hold...
Expand All @@ -96,37 +120,29 @@
WHERE o.memType IN (1,2,3)
AND o.personNum = 1
GROUP BY cardNo
HAVING diff BETWEEN %u AND 20', $_SESSION['pastDueDays']);
HAVING diff = %u', $_SESSION['pastDueDays']);
$pastDueR = mysqli_query($DBS['comet'], $pastDueQ);

$pastDueMsg = $_SESSION['pastDueMsg'];
$pastDueSubject = $_SESSION['pastDueSubject'];

if (!$pastDueR)
printf('Error: %s, Query: %s', mysqli_error($DBS['comet']), $pastDueQ);

while (list($email, $first, $last, $sPrice, $planAmount, $paid, $nextDue, $daysLate) = mysqli_fetch_row($pastDueR)) {
$replace = array($first, $last, $nextDue, '$' . number_format($sPrice-$paid, 2), '$' . $planAmount);
$newTo = $first . ' ' . $last . $to;
$body = str_replace($search, $replace, $pastDueMsg);
echo $body . "\n";

$return = cometMail($newTo, $from, $pastDueSubject, $body, $type = 'reminder');

if ($return == 0) {
$count++;
echo "Successfully sent past due email #$count\n";
} else {
echo $return;
}
}

exit();

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);

$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $user,
'password' => $pass));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}

?>
63 changes: 30 additions & 33 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,42 @@ function escape_data(&$connection, $data) {
}
}

function cometMail($to, $from, $subject, $body) {
require_once('./includes/config.php');
function cometMail($to, $from, $subject, $body, $type = 'system') {
require_once(__DIR__ . '/config.php');
require_once('Mail.php');

global $DBS;

$smtpQ = "SELECT name, value FROM options WHERE name IN ('smtpHost', 'systemUser', 'systemPass')";
$smtpR = mysqli_query($DBS['comet'], $smtpQ);

if (!$smtpR) {
printf('MySQL Error: %s, Query: %s', mysqli_error($DBS['comet']), $smtpQ);
} else {
while (list($name, $value) = mysqli_fetch_row($smtpR)) {
$smtp[$name] = $value;
}

$host = $smtp['smtpHost'];
$user = $smtp['systemUser'];
$pass = $smtp['systemPass'];
$host = $_SESSION['smtpHost'];

if ($type == 'system') {
$user = $_SESSION['systemUser'];
$pass = $_SESSION['systemPass'];
} elseif ($type == 'reminder') {
$user = $_SESSION['smtpUser'];
$pass = $_SESSION['smtpPass'];
}

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);

$smtp = Mail::factory(
'smtp',
array (
'host' => $host,
'auth' => true,
'username' => $user,
'password' => $pass
)
);
$smtp = Mail::factory(
'smtp',
array (
'host' => $host,
'auth' => true,
'username' => $user,
'password' => $pass
)
);

$mail = $smtp->send($to, $headers, $body);
$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo '<blink>' . $mail->getMessage() . '</blink>';
}
if (PEAR::isError($mail) && $type == 'system') {
echo '<blink>' . $mail->getMessage() . '</blink>';
} elseif (PEAR::isError($mail) && $type == 'reminder') {
return $mail->getMessage();
} else {
return 0;
}
}
?>

0 comments on commit eeb67b6

Please sign in to comment.