function get_row_for_nofalseforb($row, $sql) { $res_events = DBSelect($sql, 1); if (!($e_row = DBfetch($res_events))) { return false; } else { $row = array_merge($row, $e_row); } if ($row['value'] != TRIGGER_VALUE_TRUE && !event_initial_time($row)) { if (!($eventid = first_initial_eventid($row, 0))) { return false; } $sql = 'SELECT e.eventid, e.value' . ' FROM events e ' . ' WHERE e.eventid=' . $eventid . ' AND e.acknowledged=0'; $res_events = DBSelect($sql, 1); if (!($e_row = DBfetch($res_events))) { return false; } else { $row = array_merge($row, $e_row); } } return $row; }
function first_initial_eventid($row, $show_unknown = 0) { $events = get_latest_events($row, $show_unknown); $sql_cond = $show_unknown == 0 ? ' AND e.value<>2 ' : ''; if (empty($events)) { $sql = 'SELECT e.eventid ' . ' FROM events e ' . ' WHERE e.objectid=' . $row['triggerid'] . $sql_cond . ' AND e.object=' . EVENT_OBJECT_TRIGGER . ' ORDER BY e.object, e.objectid, e.eventid'; $res = DBselect($sql, 1); if ($rows = DBfetch($res)) { return $rows['eventid']; } } else { if (!empty($events) && $events[0]['value'] != $row['value']) { $eventid = $events[0]['eventid']; $sql = 'SELECT e.eventid ' . ' FROM events e ' . ' WHERE e.eventid > ' . $eventid . ' AND e.objectid=' . $row['triggerid'] . $sql_cond . ' AND e.object=' . EVENT_OBJECT_TRIGGER . ' ORDER BY e.object, e.objectid, e.eventid'; $res = DBselect($sql, 1); if ($rows = DBfetch($res)) { return $rows['eventid']; } $row['eventid'] = $eventid; $row['value'] = $events[0]['value']; return first_initial_eventid($row, $show_unknown = 0); // recursion!!! } else { if (!empty($events) && $events[0]['value'] == $row['value']) { $eventid = count($events) > 1 ? $events[1]['eventid'] : 0; $sql = 'SELECT e.eventid,e.clock ' . ' FROM events e ' . ' WHERE e.eventid > ' . $eventid . ' AND e.objectid=' . $row['triggerid'] . ' AND e.object=' . EVENT_OBJECT_TRIGGER . ' AND e.value=' . $row['value'] . ' ORDER BY e.object, e.objectid, e.eventid'; $res = DBselect($sql, 1); $rows = DBfetch($res); return $rows['eventid']; } } } return false; }