/** * Display notification registered for a group * * @since version 0.83 * * @param $group Group object * * @return nothing **/ static function showForGroup(Group $group) { global $DB; if (!Notification::canView()) { return false; } $sql = "SELECT `glpi_notifications`.`id`\n FROM `glpi_notificationtargets`\n INNER JOIN `glpi_notifications`\n ON (`glpi_notifications`.`id` = `glpi_notificationtargets`.`notifications_id`)\n WHERE `items_id` = '" . $group->getID() . "'\n AND (`type` = '" . Notification::SUPERVISOR_GROUP_TYPE . "'\n OR `type` = '" . Notification::GROUP_TYPE . "') " . getEntitiesRestrictRequest('AND', 'glpi_notifications', '', '', true); $req = $DB->request($sql); echo "<table class='tab_cadre_fixe'>"; if ($req->numrows()) { echo "<tr><th>" . __('Name') . "</th>"; echo "<th>" . Entity::getTypeName(1) . "</th>"; echo "<th>" . __('Active') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Notification method') . "</th>"; echo "<th>" . NotificationEvent::getTypeName(1) . "</th>"; echo "<th>" . NotificationTemplate::getTypeName(1) . "</th></tr>"; $notif = new Notification(); Session::initNavigateListItems('Notification', sprintf(__('%1$s = %2$s'), Group::getTypeName(1), $group->getName())); foreach ($req as $data) { Session::addToNavigateListItems('Notification', $data['id']); if ($notif->getFromDB($data['id'])) { echo "<tr class='tab_bg_2'><td>" . $notif->getLink(); echo "</td><td>" . Dropdown::getDropdownName('glpi_entities', $notif->getEntityID()); echo "</td><td>" . Dropdown::getYesNo($notif->getField('is_active')) . "</td><td>"; $itemtype = $notif->getField('itemtype'); if ($tmp = getItemForItemtype($itemtype)) { echo $tmp->getTypeName(1); } else { echo " "; } echo "</td><td>" . Notification::getMode($notif->getField('mode')); echo "</td><td>" . NotificationEvent::getEventName($itemtype, $notif->getField('event')); echo "</td>" . "<td>" . Dropdown::getDropdownName('glpi_notificationtemplates', $notif->getField('notificationtemplates_id')); echo "</td></tr>"; } } } else { echo "<tr class='tab_bg_2'><td class='b center'>" . __('No item found') . "</td></tr>"; } echo "</table>"; }
/** * Display debug information for current object * NotificationTemplateTranslation => translation preview * * @since version 0.84 **/ function showDebug() { $template = new NotificationTemplate(); if (!$template->getFromDB($this->fields['notificationtemplates_id'])) { return; } $itemtype = $template->getField('itemtype'); if (!($item = getItemForItemtype($itemtype))) { return; } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>" . __('Preview') . "</th></tr>"; $oktypes = array('CartridgeItem', 'Change', 'ConsumableItem', 'Contract', 'Crontask', 'Problem', 'Project', 'Ticket', 'User'); if (!in_array($itemtype, $oktypes)) { // this itemtype doesn't work, need to be fixed echo "<tr class='tab_bg_2 center'><td>" . NOT_AVAILABLE . "</td>"; echo "</table></div>"; return; } // Criteria Form $key = getForeignKeyFieldForItemType($item->getType()); $id = Session::getSavedOption(__CLASS__, $key, 0); $event = Session::getSavedOption(__CLASS__, $key . '_event', ''); echo "<tr class='tab_bg_2'><td>" . $item->getTypeName(1) . " "; $item->dropdown(array('value' => $id, 'on_change' => 'reloadTab("' . $key . '="+this.value)')); echo "</td><td>" . NotificationEvent::getTypeName(1) . " "; NotificationEvent::dropdownEvents($item->getType(), array('value' => $event, 'on_change' => 'reloadTab("' . $key . '_event="+this.value)')); echo "</td>"; // Preview if ($event && $item->getFromDB($id)) { $options = array('_debug' => true); // TODO Awfull Hack waiting for https://forge.indepnet.net/issues/3439 $multi = array('alert', 'alertnotclosed', 'end', 'notice', 'periodicity', 'periodicitynotice'); if (in_array($event, $multi)) { // Won't work for Cardridge and Consumable $options['entities_id'] = $item->getEntityID(); $options['items'] = array($item->getID() => $item->fields); } $target = NotificationTarget::getInstance($item, $event, $options); $infos = array('language' => $_SESSION['glpilanguage'], 'additionnaloption' => array('usertype' => NotificationTarget::GLPI_USER)); $template->resetComputedTemplates(); $template->setSignature(Notification::getMailingSignature($_SESSION['glpiactive_entity'])); if ($tid = $template->getTemplateByLanguage($target, $infos, $event, $options)) { $data = $template->templates_by_languages[$tid]; echo "<tr><th colspan='2'>" . __('Subject') . "</th></tr>"; echo "<tr class='tab_bg_2 b'><td colspan='2'>" . $data['subject'] . "</td></tr>"; echo "<tr><th>" . __('Email text body') . "</th>"; echo "<th>" . __('Email HTML body') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>" . nl2br($data['content_text']) . "</td>"; echo "<td>" . $data['content_html'] . "</td></tr>"; } } echo "</table></div>"; }
function showForm($ID, $options = array()) { global $CFG_GLPI; $this->initForm($ID, $options); $this->showFormHeader($options); echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>"; echo "<td>"; Html::autocompletionTextField($this, "name"); echo "</td>"; echo "<td rowspan='6' class='middle right'>" . __('Comments') . "</td>"; echo "<td class='center middle' rowspan='6'><textarea cols='45' rows='9' class='form-control' name='comment' >" . $this->fields["comment"] . "</textarea></td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Active') . "</td>"; echo "<td>"; Dropdown::showYesNo('is_active', $this->fields['is_active']); echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Type') . "</td>"; echo "<td>"; if (!Session::haveRight(static::$rightname, UPDATE)) { $itemtype = $this->fields['itemtype']; echo $itemtype::getTypeName(1); $rand = ''; } else { if (Config::canUpdate() && $this->getEntityID() == 0) { $rand = Dropdown::showItemTypes('itemtype', $CFG_GLPI["notificationtemplates_types"], array('value' => $this->fields['itemtype'])); } else { $rand = Dropdown::showItemTypes('itemtype', array_diff($CFG_GLPI["notificationtemplates_types"], array('Crontask', 'DBConnection', 'User')), array('value' => $this->fields['itemtype'])); } } $params = array('itemtype' => '__VALUE__'); Ajax::updateItemOnSelectEvent("dropdown_itemtype{$rand}", "show_events", $CFG_GLPI["root_doc"] . "/ajax/dropdownNotificationEvent.php", $params); Ajax::updateItemOnSelectEvent("dropdown_itemtype{$rand}", "show_templates", $CFG_GLPI["root_doc"] . "/ajax/dropdownNotificationTemplate.php", $params); echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Notification method') . "</td>"; echo "<td>"; self::dropdownMode(array('value' => $this->fields['mode'])); echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . NotificationEvent::getTypeName(1) . "</td>"; echo "<td><span id='show_events'>"; NotificationEvent::dropdownEvents($this->fields['itemtype'], array('value' => $this->fields['event'])); echo "</span></td></tr>"; echo "<tr class='tab_bg_1'><td>" . NotificationTemplate::getTypeName(1) . "</td>"; echo "<td><span id='show_templates'>"; NotificationTemplate::dropdownTemplates('notificationtemplates_id', $this->fields['itemtype'], $this->fields['notificationtemplates_id']); echo "</span></td></tr>"; $this->showFormButtons($options); return true; }