manage new config system

git-svn-id: https://forge.glpi-project.org/svn/example/trunk@211 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
moyooo 2013-02-19 08:27:50 +00:00
parent 064cf6a24f
commit d9a47a3e19
3 changed files with 100 additions and 0 deletions

View File

@ -557,6 +557,11 @@ function plugin_example_addParamFordynamicReport($itemtype) {
function plugin_example_install() { function plugin_example_install() {
global $DB; global $DB;
$config = new Config();
$config->setConfigurationValues('plugin:Example', array('configuration' => false));
ProfileRight::addProfileRights(array('example:read'));
if (!TableExists("glpi_plugin_example_examples")) { if (!TableExists("glpi_plugin_example_examples")) {
$query = "CREATE TABLE `glpi_plugin_example_examples` ( $query = "CREATE TABLE `glpi_plugin_example_examples` (
`id` int(11) NOT NULL auto_increment, `id` int(11) NOT NULL auto_increment,
@ -611,6 +616,10 @@ function plugin_example_install() {
function plugin_example_uninstall() { function plugin_example_uninstall() {
global $DB; global $DB;
$config = new Config();
$config->deleteConfigurationValues('plugin:Example', array('configuration' => false));
ProfileRight::deleteProfileRights(array('example:read'));
$notif = new Notification(); $notif = new Notification();
$options = array('itemtype' => 'Ticket', $options = array('itemtype' => 'Ticket',

88
inc/config.class.php Normal file
View File

@ -0,0 +1,88 @@
<?php
/*
* @version $Id$
-------------------------------------------------------------------------
GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2011 by the INDEPNET Development Team.
http://indepnet.net/ http://glpi-project.org
-------------------------------------------------------------------------
LICENSE
This file is part of GLPI.
GLPI 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.
GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
class PluginExampleConfig extends CommonDBTM {
static protected $notable = true;
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
if (!$withtemplate) {
if ($item->getType() == 'Config') {
return __('Example plugin');
}
}
return '';
}
static function configUpdate($input) {
$input['configuration'] = 1 - $input['configuration'];
return $input;
}
function showFormExample() {
global $CFG_GLPI;
if (!Session::haveRight("config", "w")) {
return false;
}
$my_config = Config::getConfigurationValues('plugin:Example');
echo "<form name='form' action=\"".Toolbox::getItemTypeFormURL('Config')."\" method='post'>";
echo "<div class='center' id='tabsbody'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='4'>" . __('Example setup') . "</th></tr>";
echo "<td >" . __('My boolean choice :') . "</td>";
echo "<td colspan='3'>";
echo "<input type='hidden' name='config_class' value='".__CLASS__."'>";
echo "<input type='hidden' name='config_context' value='plugin:Example'>";
Dropdown::showYesNo("configuration", $my_config['configuration']);
echo "</td></tr>";
echo "<tr class='tab_bg_2'>";
echo "<td colspan='4' class='center'>";
echo "<input type='submit' name='update' class='submit' value=\""._sx('button','Save')."\">";
echo "</td></tr>";
echo "</table></div>";
Html::closeForm();
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
if ($item->getType() == 'Config') {
$config = new self();
$config->showFormExample();
}
}
}
?>

View File

@ -42,6 +42,9 @@ function plugin_init_example() {
// array('classname' => 'PluginExampleExample', // array('classname' => 'PluginExampleExample',
// )); // ));
Plugin::registerClass('PluginExampleConfig', array('addtabon' => 'Config'));
Plugin::registerClass('PluginExampleRight', array('addtabon' => 'Profile'));
// Params : plugin name - string type - ID - Array of attributes // Params : plugin name - string type - ID - Array of attributes
Plugin::registerClass('PluginExampleDropdown'); Plugin::registerClass('PluginExampleDropdown');