+/*
+ * find open notifications and send an email to the object's users.
+ */
+
+function mail_notifications ()
+{
+ global $dbms;
+
+ $notifres = $dbms->query("SELECT notificationid, objectid, type_of_issueid FROM notification
+ WHERE statuscode != 'cls'");
+
+ for ($notifrow = 0; $notifrow < pg_numrows($notifres); $notifrow++)
+ {
+ $notification = pg_fetch_object($notifres, $notifrow);
+
+ $issue = pg_fetch_object($dbms->query("SELECT description FROM type_of_issue
+ WHERE type_of_issueid='" . $notification->type_of_issueid . "'"), 0);
+ $object = pg_fetch_object($dbms->query("SELECT objectname FROM object
+ WHERE objectid='" . $notification->objectid ."'"), 0);
+
+ $users = $dbms->query("SELECT username FROM object_user WHERE objectid='" . $notification->objectid . "'");
+
+ for ($userrow = 0; $userrow < pg_numrows($users); $userrow++)
+ {
+ $objusr = pg_fetch_object($users, $userrow);
+ $usr = pg_fetch_object($dbms->query("SELECT email FROM usr
+ WHERE username='" . $objusr->username . "'"), 0);
+
+ $message = "Notification " . $notification->notificationid . ": " . $issue->description;
+ $message .= " for object " . $object->objectname . "\n";
+
+ mail($usr->email, "GnuCoMo Notification", $message);
+ }
+ }
+}
+