Site Id intermittent error. (#4492)
[openemr.git] / library / ajax / dated_reminders_counter.php
blob08a524c4973029f22e3844ee5f616fd9bd77b210
1 <?php
3 /**
4 * Returns a count of due messages for current user.
5 * In 2021, added the timeout mechanism to this script.
7 * @package OpenEMR
8 * @link https://www.open-emr.org
9 * @author Craig Bezuidenhout <https://www.tajemo.co.za/>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @author Jerry Padgett <sjpadgett@gmail.com>
12 * @copyright Copyright (c) 2012 tajemo.co.za <https://www.tajemo.co.za/>
13 * @copyright Copyright (c) 2018-2021 Brady Miller <brady.g.miller@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once(__DIR__ . "/../../interface/globals.php");
18 require_once("$srcdir/dated_reminder_functions.php");
19 require_once("$srcdir/pnotes.inc");
21 use OpenEMR\Common\Csrf\CsrfUtils;
22 use OpenEMR\Common\Session\SessionTracker;
24 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
25 CsrfUtils::csrfNotVerified();
28 // ensure timeout has not happened
29 if (SessionTracker::isSessionExpired()) {
30 echo json_encode(['timeoutMessage' => 'timeout']);
31 exit;
33 // keep this below above time out check.
34 OpenEMR\Common\Session\SessionUtil::setSession('keepAliveTime', time());
36 $portal_count = array();
37 // if portal is enabled get various alerts
38 if (!empty($_POST['isPortal'])) {
39 $portal_count = GetPortalAlertCounts();
42 //Collect number of due reminders
43 $dueReminders = GetDueReminderCount(5, strtotime(date('Y/m/d')));
45 //Collect number of active messages
46 $activeMessages = getPnotesByUser("1", "no", $_SESSION['authUser'], true);
48 $totalNumber = $dueReminders + $activeMessages;
49 $portal_count['reminderText'] = ($totalNumber > 0 ? '(' . text((int)$totalNumber) . ')' : '');
51 echo json_encode($portal_count);