1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163:
<?php
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
class NotificationTargetObjectLock extends NotificationTarget {
function getEvents() {
return ['unlock' => __('Unlock Item Request')];
}
function getTags() {
$tags = ['objectlock.action' => _n('Event', 'Events', 1),
'objectlock.name' => __('Item Name'),
'objectlock.id' => __('Item ID'),
'objectlock.type' => __('Item Type'),
'objectlock.date_mod' => __('Lock date'),
'objectlock.lockedby.lastname' => __('Lastname of locking user'),
'objectlock.lockedby.firstname' => __('Firstname of locking user'),
'objectlock.requester.lastname' => __('Requester Lastname'),
'objectlock.requester.firstname' => __('Requester Firstname'),
'objectlock.url' => __('Item URL')];
foreach ($tags as $tag => $label) {
$this->addTagToList(['tag' => $tag,
'label' => $label,
'value' => true]);
}
asort($this->tag_descriptions);
}
function addNotificationTargets($entity) {
$this->addTarget(Notification::USER, __('Locking User'));
}
function addSpecificTargets($data, $options) {
$user = new User();
if ($user->getFromDB($this->obj->fields['users_id'])) {
$this->addToRecipientsList(['language' => $user->getField('language'),
'users_id' => $user->getID()]);
}
}
function addDataForTemplate($event, $options = []) {
global $CFG_GLPI;
$events = $this->getEvents();
$object = getItemForItemtype($options['item']->fields['itemtype']);
$object->getFromDB($options['item']->fields['items_id']);
$user = new User();
$user->getFromDB($options['item']->fields['users_id']);
$this->data['##objectlock.action##'] = $events[$event];
$this->data['##objectlock.name##'] = $object->fields['name'];
$this->data['##objectlock.id##'] = $options['item']->fields['items_id'];
$this->data['##objectlock.type##'] = $options['item']->fields['itemtype'];
$this->data['##objectlock.date_mod##'] = Html::convDateTime($options['item']->fields['date_mod'],
$user->fields['date_format']);
$this->data['##objectlock.lockedby.lastname##']
= $user->fields['realname'];
$this->data['##objectlock.lockedby.firstname##']
= $user->fields['firstname'];
$this->data['##objectlock.requester.lastname##']
= $_SESSION['glpirealname'];
$this->data['##objectlock.requester.firstname##']
= $_SESSION['glpifirstname'];
$this->data['##objectlock.url##'] = $CFG_GLPI['url_base']."/?redirect=".
$options['item']->fields['itemtype']. "_".
$options['item']->fields['items_id'];
$this->getTags();
foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
if (!isset($this->data[$tag])) {
$this->data[$tag] = $values['label'];
}
}
}
function getSender() {
$mails = new UserEmail();
if (isset( $_SESSION['glpiID']) && ($_SESSION['glpiID'] > 0)
&& isset($_SESSION['glpilock_directunlock_notification'])
&& ($_SESSION['glpilock_directunlock_notification'] > 0)
&& $mails->getFromDBByCrit([
'users_id' => $_SESSION['glpiID'],
'is_default' => 1
])) {
$ret = ['email' => $mails->fields['email'],
'name' => formatUserName(0, $_SESSION["glpiname"], $_SESSION["glpirealname"],
$_SESSION["glpifirstname"])];
} else {
$ret = parent::getSender();
}
return $ret;
}
function getReplyTo($options = []) {
return $this->getSender();
}
}