Copyright (C) 2003-2011 by the Additionalalerts Development Team. https://forge.indepnet.net/projects/additionalalerts ------------------------------------------------------------------------- LICENSE This file is part of Additionalalerts. Additionalalerts is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Additionalalerts is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with additionalalerts. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include '../../../inc/includes.php'; Session::checkRight("profile", "r"); $prof = new PluginAdditionalalertsProfile(); //Save profile if (isset($_POST['update'])) { $prof->update($_POST); Html::back(); }
function plugin_additionalalerts_uninstall() { global $DB; $tables = array("glpi_plugin_additionalalerts_ocsalerts", "glpi_plugin_additionalalerts_infocomalerts", "glpi_plugin_additionalalerts_notificationstates", "glpi_plugin_additionalalerts_notificationtypes", "glpi_plugin_additionalalerts_configs"); foreach ($tables as $table) { $DB->query("DROP TABLE IF EXISTS `{$table}`;"); } //old versions $tables = array("glpi_plugin_additionalalerts_reminderalerts", "glpi_plugin_alerting_config", "glpi_plugin_alerting_state", "glpi_plugin_alerting_profiles", "glpi_plugin_alerting_mailing", "glpi_plugin_alerting_type", "glpi_plugin_additionalalerts_profiles"); foreach ($tables as $table) { $DB->query("DROP TABLE IF EXISTS `{$table}`;"); } $notif = new Notification(); $options = array('itemtype' => 'PluginAdditionalalertsOcsAlert', 'event' => 'ocs', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notifications', $options) as $data) { $notif->delete($data); } $options = array('itemtype' => 'PluginAdditionalalertsOcsAlert', 'event' => 'newocs', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notifications', $options) as $data) { $notif->delete($data); } $options = array('itemtype' => 'PluginAdditionalalertsInfocomAlert', 'event' => 'notinfocom', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notifications', $options) as $data) { $notif->delete($data); } //templates $template = new NotificationTemplate(); $translation = new NotificationTemplateTranslation(); $options = array('itemtype' => 'PluginAdditionalalertsOcsAlert', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notificationtemplates', $options) as $data) { $options_template = array('notificationtemplates_id' => $data['id'], 'FIELDS' => 'id'); foreach ($DB->request('glpi_notificationtemplatetranslations', $options_template) as $data_template) { $translation->delete($data_template); } $template->delete($data); } //templates $template = new NotificationTemplate(); $translation = new NotificationTemplateTranslation(); $options = array('itemtype' => 'PluginAdditionalalertsInfocomAlert', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notificationtemplates', $options) as $data) { $options_template = array('notificationtemplates_id' => $data['id'], 'FIELDS' => 'id'); foreach ($DB->request('glpi_notificationtemplatetranslations', $options_template) as $data_template) { $translation->delete($data_template); } $template->delete($data); } //Delete rights associated with the plugin $profileRight = new ProfileRight(); foreach (PluginAdditionalalertsProfile::getAllRights() as $right) { $profileRight->deleteByCriteria(array('name' => $right['field'])); } PluginAdditionalalertsProfile::removeRightsFromSession(); PluginAdditionalalertsMenu::removeRightsFromSession(); return true; }
function plugin_additionalalerts_install() { global $DB; include_once GLPI_ROOT . "/plugins/additionalalerts/inc/profile.class.php"; $install = false; $update78 = false; $update80 = false; if (!TableExists("glpi_plugin_alerting_config") && !TableExists("glpi_plugin_additionalalerts_notificationstates")) { $install = true; $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/empty-1.5.0.sql"); } else { if (TableExists("glpi_plugin_alerting_profiles") && FieldExists("glpi_plugin_alerting_profiles", "interface")) { $update78 = true; $update80 = true; $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.2.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.3.0.sql"); } else { if (!TableExists("glpi_plugin_additionalalerts_notificationstates")) { $update78 = true; $update80 = true; $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.3.0.sql"); } else { if (TableExists("glpi_plugin_additionalalerts_reminderalerts")) { $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.5.0.sql"); $notif = new Notification(); $options = array('itemtype' => 'PluginAdditionalalertsReminderAlert', 'event' => 'reminder', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notifications', $options) as $data) { $notif->delete($data); } $template = new NotificationTemplate(); $translation = new NotificationTemplateTranslation(); $options = array('itemtype' => 'PluginAdditionalalertsReminderAlert', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notificationtemplates', $options) as $data) { $options_template = array('notificationtemplates_id' => $data['id'], 'FIELDS' => 'id'); foreach ($DB->request('glpi_notificationtemplatetranslations', $options_template) as $data_template) { $translation->delete($data_template); } $template->delete($data); } $temp = new CronTask(); if ($temp->getFromDBbyName('PluginAdditionalalertsReminderAlert', 'AdditionalalertsReminder')) { $temp->delete(array('id' => $temp->fields["id"])); } } } } } if ($install || $update78) { //Do One time on 0.78 $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginAdditionalalertsInfocomAlert' AND `name` = 'Alert infocoms'"; $result = $DB->query($query_id) or die($DB->error()); $itemtype = $DB->result($result, 0, 'id'); $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n VALUES(NULL, " . $itemtype . ", '','##lang.notinfocom.title## : ##notinfocom.entity##',\n '##FOREACHnotinfocoms##\n ##lang.notinfocom.name## : ##notinfocom.name##\n ##lang.notinfocom.computertype## : ##notinfocom.computertype##\n ##lang.notinfocom.operatingsystem## : ##notinfocom.operatingsystem##\n ##lang.notinfocom.state## : ##notinfocom.state##\n ##lang.notinfocom.location## : ##notinfocom.location##\n ##lang.notinfocom.user## : ##notinfocom.user## / ##notinfocom.group## / ##notinfocom.contact##\n ##ENDFOREACHnotinfocoms##',\n '<table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\">\n <tbody>\n <tr>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.notinfocom.name##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.notinfocom.computertype##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.notinfocom.operatingsystem##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.notinfocom.state##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.notinfocom.location##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.notinfocom.user##</span></td>\n </tr>\n ##FOREACHnotinfocoms## \n <tr>\n <td><a href=\"##notinfocom.urlname##\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##notinfocom.name##</span></a></td>\n <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##notinfocom.computertype##</span></td>\n <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##notinfocom.operatingsystem##</span></td>\n <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##notinfocom.state##</span></td>\n <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##notinfocom.location##</span></td>\n <td><a href=\"##notinfocom.urluser##\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##notinfocom.user##</span></a> / <a href=\"##notinfocom.urlgroup##\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##notinfocom.group##</span></a> / <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##notinfocom.contact##</span></td>\n </tr>\n ##ENDFOREACHnotinfocoms##\n </tbody>\n </table>');"; $result = $DB->query($query); $query = "INSERT INTO `glpi_notifications`\n VALUES (NULL, 'Alert infocoms', 0, 'PluginAdditionalalertsInfocomAlert', 'notinfocom',\n 'mail'," . $itemtype . ",\n '', 1, 1, '2010-03-13 10:36:46');"; $result = $DB->query($query); //////////////////// $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginAdditionalalertsOcsAlert' AND `name` = 'Alert machines ocs'"; $result = $DB->query($query_id) or die($DB->error()); $itemtype = $DB->result($result, 0, 'id'); $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n VALUES(NULL, " . $itemtype . ", '','##lang.ocsmachine.title## : ##ocsmachine.entity##',\n '##FOREACHocsmachines##\n ##lang.ocsmachine.name## : ##ocsmachine.name##\n ##lang.ocsmachine.operatingsystem## : ##ocsmachine.operatingsystem##\n ##lang.ocsmachine.state## : ##ocsmachine.state##\n ##lang.ocsmachine.location## : ##ocsmachine.location##\n ##lang.ocsmachine.user## : ##ocsmachine.user## / ##lang.ocsmachine.group## : ##ocsmachine.group## / ##lang.ocsmachine.contact## : ##ocsmachine.contact##\n ##lang.ocsmachine.lastocsupdate## : ##ocsmachine.lastocsupdate##\n ##lang.ocsmachine.lastupdate## : ##ocsmachine.lastupdate##\n ##lang.ocsmachine.ocsserver## : ##ocsmachine.ocsserver##\n ##ENDFOREACHocsmachines##',\n '<table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\">\n <tbody>\n <tr>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.ocsmachine.name##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.ocsmachine.operatingsystem##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.ocsmachine.state##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.ocsmachine.location##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.ocsmachine.user##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.ocsmachine.lastocsupdate##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.ocsmachine.lastupdate##</span></td>\n <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.ocsmachine.ocsserver##</span></td>\n </tr>\n ##FOREACHocsmachines## \n <tr>\n <td><a href=\"##ocsmachine.urlname##\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##ocsmachine.name##</span></a></td>\n <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##ocsmachine.operatingsystem##</span></td>\n <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##ocsmachine.state##</span></td>\n <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##ocsmachine.location##</span></td>\n <td>##IFocsmachine.user##<a href=\"##ocsmachine.urluser##\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##ocsmachine.user##</span></a> / ##ENDIFocsmachine.user####IFocsmachine.group##<a href=\"##ocsmachine.urlgroup##\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##ocsmachine.group##</span></a> / ##ENDIFocsmachine.group####IFocsmachine.contact##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##ocsmachine.contact####ENDIFocsmachine.contact##</span></td>\n <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##ocsmachine.lastocsupdate##</span></td>\n <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##ocsmachine.lastupdate##</span></td>\n <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##ocsmachine.ocsserver##</span></td>\n </tr>\n ##ENDFOREACHocsmachines##\n </tbody>\n </table>');"; $result = $DB->query($query); $query = "INSERT INTO `glpi_notifications`\n VALUES (NULL, 'Alert new machines ocs', 0, 'PluginAdditionalalertsOcsAlert', 'newocs',\n 'mail'," . $itemtype . ",\n '', 1, 1, '2010-03-20 10:36:46');"; $result = $DB->query($query); $query = "INSERT INTO `glpi_notifications`\n VALUES (NULL, 'Alert ocs synchronization', 0, 'PluginAdditionalalertsOcsAlert', 'ocs',\n 'mail'," . $itemtype . ",\n '', 1, 1, '2010-03-20 10:36:46');"; $result = $DB->query($query); } if ($update78) { //Do One time on 0.78 $query_ = "SELECT *\n FROM `glpi_plugin_additionalalerts_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_additionalalerts_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $query = "ALTER TABLE `glpi_plugin_additionalalerts_profiles`\n DROP `name` ;"; $result = $DB->query($query); } // To be called for each task the plugin manage CronTask::Register('PluginAdditionalalertsOcsAlert', 'AdditionalalertsOcs', DAY_TIMESTAMP); CronTask::Register('PluginAdditionalalertsOcsAlert', 'AdditionalalertsNewOcs', HOUR_TIMESTAMP); CronTask::Register('PluginAdditionalalertsInfocomAlert', 'AdditionalalertsNotInfocom', HOUR_TIMESTAMP); PluginAdditionalalertsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); return true; }