|
|
@@ -184,6 +184,32 @@ function refreshPreview() {
|
|
|
echo json_encode($jsonData);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param $userReminders {'once_a_day' => {$type => $last_exec_time}, 'immediately' => {$type => $last_exec_time}}
|
|
|
+ */
|
|
|
+ public function sendUserReminders($who, $userReminders, $forceMail = null) {
|
|
|
+ DBG::_('DBG_NTF', '>1', "reminders.1", $userReminders, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ // remove duplicates
|
|
|
+ if (!empty($userReminders['once_a_day']) && !empty($userReminders['immediately'])) {
|
|
|
+ foreach ($userReminders['once_a_day'] as $what => $last_exec) {
|
|
|
+ if (array_key_exists($what, $userReminders['immediately'])) {
|
|
|
+ DBG::_('DBG_NTF', '>2', "skip immediately '{$what}' for '{$who}'", $userReminders['immediately'][$what], __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ unset($userReminders['immediately'][$what]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (empty($userReminders['immediately'])) unset($userReminders['immediately']);
|
|
|
+ }
|
|
|
+ DBG::_('DBG_NTF', '>1', "reminders.2", $userReminders, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ foreach ($userReminders as $when => $listWhat) {
|
|
|
+ if (!empty($listWhat)) {
|
|
|
+ $reminders = array_keys($listWhat);
|
|
|
+ echo "<p>Sending to {$who} reminders [" . implode(",", $reminders) . "] at '{$when}'</p>" . "\n";
|
|
|
+ $this->send($who, $listWhat, $when, $forceMail = 'plabudda@biall-net.pl');
|
|
|
+ $this->markAsSent($who, $listWhat, $when);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param $reminders array( )
|
|
|
* @param $when 'once_a_day', 'immediately'
|
|
|
@@ -202,7 +228,7 @@ function refreshPreview() {
|
|
|
$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
|
|
|
if (!preg_match($pattern, $mainMail)) throw new Exception("Adres email ma błędny format");
|
|
|
|
|
|
- $usrReminders = $this->getUserReminders($usrLogin, $reminders);
|
|
|
+ $usrReminders = $this->getUserReminders($usrLogin, $reminders, $when);
|
|
|
if (empty($usrReminders)) {
|
|
|
DBG::_('DBG_NTF', '>0', "Skip usr({$usrLogin}) - no remindres", $usrReminders, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
return;
|
|
|
@@ -295,10 +321,11 @@ function refreshPreview() {
|
|
|
/**
|
|
|
* @param $reminders - array( $notifyType => $lastExecTime )
|
|
|
*/
|
|
|
- public function getUserReminders($usrLogin, $reminders) {
|
|
|
+ public function getUserReminders($usrLogin, $reminders, $when = null) {
|
|
|
$usrReminders = array();
|
|
|
foreach ($reminders as $notifyType => $lastExecTime) {
|
|
|
- $listTodo = $this->getTodoForUserReminder($usrLogin, $notifyType, $lastExecTime);
|
|
|
+ $fetchFromTime = (null == $when || 'once_a_day' == $when)? null : $lastExecTime;
|
|
|
+ $listTodo = $this->getTodoForUserReminder($usrLogin, $notifyType, $fetchFromTime);
|
|
|
if (!empty($listTodo)) $usrReminders[$notifyType] = $listTodo;
|
|
|
}
|
|
|
return $usrReminders;
|
|
|
@@ -835,26 +862,20 @@ function refreshPreview() {
|
|
|
$sqlWhenFltr = array();
|
|
|
if (in_array('once_a_day', $whenTypes)) {
|
|
|
$sqlWhenFltr[] = "
|
|
|
- n.`when` = 'once_a_day' and (
|
|
|
- n.last_exec_time is null
|
|
|
- or DATE(n.last_exec_time) < CURDATE()
|
|
|
+ (
|
|
|
+ n.`when` = 'once_a_day' and (
|
|
|
+ n.last_exec_time is null
|
|
|
+ or DATE(n.last_exec_time) < CURDATE()
|
|
|
+ )
|
|
|
)
|
|
|
";
|
|
|
}
|
|
|
if (in_array('immediately', $whenTypes)) {
|
|
|
- $sqlWhenFltr[] = "
|
|
|
- n.`when` = 'immediately'
|
|
|
- ";
|
|
|
+ $sqlWhenFltr[] = "( n.`when` = 'immediately' )";
|
|
|
}
|
|
|
if (empty($sqlWhenFltr)) throw new Exception("when types not allowed in getTodoList");
|
|
|
|
|
|
- $sqlWhenFltr = "
|
|
|
- (
|
|
|
- (
|
|
|
- " . implode(") or (", $sqlWhenFltr) . "
|
|
|
- )
|
|
|
- )
|
|
|
- ";
|
|
|
+ $sqlWhenFltr = "( " . implode(" or ", $sqlWhenFltr) . " )";
|
|
|
}
|
|
|
$sth = $pdo->prepare("
|
|
|
select u.ADM_ACCOUNT
|
|
|
@@ -898,7 +919,7 @@ function refreshPreview() {
|
|
|
//$timeTomorrow = mktime(0, 0, 0, date('n'), date('j') + 1, date('Y'));
|
|
|
DBG::_('DBG_NTF', '>1', "rawReminders (today:{$timeToday})", $rawReminders, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
foreach ($rawReminders as $row) {
|
|
|
- $user = $row['who'];
|
|
|
+ $who = $row['who'];
|
|
|
$when = $row['when'];
|
|
|
$what = $row['what'];
|
|
|
$last_exec_time = $row['last_exec_time'];
|
|
|
@@ -917,23 +938,11 @@ function refreshPreview() {
|
|
|
continue;
|
|
|
}
|
|
|
$last_date = ($last_exec_time)? date("Y-m-d H:i:s", $last_exec_time) : null;
|
|
|
- if (!isset($reminders[$user])) $reminders[$user] = array();
|
|
|
- if (!isset($reminders[$user][$when])) $reminders[$user][$when] = array();
|
|
|
- $reminders[$user][$when][$what] = $last_date;
|
|
|
+ if (!isset($reminders[$who])) $reminders[$who] = array();
|
|
|
+ if (!isset($reminders[$who][$when])) $reminders[$who][$when] = array();
|
|
|
+ $reminders[$who][$when][$what] = $last_date;
|
|
|
if ('immediately' == $when && null !== $last_exec_time_fix_for_immediately && $last_exec_time_fix_for_immediately > $last_exec_time) {
|
|
|
- $reminders[$user][$when][$what] = date("Y-m-d H:i:s", $last_exec_time_fix_for_immediately);
|
|
|
- }
|
|
|
- }
|
|
|
- // remove duplicates
|
|
|
- foreach ($reminders as $user => $listWhen) {
|
|
|
- if (!empty($listWhen['once_a_day']) && !empty($listWhen['immediately'])) {
|
|
|
- foreach ($listWhen['once_a_day'] as $what => $last_exec) {
|
|
|
- if (array_key_exists($what, $listWhen['immediately'])) {
|
|
|
- DBG::_('DBG_NTF', '>2', "skip immediately '{$what}'", $listWhen['immediately'][$what], __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- unset($reminders[$user]['immediately'][$what]);
|
|
|
- }
|
|
|
- }
|
|
|
- if (empty($reminders[$user]['immediately'])) unset($reminders[$user]['immediately']);
|
|
|
+ $reminders[$who][$when][$what] = date("Y-m-d H:i:s", $last_exec_time_fix_for_immediately);
|
|
|
}
|
|
|
}
|
|
|
return $reminders;
|