public function store() { if ($this->getEventNotificationId() != 0) { try { $stmt = DB::getInstance()->prepare("UPDATE event_notifications SET\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_id = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tupdate_date = NOW(),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\taction = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tobject = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tnotify = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tnotified = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tnotification_date = FROM_UNIXTIME(?)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE id=?"); $stmt->execute(array($this->getUserId(), $this->getAction(), $this->getObject(), $this->getNotify(), $this->getNotified(), $this->getNotificationDate(), $this->getEventNotificationId())); return $stmt->rowCount(); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } } elseif ($this->getUserId() != 0 and $this->getAction() != "") { //check if there already exists an event for the given action, object and user_id $event_notification = new EventNotification(false, $this->getUserId(), $this->getAction(), $this->getObject()); if (!$event_notification->fetch()) { try { $stmt = DB::getInstance()->prepare("INSERT INTO event_notifications (user_id, create_date, update_date, action, object, notify, notified, notification_date)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (?, NOW(), NOW(), ?, ?, ?, ?, ?)"); $stmt->execute(array($this->getUserId(), $this->getAction(), $this->getObject(), $this->getNotify(), $this->getNotified(), $this->getNotificationDate())); return DB::getInstance()->lastInsertId(); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } } } return false; }
public function __construct($user_id = false, $action = false, $object = false, $notify = false, $notified = false, $offset = false, $limit = false, $sort_by = false, $order = false) { $result = array(); if ($offset !== false) { $this->setOffset((int) $offset); } if ($limit !== false) { $this->setLimit((int) $limit); } if ($sort_by !== false) { $this->setSortBy($sort_by); } if ($order !== false) { $this->SetOrder($order); } // initialize $total_count with the total number of objects in the list (over all pages) try { $stmt = DB::getInstance()->prepare("SELECT COUNT(*) as total_count\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM event_notifications\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(user_id = :user_id OR :user_id=0) AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(action = :action OR :action='') AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(object = :object OR :object=0) AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(notify = :notify OR :notify=0) AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(notified = :notified OR :notified=0)"); $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT); $stmt->bindParam(':action', $action, PDO::PARAM_STR); $stmt->bindParam(':object', $object, PDO::PARAM_INT); $stmt->bindParam(':notify', $notify, PDO::PARAM_INT); $stmt->bindParam(':notified', $notified, PDO::PARAM_INT); $stmt->execute(); $total_count = $stmt->fetch(PDO::FETCH_ASSOC); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } $this->setTotalCount((int) $total_count['total_count']); //if limit -1 then get all ressource records if ($this->getLimit() == -1) { $this->setLimit($this->getTotalCount()); } try { $stmt = DB::getInstance()->prepare("SELECT event_notifications.id as event_notification_id, event_notifications.*\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM event_notifications\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(user_id = :user_id OR :user_id=0) AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(action = :action OR :action='') AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(object = :object OR :object=0) AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(notify = :notify OR :notify=0) AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(notified = :notified OR :notified=0)\n\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase :sort_by\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhen 'event_notification_id' then event_notifications.id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse NULL\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\t\t\t\t\t" . $this->getOrder() . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT :offset, :limit"); $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT); $stmt->bindParam(':action', $action, PDO::PARAM_STR); $stmt->bindParam(':object', $object, PDO::PARAM_INT); $stmt->bindParam(':notify', $notify, PDO::PARAM_INT); $stmt->bindParam(':notified', $notified, PDO::PARAM_INT); $stmt->bindParam(':offset', $this->getOffset(), PDO::PARAM_INT); $stmt->bindParam(':limit', $this->getLimit(), PDO::PARAM_INT); $stmt->bindParam(':sort_by', $this->getSortBy(), PDO::PARAM_STR); $stmt->execute(); $resultset = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } foreach ($resultset as $item) { $event_notification = new EventNotification((int) $item['event_notification_id']); $event_notification->fetch(); $this->event_notification_list[] = $event_notification; } }
/** * Poll stdin for Supervisord notifications and dispatch notifications to * the callback function which should accept this object (EventListener) as * its first parameter and an EventNotification as its second. The callback * should return TRUE if it was successful, FALSE on failure, or 'quit' to * break from the event listener loop. * * @param Closure|array Closure callback */ public function listen($callback) { $this->sendReady(); while (true) { if (!($input = trim($this->readLine()))) { continue; } $headers = EventNotification::parseData($input); $payload = fread($this->inputStream, (int) $headers['len']); $notification = new EventNotification($input, $payload, $headers); $result = call_user_func($callback, $this, $notification); if (true === $result) { $this->sendComplete(); } else { if (false === $result) { $this->sendFail(); } else { if ($result == 'quit') { break; } } } $this->sendReady(); } }
/** * Poll stdin for Supervisord notifications and dispatch notifications to * the callback function which should accept this object (EventListener) as * its first parameter and an EventNotification as its second. The callback * should return TRUE if it was successful, FALSE on failure, or 'quit' to * break from the event listener loop. * * @param Closure|array Closure callback */ public function listen($callback) { $this->sendReady(); while (true) { if (!($input = trim($this->readLine()))) { continue; } $headers = EventNotification::parseData($input); // PHP 5.6 doesn't deal gracefully with this causing a buffer overflow $payload = ''; if (isset($headers['len'])) { $payload = fread($this->inputStream, (int) $headers['len']); } $notification = new EventNotification($input, $payload, $headers); $result = call_user_func($callback, $this, $notification); if (true === $result) { $this->sendComplete(); } else { if (false === $result) { $this->sendFail(); } else { if ($result == 'quit') { break; } } } $this->sendReady(); } }
header('Location: ./event_notifications.php'); } else { Permission::denyAccess(PERM_ROOT, $event_notification->getUserId()); } } elseif (empty($_POST)) { if (Permission::checkPermission(PERM_USER)) { $routerlist = new Routerlist(false, false, false, false, false, false, false, false, 0, -1); $routerlist->sort("hostname", "asc"); $smarty->assign('routerlist', $routerlist->getRouterlist()); $event_notification_list = new EventNotificationList($_SESSION['user_id']); $smarty->assign('event_notification_list', $event_notification_list->getEventNotificationList()); $smarty->display("header.tpl.html"); $smarty->display("event_notifications.tpl.html"); $smarty->display("footer.tpl.html"); } else { Permission::denyAccess(PERM_USER); } } else { if (Permission::checkPermission(PERM_USER)) { $event_notification = new EventNotification(false, (int) $_SESSION['user_id'], $_POST['action'], (int) $_POST['object'], true); if ($event_notification->store()) { $message[] = array('Die Benachrichtigung wurde eingetragen.', 1); } else { $message[] = array('Die Benachrichtigung konnte nicht eingetragen werden.', 2); } Message::setMessage($message); header('Location: ./event_notifications.php'); } else { Permission::denyAccess(PERM_USER); } }