function run_notify($userid) { $notification_number = 0; // Will be used to display number of notifications in an email $notification_message = ""; // Variable holds body of email $result = db_query("SELECT * FROM notify WHERE `userid` = '{$userid}'"); // Get user notification list while ($row = db_fetch_array($result)) { $feedid = $row['feedid']; $feed = get_feed($feedid); // Get all feed details from feed model function if (time() - strtotime($feed[3]) < 60 * 1) { $active = 1; } else { $active = 0; } // Check if feed is active // if feed becomes active again then the notification status needs to be reset to unsent if ($active && $row['oninactive_sent']) { db_query("UPDATE notify SET oninactive_sent = 0 WHERE feedid='{$feedid}'"); } // if feed is not the onvalue value then notification status needs to be reset to unsent if ($feed[4] != $row['onvalue'] && $row['onvalue_sent']) { db_query("UPDATE notify SET onvalue_sent = 0 WHERE feedid='{$feedid}'"); } if (!$row['onvalue_sent'] && $row['onvalue'] && $feed[4] == $row['onvalue']) { $notification_message .= "<p>" . _("Feed ") . $feed[1] . _(" is") . " == " . $row['onvalue'] . "</p>"; $notification_number++; db_query("UPDATE notify SET onvalue_sent = 1 WHERE feedid='{$feedid}'"); } if (!$row['oninactive_sent'] && $row['oninactive'] && !$active) { $notification_message .= "<p>" . _("Feed ") . $feed[1] . _(" is inactive") . "</p>"; $notification_number++; db_query("UPDATE notify SET oninactive_sent = 1 WHERE feedid='{$feedid}'"); } } $to = get_notify_recipients($userid); $subject = $notification_number . "x emoncms events"; $body = $notification_message; if ($notification_number > 0) { send_mail($to, $subject, $body); } return $notification_message; }
function notify_controller() { require "Models/notify_model.php"; require "Models/feed_model.php"; require "Models/mail_model.php"; global $session, $action, $format; $userid = $session['userid']; // notify/set?feedid=1&onvalue=300&oninactive=1&periodic=1 if ($action == 'set' && $session['write']) { $feedid = intval($_GET['feedid']); $onvalue = floatval($_GET['onvalue']); $oninactive = intval($_GET['oninactive']); $periodic = intval($_GET['periodic']); $output['content'] = set_notify($userid, $feedid, $onvalue, $oninactive, $periodic); if ($format == 'html') { header("Location: ../notify/view?id=" . $feedid); } } elseif ($action == 'view' && $session['write']) { $feedid = intval($_GET['id']); $notify = get_notify($userid, $feedid); //if ($format == 'json') $output = json_encode($feeds); if ($format == 'html') { $output['content'] = view("notify_view.php", array('feedid' => $feedid, 'notify' => $notify)); } } elseif ($action == 'setrecipients' && $session['write']) { $recipients = preg_replace('/[^\\w\\s-.,@]/', '', $_GET["recipients"]); set_notify_recipients($userid, $recipients); $recipients = get_notify_recipients($userid); if ($format == 'html') { $output['content'] = view("notify_settings_view.php", array('recipients' => $recipients)); } } elseif ($action == 'settings' && $session['write']) { $recipients = get_notify_recipients($userid); if ($format == 'html') { $output['content'] = view("notify_settings_view.php", array('recipients' => $recipients)); } } return $output; }