. */ /** * @brief Contains the docservers_controler Object * (herits of the BaseObject class) * * @file * @author Loïc Vinet - Maarch * @date $date$ * @version $Revision$ * @ingroup core */ //Loads the required class try { require_once 'modules/notifications/class/events.php'; require_once 'modules/notifications/notifications_tables_definition.php'; require_once 'core/class/ObjectControlerAbstract.php'; } catch (Exception $e) { echo $e->getMessage() . ' // '; } /** * Class for controling docservers objects from database */ class events_controler extends ObjectControler { public function getEventsByNotificationSid($notification_sid) { $query = "SELECT * FROM " . _NOTIF_EVENT_STACK_TABLE_NAME . " WHERE exec_date is NULL " . " AND notification_sid = " . $notification_sid ; $dbConn = new dbquery(); $dbConn->connect(); $dbConn->query($query); $events = array(); while ($eventRecordset = $dbConn->fetch_object()) { $events[] = $eventRecordset; } return $events; } function wildcard_match($pattern, $str) { $pattern = '/^' . str_replace(array('%', '\*', '\?', '\[', '\]'), array('.*', '.*', '.', '[', ']+'), preg_quote($pattern)) . '$/is'; $result = preg_match($pattern, $str); return $result; } public function fill_event_stack($event_id, $table_name, $record_id, $user, $info) { if ($record_id == '') return; $query = "SELECT * " ."FROM " . _NOTIFICATIONS_TABLE_NAME ." WHERE is_enabled = 'Y'"; $dbConn = new dbquery(); $dbConn->connect(); $dbConn->query($query); if($dbConn->nb_result() === 0) { return; } while($notification = $dbConn->fetch_object()) { $event_ids = explode(',' , $notification->event_id); if($event_id == $notification->event_id || $this->wildcard_match($notification->event_id, $event_id) || in_array($event_id, $event_ids)) { $notifications[] = $notification; } } if (count($notifications) == 0) return; foreach ($notifications as $notification) { $dbConn->query( "INSERT INTO " ._NOTIF_EVENT_STACK_TABLE_NAME." (" ."notification_sid, " ."table_name, " ."record_id, " ."user_id, " ."event_info, " ."event_date" .") " ."VALUES(" .$notification->notification_sid.", " ."'".$table_name."', " ."'".$record_id."', " ."'".$user."', " ."'".$info."', " .$dbConn->current_datetime() .")", false, true ); } } public function commitEvent($eventId, $result) { $dbConn = new dbquery(); $dbConn->connect(); $query = "UPDATE " . _NOTIF_EVENT_STACK_TABLE_NAME . " SET exec_date = ".$dbConn->current_datetime().", exec_result = '".$result."'" . " WHERE event_stack_sid = ".$eventId; $dbConn->query($query); } }