function plugin_accounts_install() { global $DB, $CFG_GLPI; include_once GLPI_ROOT . "/plugins/accounts/inc/profile.class.php"; $install = false; $update78 = false; $update80 = false; $update171 = false; if (!TableExists("glpi_plugin_compte") && !TableExists("glpi_plugin_comptes") && !TableExists("glpi_comptes") && !TableExists("glpi_plugin_accounts_accounts")) { $install = true; $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/empty-1.9.0.sql"); } else { if (TableExists("glpi_comptes") && !FieldExists("glpi_comptes", "notes")) { $update78 = true; $update80 = true; $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.3.sql"); plugin_accounts_updatev14(); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql"); $_SESSION['plugin_acounts_upgrading'] = 1; } else { if (TableExists("glpi_plugin_comptes") && !FieldExists("glpi_plugin_comptes", "all_users")) { $update78 = true; $update80 = true; $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.3.sql"); plugin_accounts_updatev14(); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql"); $_SESSION['plugin_acounts_upgrading'] = 1; } else { if (TableExists("glpi_plugin_compte_profiles") && !FieldExists("glpi_plugin_compte_profiles", "my_groups")) { $update78 = true; $update80 = true; plugin_accounts_updatev14(); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql"); $_SESSION['plugin_acounts_upgrading'] = 1; } else { if (TableExists("glpi_plugin_compte_profiles") && FieldExists("glpi_plugin_compte_profiles", "interface")) { $update78 = true; $update80 = true; $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql"); $_SESSION['plugin_acounts_upgrading'] = 1; } else { if (TableExists("glpi_plugin_compte") && !FieldExists("glpi_plugin_compte", "date_mod")) { $update78 = true; $update80 = true; $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql"); } else { if (TableExists("glpi_plugin_compte") && !TableExists("glpi_plugin_compte_aeskey")) { $update78 = true; $update80 = true; $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql"); } else { if (TableExists("glpi_plugin_compte") && !TableExists("glpi_plugin_accounts_accounts")) { $update78 = true; $update80 = true; $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql"); } else { if (TableExists("glpi_plugin_accounts_accounts") && !FieldExists("glpi_plugin_accounts_accounts", "locations_id")) { $update80 = true; $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql"); } else { if (TableExists("glpi_plugin_accounts_hashes") && !FieldExists("glpi_plugin_accounts_hashes", "entities_id")) { $update171 = true; $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql"); } } } } } } } } } } //from 1.6 version if (TableExists("glpi_plugin_accounts_accounts") && !FieldExists("glpi_plugin_accounts_accounts", "users_id_tech")) { $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.8.0.sql"); } //from 1.9 version if (TableExists("glpi_plugin_accounts_accounttypes") && !FieldExists("glpi_plugin_accounts_accounttypes", "is_recursive")) { $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.9.0.sql"); } if ($install || $update78) { //Do One time on 0.78 $query_id = "SELECT `id` FROM `glpi_notificationtemplates`\n WHERE `itemtype`='PluginAccountsAccount'\n AND `name` = 'New Accounts'"; $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.account.title##',\n '##lang.account.url## : ##account.url##\r\n\r\n\n ##lang.account.entity## : ##account.entity##\r\n\n ##IFaccount.name####lang.account.name## : ##account.name##\r\n##ENDIFaccount.name##\n ##IFaccount.type####lang.account.type## : ##account.type##\r\n##ENDIFaccount.type##\n ##IFaccount.state####lang.account.state## : ##account.state##\r\n##ENDIFaccount.state##\n ##IFaccount.login####lang.account.login## : ##account.login##\r\n##ENDIFaccount.login##\n ##IFaccount.users_id####lang.account.users_id## : ##account.users_id##\r\n##ENDIFaccount.users_id##\n ##IFaccount.groups_id####lang.account.groups_id## : ##account.groups_id##\r\n##ENDIFaccount.groups_id##\n ##IFaccount.others####lang.account.others## : ##account.others##\r\n##ENDIFaccount.others##\n ##IFaccount.datecreation####lang.account.datecreation## : ##account.datecreation##\r\n##ENDIFaccount.datecreation##\n ##IFaccount.dateexpiration####lang.account.dateexpiration## : ##account.dateexpiration##\r\n##ENDIFaccount.dateexpiration##\n ##IFaccount.comment####lang.account.comment## : ##account.comment##\r\n##ENDIFaccount.comment##',\n '<p><strong>##lang.account.url##</strong> : <a href=\"##account.url##\">##account.url##</a></p>\n <p><strong>##lang.account.entity##</strong> : ##account.entity##<br /> ##IFaccount.name##<strong>##lang.account.name##</strong> : ##account.name##<br />##ENDIFaccount.name## ##IFaccount.type##<strong>##lang.account.type##</strong> : ##account.type##<br />##ENDIFaccount.type## ##IFaccount.state##<strong>##lang.account.state##</strong> : ##account.state##<br />##ENDIFaccount.state## ##IFaccount.login##<strong>##lang.account.login##</strong> : ##account.login##<br />##ENDIFaccount.login## ##IFaccount.users##<strong>##lang.account.users##</strong> : ##account.users##<br />##ENDIFaccount.users## ##IFaccount.groups##<strong>##lang.account.groups##</strong> : ##account.groups##<br />##ENDIFaccount.groups## ##IFaccount.others##<strong>##lang.account.others##</strong> : ##account.others##<br />##ENDIFaccount.others## ##IFaccount.datecreation##<strong>##lang.account.datecreation##</strong> : ##account.datecreation##<br />##ENDIFaccount.datecreation## ##IFaccount.dateexpiration##<strong>##lang.account.dateexpiration##</strong> : ##account.dateexpiration##<br />##ENDIFaccount.dateexpiration## ##IFaccount.comment##<strong>##lang.account.comment##</strong> : ##account.comment####ENDIFaccount.comment##</p>');"; $result = $DB->query($query); $query = "INSERT INTO `glpi_notifications`\n VALUES (NULL, 'New Accounts', 0, 'PluginAccountsAccount', 'new',\n 'mail'," . $itemtype . ",\n '', 1, 1, '2010-02-17 22:36:46');"; $result = $DB->query($query); $query_id = "SELECT `id` FROM `glpi_notificationtemplates`\n WHERE `itemtype`='PluginAccountsAccount'\n AND `name` = 'Alert Accounts'"; $result = $DB->query($query_id) or die($DB->error()); $itemtype = $DB->result($result, 0, 'id'); $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n VALUES(NULL, " . $itemtype . ", '','##account.action## : ##account.entity##',\n '##lang.account.entity## :##account.entity##\n ##FOREACHaccounts##\n ##lang.account.name## : ##account.name## - ##lang.account.dateexpiration## : ##account.dateexpiration##\n ##ENDFOREACHaccounts##',\n '<p>##lang.account.entity## :##account.entity##<br /> <br />\n ##FOREACHaccounts##<br />\n ##lang.account.name## : ##account.name## - ##lang.account.dateexpiration## : ##account.dateexpiration##<br />\n ##ENDFOREACHaccounts##</p>');"; $result = $DB->query($query); $query = "INSERT INTO `glpi_notifications`\n VALUES (NULL, 'Alert Expired Accounts', 0, 'PluginAccountsAccount', 'ExpiredAccounts',\n 'mail'," . $itemtype . ",\n '', 1, 1, '2010-02-17 22:36:46');"; $result = $DB->query($query); $query = "INSERT INTO `glpi_notifications`\n VALUES (NULL, 'Alert Accounts Which Expire', 0, 'PluginAccountsAccount', 'AccountsWhichExpire',\n 'mail'," . $itemtype . ",\n '', 1, 1, '2010-02-17 22:36:46');"; $result = $DB->query($query); } if ($update78) { //Do One time on 0.78 $query_ = "SELECT *\n FROM `glpi_plugin_accounts_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_accounts_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $query = "ALTER TABLE `glpi_plugin_accounts_profiles`\n DROP `name` ;"; $result = $DB->query($query); Plugin::migrateItemType(array(1900 => 'PluginAccountsAccount', 1901 => 'PluginAccountsHelpdesk', 1902 => 'PluginAccountsGroup'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_accounts_accounts_items")); Plugin::migrateItemType(array(1200 => "PluginAppliancesAppliance", 1300 => "PluginWebapplicationsWebapplication", 1700 => "PluginCertificatesCertificate", 4400 => "PluginDomainsDomain", 2400 => "PluginDatabasesDatabase"), array("glpi_plugin_accounts_accounts_items")); } if ($update171) { $query = "UPDATE `glpi_plugin_accounts_hashes`\n SET `is_recursive` = '1'\n WHERE `id` = '1';"; $result = $DB->query($query); $query = "UPDATE `glpi_plugin_accounts_aeskeys`\n SET `plugin_accounts_hashes_id` = '1'\n WHERE `id` = '1';"; $result = $DB->query($query); } if (isset($_SESSION['plugin_acounts_upgrading'])) { $msg = __('After plugin installation, you must do upgrade of your passwords from here : ', 'accounts'); $msg .= "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/accounts/front/upgrade.form.php'>" . __('Upgrading page', 'accounts') . "</a>"; Session::addMessageAfterRedirect($msg, ERROR); } CronTask::Register('PluginAccountsAccount', 'AccountsAlert', DAY_TIMESTAMP); PluginAccountsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); return true; }
Copyright (C) 2003-2011 by the accounts Development Team. https://forge.indepnet.net/projects/accounts ------------------------------------------------------------------------- LICENSE This file is part of accounts. accounts 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. accounts 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 accounts. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include '../../../inc/includes.php'; Session::checkRight("profile", "r"); $prof = new PluginAccountsProfile(); //Save profile if (isset($_POST['update'])) { $prof->update($_POST); Html::back(); }
function plugin_accounts_uninstall() { global $DB; include_once GLPI_ROOT . "/plugins/accounts/inc/profile.class.php"; include_once GLPI_ROOT . "/plugins/accounts/inc/menu.class.php"; $tables = array("glpi_plugin_accounts_accounts", "glpi_plugin_accounts_accounts_items", "glpi_plugin_accounts_accounttypes", "glpi_plugin_accounts_accountstates", "glpi_plugin_accounts_configs", "glpi_plugin_accounts_hashs", "glpi_plugin_accounts_hashes", "glpi_plugin_accounts_aeskeys", "glpi_plugin_accounts_notificationstates"); foreach ($tables as $table) { $DB->query("DROP TABLE IF EXISTS `{$table}`;"); } //old versions $tables = array("glpi_plugin_comptes", "glpi_plugin_compte_device", "glpi_dropdown_plugin_compte_type", "glpi_dropdown_plugin_compte_status", "glpi_plugin_compte_profiles", "glpi_plugin_compte_config", "glpi_plugin_compte_default", "glpi_plugin_compte_mailing", "glpi_plugin_compte", "glpi_plugin_compte_hash", "glpi_plugin_compte_aeskey", "glpi_plugin_accounts_profiles"); foreach ($tables as $table) { $DB->query("DROP TABLE IF EXISTS `{$table}`;"); } $notif = new Notification(); $options = array('itemtype' => 'PluginAccountsAccount', 'event' => 'new', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notifications', $options) as $data) { $notif->delete($data); } $options = array('itemtype' => 'PluginAccountsAccount', 'event' => 'ExpiredAccounts', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notifications', $options) as $data) { $notif->delete($data); } $options = array('itemtype' => 'PluginAccountsAccount', 'event' => 'AccountsWhichExpire', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notifications', $options) as $data) { $notif->delete($data); } //templates $template = new NotificationTemplate(); $translation = new NotificationTemplateTranslation(); $options = array('itemtype' => 'PluginAccountsAccount', '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); } $tables_glpi = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs", "glpi_items_tickets", "glpi_dropdowntranslations"); foreach ($tables_glpi as $table_glpi) { $DB->query("DELETE FROM `{$table_glpi}`\n WHERE `itemtype` = 'PluginAccountsAccount'\n OR `itemtype` = 'PluginAccountsHelpdesk'\n OR `itemtype` = 'PluginAccountsGroup'\n OR `itemtype` = 'PluginAccountsAccountState'\n OR `itemtype` = 'PluginAccountsAccountType' ;"); } if (class_exists('PluginDatainjectionModel')) { PluginDatainjectionModel::clean(array('itemtype' => 'PluginAccountsAccount')); } //Delete rights associated with the plugin $profileRight = new ProfileRight(); foreach (PluginAccountsProfile::getAllRights() as $right) { $profileRight->deleteByCriteria(array('name' => $right['field'])); } PluginAccountsProfile::removeRightsFromSession(); PluginAccountsMenu::removeRightsFromSession(); return true; }