static function postClone(NotificationTemplate $clone, $oldid) { global $DB; $trad = new NotificationTemplateTranslation(); $fkey = getForeignKeyFieldForTable($clone->getTable()); $crit = array($fkey => $oldid); foreach ($DB->request($trad->getTable(), $crit) as $data) { unset($data['id']); $data[$fkey] = $clone->getID(); $trad->add(Toolbox::addslashes_deep($data)); } }
/** * Install mreporting notifications. * * @return array 'success' => true on success */ static function install() { global $LANG, $DB; // Création du template de la notification $template = new NotificationTemplate(); $found_template = $template->find("itemtype = 'PluginMreportingNotification'"); if (count($found_template) == 0) { $template_id = $template->add(array('name' => $LANG['plugin_mreporting']['notification_name'], 'comment' => $LANG['plugin_mreporting']['notification_comment'], 'itemtype' => 'PluginMreportingNotification')); // Ajout d'une traduction (texte) en Français $translation = new NotificationTemplateTranslation(); $translation->add(array('notificationtemplates_id' => $template_id, 'language' => '', 'subject' => $LANG['plugin_mreporting']['notification_subject'], 'content_text' => $LANG['plugin_mreporting']['notification_text'], 'content_html' => $LANG['plugin_mreporting']['notification_html'])); // Création de la notification $notification = new Notification(); $notification_id = $notification->add(array('name' => $LANG['plugin_mreporting']['notification_name'], 'comment' => $LANG['plugin_mreporting']['notification_comment'], 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 1, 'itemtype' => 'PluginMreportingNotification', 'notificationtemplates_id' => $template_id, 'event' => 'sendReporting', 'mode' => 'mail')); } $DB->query('INSERT INTO glpi_notificationtargets (items_id, type, notifications_id) VALUES (1, 1, ' . $notification_id . ');'); return array('success' => true); }
public static function install() { $notifications = array('plugin_formcreator_form_created' => array('name' => __('A form has been created', 'formcreator'), 'subject' => __('Your request have been saved', 'formcreator'), 'content' => __('Hi,\\nYour request from GLPI have been successfully saved with number ##formcreator.request_id## and transmetted to the helpdesk team.\\nYou can see your answers onto the following link:\\n##formcreator.validation_link##', 'formcreator'), 'notified' => self::AUTHOR), 'plugin_formcreator_need_validation' => array('name' => __('A form need to be validate', 'formcreator'), 'subject' => __('A form from GLPI need to be validate', 'formcreator'), 'content' => __('Hi,\\nA form from GLPI need to be validate and you have been choosen as the validator.\\nYou can access it by clicking onto this link:\\n##formcreator.validation_link##', 'formcreator'), 'notified' => self::APPROVER), 'plugin_formcreator_refused' => array('name' => __('The form is refused', 'formcreator'), 'subject' => __('Your form have been refused by the validator', 'formcreator'), 'content' => __('Hi,\\nWe are sorry to inform you that your form have been refused by the validator for the reason below:\\n##formcreator.validation_comment##\\n\\nYou can still modify and resubmit it by clicking onto this link:\\n##formcreator.validation_link##', 'formcreator'), 'notified' => self::AUTHOR), 'plugin_formcreator_accepted' => array('name' => __('The form is accepted', 'formcreator'), 'subject' => __('Your form have been accepted by the validator', 'formcreator'), 'content' => __('Hi,\\nWe are pleased to inform you that your form have been accepted by the validator.\\nYour request will be considered soon.', 'formcreator'), 'notified' => self::AUTHOR), 'plugin_formcreator_deleted' => array('name' => __('The form is deleted', 'formcreator'), 'subject' => __('Your form have been deleted by an administrator', 'formcreator'), 'content' => __('Hi,\\nWe are sorry to inform you that your request cannot be considered and have been deleted by an administrator.', 'formcreator'), 'notified' => self::AUTHOR)); // Create the notification template $notification = new Notification(); $notification_target = new NotificationTarget(); $template = new NotificationTemplate(); $translation = new NotificationTemplateTranslation(); foreach ($notifications as $event => $datas) { // Check if notification allready exists $exists = $notification->find("itemtype = 'PluginFormcreatorFormanswer' AND event = '{$event}'"); // If it doesn't exists, create it if (count($exists) == 0) { $template_id = $template->add(array('name' => addslashes($datas['name']), 'comment' => '', 'itemtype' => 'PluginFormcreatorFormanswer')); // Add a default translation for the template $translation->add(array('notificationtemplates_id' => $template_id, 'language' => '', 'subject' => addslashes($datas['subject']), 'content_text' => addslashes($datas['content']), 'content_html' => '<p>' . str_replace('\\n', '<br />', $datas['content']) . '</p>')); // Create the notification $notification_id = $notification->add(array('name' => addslashes($datas['name']), 'comment' => '', 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 1, 'itemtype' => 'PluginFormcreatorFormanswer', 'notificationtemplates_id' => $template_id, 'event' => $event, 'mode' => 'mail')); // Add default notification targets $notification_target->add(array("items_id" => $datas['notified'], "type" => Notification::USER_TYPE, "notifications_id" => $notification_id)); } } }
You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkCentralAccess(); if (!isset($_GET["id"])) { $_GET["id"] = ""; } $language = new NotificationTemplateTranslation(); if (isset($_POST["add"])) { $language->check(-1, CREATE, $_POST); $newID = $language->add($_POST); Event::log($newID, "notificationtemplatetranslations", 4, "notification", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["language"])); Html::back(); } else { if (isset($_POST["purge"])) { $language->check($_POST["id"], PURGE); $language->delete($_POST, 1); Event::log($_POST["id"], "notificationtemplatetranslations", 4, "notification", sprintf(__('%s purges an item'), $_SESSION["glpiname"])); $language->redirectToList(); } else { if (isset($_POST["update"])) { $language->check($_POST["id"], UPDATE); $language->update($_POST); Event::log($_POST["id"], "notificationtemplatetranslations", 4, "notification", sprintf(__('%s updates an item'), $_SESSION["glpiname"])); Html::back(); } else {
public static function install(Migration $migration) { global $DB; $migration->displayMessage("Migrate PluginOrderOrder notifications"); $template = new NotificationTemplate(); $templates_id = false; $query_id = "SELECT `id`\n FROM `glpi_notificationtemplates`\n WHERE `itemtype`='PluginOrderOrder'\n AND `name` = 'Order Validation'"; $result = $DB->query($query_id) or die($DB->error()); if ($DB->numrows($result) > 0) { $templates_id = $DB->result($result, 0, 'id'); } else { $tmp = array('name' => 'Order Validation', 'itemtype' => 'PluginOrderOrder', 'date_mod' => $_SESSION['glpi_currenttime'], 'comment' => '', 'css' => ''); $templates_id = $template->add($tmp); } if ($templates_id) { $translation = new NotificationTemplateTranslation(); if (!countElementsInTable($translation->getTable(), "`notificationtemplates_id`='{$templates_id}'")) { $tmp['notificationtemplates_id'] = $templates_id; $tmp['language'] = ''; $tmp['subject'] = '##lang.ordervalidation.title##'; $tmp['content_text'] = '##lang.ordervalidation.url## : ##ordervalidation.url## ##lang.ordervalidation.entity## : ##ordervalidation.entity## ##IFordervalidation.name####lang.ordervalidation.name## : ##ordervalidation.name## ##ENDIFordervalidation.name## ##IFordervalidation.numorder####lang.ordervalidation.numorder## : ##ordervalidation.numorder## ##ENDIFordervalidation.numorder## ##IFordervalidation.orderdate####lang.ordervalidation.orderdate## : ##ordervalidation.orderdate####ENDIFordervalidation.orderdate## ##IFordervalidation.state####lang.ordervalidation.state## : ##ordervalidation.state####ENDIFordervalidation.state## ##IFordervalidation.users####lang.ordervalidation.users## : ##ordervalidation.users####ENDIFordervalidation.users## ##IFordervalidation.comment####lang.ordervalidation.comment## : ##ordervalidation.comment####ENDIFordervalidation.comment##'; $tmp['content_html'] = '<p><strong>##lang.ordervalidation.url##</strong> : ' . '<a href=\\"##ordervalidation.url##\\">##ordervalidation.url##</a><br />' . '<br /><strong>##lang.ordervalidation.entity##</strong> : ##ordervalidation.entity##<br />' . ' ##IFordervalidation.name##<strong>##lang.ordervalidation.name##</strong>' . ' : ##ordervalidation.name####ENDIFordervalidation.name##<br />' . '##IFordervalidation.numorder##<strong>##lang.ordervalidation.numorder##</strong>' . ' : ##ordervalidation.numorder####ENDIFordervalidation.numorder##<br />##IFordervalidation.orderdate##<strong>##lang.ordervalidation.orderdate##</strong>' . ' : ##ordervalidation.orderdate####ENDIFordervalidation.orderdate##<br />' . '##IFordervalidation.state##<strong>##lang.ordervalidation.state##</strong>' . ' : ##ordervalidation.state####ENDIFordervalidation.state##<br />' . '##IFordervalidation.users##<strong>##lang.ordervalidation.users##</strong>' . ' : ##ordervalidation.users####ENDIFordervalidation.users##<br /><br />' . '##IFordervalidation.comment##<strong>##lang.ordervalidation.comment##</strong> : ##ordervalidation.comment####ENDIFordervalidation.comment##</p>'; $translation->add($tmp); } $notifs = array('New Order Validation' => 'ask', 'Confirm Order Validation' => 'validation', 'Cancel Order Validation' => 'undovalidation', 'Cancel Order' => 'cancel'); $notification = new Notification(); foreach ($notifs as $label => $name) { if (!countElementsInTable("glpi_notifications", "`itemtype`='PluginOrderOrder' AND `event`='{$name}'")) { $tmp = array('name' => $label, 'entities_id' => 0, 'itemtype' => 'PluginOrderOrder', 'event' => $name, 'mode' => 'mail', 'comment' => '', 'is_recursive' => 1, 'is_active' => 1, 'date_mod' => $_SESSION['glpi_currenttime'], 'notificationtemplates_id' => $templates_id); $notification->add($tmp); } } } $query_id = "SELECT `id`\n FROM `glpi_notificationtemplates`\n WHERE `itemtype`='PluginOrderOrder'\n AND `name` = 'Due date overtaken'"; $result = $DB->query($query_id) or die($DB->error()); if ($DB->numrows($result) > 0) { $templates_id = $DB->result($result, 0, 'id'); } else { $tmp = array('name' => 'Due date overtaken', 'itemtype' => 'PluginOrderOrder', 'date_mod' => $_SESSION['glpi_currenttime'], 'comment' => '', 'css' => ''); $templates_id = $template->add($tmp); } if ($templates_id) { $translation = new NotificationTemplateTranslation(); if (!countElementsInTable($translation->getTable(), "`notificationtemplates_id`='{$templates_id}'")) { $tmp = array(); $tmp['notificationtemplates_id'] = $templates_id; $tmp['language'] = ''; $tmp['subject'] = '##order.action## ##order.entity##'; $tmp['content_text'] = '##lang.order.entity## : ##order.entity##\\n' . ' \\n##FOREACHorders##\\n' . '##lang.order.item.name## : ##order.item.name##\\n ' . '##lang.order.item.numorder## : ##order.item.numorder##\\n ' . '##lang.order.item.orderdate## : ##order.item.orderdate##\\n ' . '##lang.order.item.duedate## : ##order.item.duedate##\\n ' . '##lang.order.item.deliverydate## : ##order.item.deliverydate##\\n ' . '##order.item.url## \\n ##ENDFOREACHorders##'; $tmp['content_html'] = "##lang.order.entity## : ##order.entity##<br /> " . "<br />##FOREACHorders##<br />" . "##lang.order.item.name## : ##order.item.name##<br /> " . "##lang.order.item.numorder## : ##order.item.numorder##<br /> " . "##lang.order.item.orderdate## : ##order.item.orderdate##<br /> <a>" . "##lang.order.item.duedate## : ##order.item.duedate##<br /> </a><a>" . "##lang.order.item.deliverydate## : ##order.item.deliverydate##<br /> </a><a>" . "##order.item.url##</a><br /> ##ENDFOREACHorders##"; $translation->add($tmp); } $notifs = array('Due date overtaken' => 'duedate'); $notification = new Notification(); foreach ($notifs as $label => $name) { if (!countElementsInTable("glpi_notifications", "`itemtype`='PluginOrderOrder' AND `event`='{$name}'")) { $tmp = array('name' => $label, 'entities_id' => 0, 'itemtype' => 'PluginOrderOrder', 'event' => $name, 'mode' => 'mail', 'comment' => '', 'is_recursive' => 1, 'is_active' => 1, 'date_mod' => $_SESSION['glpi_currenttime'], 'notificationtemplates_id' => $templates_id); $notification->add($tmp); } } } $template = new NotificationTemplate(); $templates_id = false; $query_id = "SELECT `id`\n FROM `glpi_notificationtemplates`\n WHERE `itemtype`='PluginOrderOrder'\n AND `name` = 'Order Delivered'"; $result = $DB->query($query_id) or die($DB->error()); if ($DB->numrows($result) > 0) { $templates_id = $DB->result($result, 0, 'id'); } else { $tmp = array('name' => 'Order Delivered', 'itemtype' => 'PluginOrderOrder', 'date_mod' => $_SESSION['glpi_currenttime'], 'comment' => '', 'css' => ''); $templates_id = $template->add($tmp); } if ($templates_id) { $translation = new NotificationTemplateTranslation(); if (!countElementsInTable($translation->getTable(), "`notificationtemplates_id`='{$templates_id}'")) { $tmp['notificationtemplates_id'] = $templates_id; $tmp['language'] = ''; $tmp['subject'] = '##order.action## ##ordervalidation.name## ##ordervalidation.numorder##'; $tmp['content_text'] = '##order.action## ##lang.ordervalidation.name## : ##ordervalidation.name## ##lang.ordervalidation.orderdate## : ##ordervalidation.orderdate## ##lang.ordervalidation.entity## : ##ordervalidation.entity##'; $tmp['content_html'] = '<p>##order.action## <br /><br />  ##lang.ordervalidation.name## : <br />  ##ordervalidation.name## <br />  ##lang.ordervalidation.orderdate## : <br />  ##ordervalidation.orderdate## <br />  <br />  ##lang.ordervalidation.entity## : <br /> ##ordervalidation.entity##</p>'; $translation->add($tmp); } } $notifs = array('Order Delivered' => 'delivered'); $notification = new Notification(); foreach ($notifs as $label => $name) { if (!countElementsInTable("glpi_notifications", "`itemtype`='PluginOrderOrder' AND `event`='{$name}'")) { $tmp = array('name' => $label, 'entities_id' => 0, 'itemtype' => 'PluginOrderOrder', 'event' => $name, 'mode' => 'mail', 'comment' => '', 'is_recursive' => 1, 'is_active' => 1, 'date_mod' => $_SESSION['glpi_currenttime'], 'notificationtemplates_id' => $templates_id); $notification->add($tmp); } } }