Ejemplo n.º 1
0
function processNotifications($mid = null)
{
    if ($mid == null) {
        $mid = $_SESSION['mid'];
    }
    if (isset($_SESSION['email'])) {
        $email = $_SESSION['email'];
    } else {
        $query = "SELECT email FROM Mothers where mid={$mid}";
        $row = mysql_fetch_assoc(mysql_query($query));
        $email = $row['email'];
    }
    $query = "SELECT * FROM Notifications WHERE mid = {$mid};";
    $counter = 0;
    $result = mysql_query($query);
    if (!$result) {
        error_log(mysql_error());
    }
    while ($row = mysql_fetch_array($result)) {
        if ($row['status'] != 2 && $row['status'] != 8) {
            $counter = $counter + 1;
        }
        if ($row['status'] == 0) {
            $title = notificationTitle($row['ntype']);
            $body = notificationText($row['ntype']);
            $mail = generateNotMail($title, $email, $body);
            // determine this mother's consultant and generate an email.
            $consultant_query = "SELECT S.email FROM Mothers M LEFT JOIN Mothers_Scientists MS ON MS.mid=M.mid LEFT JOIN Scientists S ON S.sid=MS.sid WHERE M.mid={$mid};";
            $consultant_result = mysql_query($consultant_query);
            if (!$consultant_result) {
                error_log(mysql_error());
            } else {
                if (!mysql_num_rows($consultant_result)) {
                    error_log("Unable to determine consultant for Mother {$email}");
                } else {
                    $title = "Notification issued to {$email}.";
                    if ($row['ntype'] == 1) {
                        $body = "Latching ";
                    } else {
                        if ($row['ntype'] == 2) {
                            $body = "Sleepy ";
                        }
                    }
                    $body = "<h2>Notification issued to mother {$email}</h2><br />" . $body;
                    $consultant_row = mysql_fetch_assoc($consultant_result);
                    $mail = generateNotMail($title, $consultant_row['email'], $body);
                }
            }
        }
    }
    $_SESSION['num_not'] = $counter;
    $query = "UPDATE Notifications SET status = 1 WHERE status = 0 AND mid = {$mid};";
    $result = mysql_query($query);
}
Ejemplo n.º 2
0
            error_log(mysql_error());
        } else {
            if (!mysql_num_rows($consultant_result)) {
                error_log('Unable to determine consultant for Mother ' . $_SESSION['email']);
            } else {
                $title = "Notification issued to " . $_SESSION['email'] . " .";
                if ($row['ntype'] == 1) {
                    $body = "Latching ";
                } else {
                    if ($row['ntype'] == 2) {
                        $body = "Sleepy ";
                    }
                }
                $body = "<h2>Notification issued to mother " . $_SESSION['email'] . "</h2><br />" . $body;
                $consultant_row = mysql_fetch_assoc($consultant_result);
                $mail = generateNotMail($title, $consultant_row['email'], $body);
            }
        }
    }
}
?>
<body>
<div data-role='page'>
<?php 
include 'header.php';
?>
<div data-role='content'>
<h1><?php 
echo _("View Diary");
?>
</h1>