static function updateTargets($input)
{
$type = "";
$action = "";
$target = self::getInstanceByType($input['itemtype']);
if (!isset($input['notifications_id'])) {
return;
}
$targets = getAllDatasFromTable('glpi_notificationtargets', 'notifications_id = ' . $input['notifications_id']);
$actives = array();
if (count($targets)) {
foreach ($targets as $data) {
$actives[$data['type'] . '_' . $data['items_id']] = $data['type'] . '_' . $data['items_id'];
}
}
// Be sure to have items once
$actives = array_unique($actives);
if (isset($input['_targets']) && count($input['_targets'])) {
// Be sure to have items once
$input['_targets'] = array_unique($input['_targets']);
foreach ($input['_targets'] as $val) {
// Add if not set
if (!isset($actives[$val])) {
list($type, $items_id) = explode("_", $val);
$tmp = array();
$tmp['items_id'] = $items_id;
$tmp['type'] = $type;
$tmp['notifications_id'] = $input['notifications_id'];
$target->add($tmp);
}
unset($actives[$val]);
}
}
// Drop others
if (count($actives)) {
foreach ($actives as $val) {
list($type, $items_id) = explode("_", $val);
if ($target->getFromDBForTarget($input['notifications_id'], $type, $items_id)) {
$target->delete(array('id' => $target->getID()));
}
}
}
}