grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * NotificationTarget Class * * @since version 0.84 **/ class NotificationTarget extends CommonDBChild { public $prefix = ''; // From CommonDBChild static public $itemtype = 'Notification'; static public $items_id = 'notifications_id'; public $table = 'glpi_notificationtargets'; public $notification_targets = array(); public $notification_targets_labels = array(); public $notificationoptions = 0; // Tags which have data in HTML : do not try to clean them public $html_tags = array(); // Data from the objet which can be used by the template // See https://forge.indepnet.net/projects/5/wiki/NotificationTemplatesTags public $datas = array(); public $tag_descriptions = array(); // From CommonDBTM public $dohistory = true; //Array to store emails by notification public $target = array(); public $entity = ''; //Object which raises the notification event public $obj = null; //Object which is associated with the event public $target_object = array(); // array of event name => event label public $events = array(); public $options = array(); public $raiseevent = ''; const TAG_LANGUAGE = 'lang'; const TAG_VALUE = 'tag'; const TAG_FOR_ALL_EVENTS = 0; const ANONYMOUS_USER = 0; const GLPI_USER = 1; const EXTERNAL_USER = 2; /** * @param $entity (default '') * @param $event (default '') * @param $object (default null) * @param $options array **/ function __construct($entity='', $event='', $object=null, $options=array()) { if ($entity === '') { $this->entity = (isset($_SESSION['glpiactive_entity'])?$_SESSION['glpiactive_entity']:0); } else { $this->entity = $entity; } if ($object) { if ($object instanceof CommonDBTM && isset($object->fields['id'])) { // Reread to avoid slashes issue $object->getFromDB($object->fields['id']); } $this->obj = $object; $this->getObjectItem($event); } $this->raiseevent = $event; $this->options = $options; $this->getNotificationTargets($entity); $this->getAdditionalTargets($event); // add new target by plugin unset($this->data); Plugin::doHook('item_add_targets', $this); asort($this->notification_targets); } /** * Retrieve an item from the database for a specific target * * @param $notifications_id integer notification ID * @param $type type of the target to retrive * @param $ID integer ID of the target to retrieve * * @since version 0.85 * * @return true if succeed else false **/ function getFromDBForTarget($notifications_id, $type, $ID) { if ($this->getFromDBByQuery("WHERE `".$this->getTable()."`.`notifications_id` = '$notifications_id' AND `".$this->getTable()."`.`items_id` = '$ID' AND `".$this->getTable()."`.`type` = '$type'")) { return true; } return false; } // Temporary hack for this class since 0.84 static function getTable() { return 'glpi_notificationtargets'; } /** * Validate send before doing it (may be overloaded : exemple for private tasks or followups) * * @since version 0.84 (new parameter) * * @param $event string notification event * @param $infos array of destination of the notification * @param $notify_me boolean notify me on my action ? * ($infos contains users_id to check if the target is me) * (false by default) * * @return true **/ function validateSendTo($event, array $infos, $notify_me=false) { if (!$notify_me) { if (isset($infos['users_id']) // Check login user and not event launch by crontask && ($infos['users_id'] === Session::getLoginUserID(false))) { return false; } } return true; } /** * @param $event (default '') **/ function getSubjectPrefix($event='') { $perso_tag = trim(Entity::getUsedConfig('notification_subject_tag', $this->getEntity(), '', '')); if (empty($perso_tag)) { $perso_tag = "GLPI"; } return "[$perso_tag] "; } /** * Get header to add to content **/ function getContentHeader() { return ''; } /** * Get footer to add to content **/ function getContentFooter() { return ''; } /** * @since version 0.84 * * @return message id for notification **/ function getMessageID() { return ""; } static function getTypeName($nb=0) { return _n('Recipient', 'Recipients', $nb); } /** * Get a notificationtarget class by giving the object which raises the event * * @see CommonDBTM::getRawName **/ function getRawName() { if (isset($this->notification_targets_labels[$this->getField("type")] [$this->getField("items_id")])) { return $this->notification_targets_labels[$this->getField("type")] [$this->getField("items_id")]; } return ''; } /** * Get a notificationtarget class by giving the object which raises the event * * @param $item the object which raises the event * @param $event the event which will be used (default '') * @param $options array of options * * @return a notificationtarget class or false **/ static function getInstance($item, $event='', $options=array()) { if ($plug = isPluginItemType($item->getType())) { $name = 'Plugin'.$plug['plugin'].'NotificationTarget'.$plug['class']; } else { $name = 'NotificationTarget'.$item->getType(); } $entity = 0; if (class_exists($name)) { //Entity ID exists in the options array if (isset($options['entities_id'])) { $entity = $options['entities_id']; //Item which raises the event contains an entityID } else if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } return new $name($entity, $event, $item, $options); } return false; } /** * Get a notificationtarget class by giving an itemtype * * @param $itemtype the itemtype of the object which raises the event * @param $event the event which will be used (default '') * @param $options array of options * * @return a notificationtarget class or false **/ static function getInstanceByType($itemtype, $event='', $options=array()) { if (($itemtype) && ($item = getItemForItemtype($itemtype))) { return self::getInstance($item, $event, $options); } return false; } /** * @param $notification Notification object **/ function showForNotification(Notification $notification) { global $DB; if (!Notification::canView()) { return false; } if ($notification->getField('itemtype') != '') { $notifications_id = $notification->fields['id']; $canedit = $notification->can($notifications_id, UPDATE); if ($canedit) { echo "