From 3ef5cba67bf474c6c9a41ea5640090f67d200a3c Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Thu, 28 Jan 2010 10:02:14 +0000 Subject: [PATCH] - bugfixing function getNextCronjobs() - fixed database-field-names in customer_autoresponder.php - added date-pattern in autoresponder_add and _delete templates - corrected $cronlog->logAction()-calls in cron_autoresponder.php - corrected time-cycle-check in cron_autoresponder.php --- customer_autoresponder.php | 24 +++++++++---------- .../froxlor/function.getNextCronjobs.php | 4 ++-- scripts/jobs/cron_autoresponder.php | 20 ++++++++++++---- .../customer/email/autoresponder_add.tpl | 4 ++-- .../customer/email/autoresponder_edit.tpl | 4 ++-- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/customer_autoresponder.php b/customer_autoresponder.php index 140235f6..b2c893e3 100644 --- a/customer_autoresponder.php +++ b/customer_autoresponder.php @@ -34,7 +34,7 @@ if($action == "add") $message = trim($_POST['message']); $date_from_off = isset($_POST['date_from_off']) ? -1 : 0; - $date_until_off = isset($_POST['date_from_off']) ? -1 : 0; + $date_until_off = isset($_POST['date_until_off']) ? -1 : 0; /* * @TODO validate date (DD-MM-YYYY) @@ -82,8 +82,8 @@ if($action == "add") SET `email` = '" . $db->escape($account) . "', `message` = '" . $db->escape($message) . "', `enabled` = '" . (int)$_POST['active'] . "', - `ts_from` = '" . (int)$ts_from . "', - `ts_until` = '" . (int)$ts_until . "', + `date_from` = '" . (int)$ts_from . "', + `date_until` = '" . (int)$ts_until . "', `subject` = '" . $db->escape($subject) . "', `customerid` = '" . $db->escape((int)$userinfo['customerid']) . "' "); @@ -126,7 +126,7 @@ if($action == "edit") $message = trim($_POST['message']); $date_from_off = isset($_POST['date_from_off']) ? -1 : 0; - $date_until_off = isset($_POST['date_from_off']) ? -1 : 0; + $date_until_off = isset($_POST['date_until_off']) ? -1 : 0; /* * @TODO validate date (DD-MM-YYYY) @@ -181,8 +181,8 @@ if($action == "edit") $db->query("UPDATE `" . TABLE_MAIL_AUTORESPONDER . "` SET `message` = '" . $db->escape($message) . "', `enabled` = '" . (int)$ResponderActive . "', - `ts_from` = '" . (int)$ts_from . "', - `ts_until` = '" . (int)$ts_until . "', + `date_from` = '" . (int)$ts_from . "', + `date_until` = '" . (int)$ts_until . "', `subject` = '" . $db->escape($subject) . "' WHERE `email` = '" . $db->escape($account) . "' AND `customerid` = '" . $db->escape((int)$userinfo['customerid']) . "' @@ -281,21 +281,21 @@ else while($row = $db->fetch_array($result)) { - if($result['date_from'] == -1 && $result['date_until'] == -1) + if($row['date_from'] == -1 && $row['date_until'] == -1) { $activated_date = $lng['panel']['not_activated']; } - elseif($result['date_from'] == -1 && $result['date_until'] != -1) + elseif($row['date_from'] == -1 && $row['date_until'] != -1) { - $activated_date = $lng['autoresponder']['date_until'].': '.date('d-m-Y', $result['date_until']); + $activated_date = $lng['autoresponder']['date_until'].': '.date('d-m-Y', $row['date_until']); } - elseif($result['date_from'] != -1 && $result['date_until'] == -1) + elseif($row['date_from'] != -1 && $row['date_until'] == -1) { - $activated_date = $lng['autoresponder']['date_from'].': '.date('d-m-Y', $result['date_from']); + $activated_date = $lng['autoresponder']['date_from'].': '.date('d-m-Y', $row['date_from']); } else { - $activated_date = $date('d-m-Y', $result['date_from']) . ' - ' . date('d-m-Y', $result['date_until']); + $activated_date = date('d-m-Y', $row['date_from']) . ' - ' . date('d-m-Y', $row['date_until']); } eval("\$autoresponder.=\"" . getTemplate("email/autoresponder_autoresponder") . "\";"); } diff --git a/lib/functions/froxlor/function.getNextCronjobs.php b/lib/functions/froxlor/function.getNextCronjobs.php index 1da68b8a..18a8ee9e 100644 --- a/lib/functions/froxlor/function.getNextCronjobs.php +++ b/lib/functions/froxlor/function.getNextCronjobs.php @@ -36,9 +36,9 @@ function getNextCronjobs() if($name == '0') continue; if($x == 0) { - $query.= 'DATE_ADD(FROM_UNIXTIME(`lastrun`), INTERVAL '.$ival.') <= UTC_TIMESTAMP()'; + $query.= 'UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(`lastrun`), INTERVAL '.$ival.')) <= UNIX_TIMESTAMP()'; } else { - $query.= ' OR DATE_ADD(UNIX_TIMESTAMP(`lastrun`), INTERVAL '.$ival.') <= UTC_TIMESTAMP()'; + $query.= ' OR UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(`lastrun`), INTERVAL '.$ival.')) <= UNIX_TIMESTAMP()'; } $x++; } diff --git a/scripts/jobs/cron_autoresponder.php b/scripts/jobs/cron_autoresponder.php index 81cf3d37..47dccc44 100644 --- a/scripts/jobs/cron_autoresponder.php +++ b/scripts/jobs/cron_autoresponder.php @@ -79,13 +79,25 @@ if($db->num_rows($result) > 0) if($ts_end != -1 && $ts_end < $ts_now) continue; $path = $row['homedir'] . $row['maildir'] . "new/"; + + if(!is_dir($paht) || !is_readable($path)) + { + $cronlog->logAction(CRON_ACTION, LOG_WARNING, "Error accessing maildir: " . $path); + continue; + } + $files = scandir($path); foreach($files as $entry) { if($entry == '.' || $entry == '..')continue; - if(time() - filemtime($path . $entry) - $cycle <= 0) + /* + * is the time passed between now and + * the time we received the mail lower/equal + * than our cycle-seconds? + */ + if(time() - filemtime($path . $entry) <= $cycle) { $content = file($path . $entry); @@ -93,7 +105,7 @@ if($db->num_rows($result) > 0) if(count($content) == 0) { - $cronlog->logAction(LOG_ERROR, LOG_WARNING, "Unable to read mail from maildir: " . $entry); + $cronlog->logAction(CRON_ACTION, LOG_WARNING, "Unable to read mail from maildir: " . $entry); continue; } @@ -174,7 +186,7 @@ if($db->num_rows($result) > 0) if($to == '' || $from == '') { - $cronlog->logAction(LOG_ERROR, LOG_WARNING, "No valid headers found in mail to parse: " . $entry); + $cronlog->logAction(CRON_ACTION, LOG_WARNING, "No valid headers found in mail to parse: " . $entry); continue; } @@ -219,7 +231,7 @@ if($db->num_rows($result) > 0) $mailerr_msg = $from; } - $cronlog->logAction(LOG_ERROR, LOG_WARNING, "Error sending autoresponder mail: " . $mailerr_msg); + $cronlog->logAction(CRON_ACTION, LOG_WARNING, "Error sending autoresponder mail: " . $mailerr_msg); } $mail->ClearAddresses(); diff --git a/templates/customer/email/autoresponder_add.tpl b/templates/customer/email/autoresponder_add.tpl index d74ccad5..d3df8fae 100644 --- a/templates/customer/email/autoresponder_add.tpl +++ b/templates/customer/email/autoresponder_add.tpl @@ -15,11 +15,11 @@ $header - {$lng['autoresponder']['date_from']}: + {$lng['autoresponder']['date_from']} (dd-mm-yyyy):  {$date_from_off} - {$lng['autoresponder']['date_until']}: + {$lng['autoresponder']['date_until']} (dd-mm-yyyy):  {$date_until_off} diff --git a/templates/customer/email/autoresponder_edit.tpl b/templates/customer/email/autoresponder_edit.tpl index d7938bba..5e6ffe2a 100644 --- a/templates/customer/email/autoresponder_edit.tpl +++ b/templates/customer/email/autoresponder_edit.tpl @@ -16,11 +16,11 @@ $header - {$lng['autoresponder']['date_from']}: + {$lng['autoresponder']['date_from']} (dd-mm-yyyy):  {$date_from_off} - {$lng['autoresponder']['date_until']}: + {$lng['autoresponder']['date_until']} (dd-mm-yyyy):  {$date_until_off}