some GLPI 0.80 new behaviour

git-svn-id: https://forge.glpi-project.org/svn/example/trunk@105 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
remicollet 2009-12-05 07:57:27 +00:00
parent c13d3089d3
commit f5c43454a7
7 changed files with 281 additions and 73 deletions

45
ajax/dropdown.tabs.php Normal file
View File

@ -0,0 +1,45 @@
<?php
/*
* @version $Id: phone.tabs.php 8933 2009-09-10 18:41:20Z remi $
-------------------------------------------------------------------------
GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2009 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
// ----------------------------------------------------------------------
define('GLPI_ROOT', '../../..');
include (GLPI_ROOT . "/inc/includes.php");
usePlugin('example',true);
$dropdown = new PluginExampleDropdown();
include (GLPI_ROOT . "/ajax/dropdown.common.tabs.php");
?>

44
front/dropdown.form.php Normal file
View File

@ -0,0 +1,44 @@
<?php
/*
* @version $Id: typedoc.form.php 8624 2009-08-04 12:45:43Z moyo $
-------------------------------------------------------------------------
GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2009 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file: Remi Collet
// Purpose of file:
// ----------------------------------------------------------------------
define('GLPI_ROOT', '../../..');
include (GLPI_ROOT . "/inc/includes.php");
usePlugin('example',true);
$dropdown = new PluginExampleDropdown();
include (GLPI_ROOT . "/front/dropdown.common.form.php");
?>

46
front/dropdown.php Normal file
View File

@ -0,0 +1,46 @@
<?php
/*
* @version $Id: document.php 8830 2009-09-01 06:28:12Z remi $
-------------------------------------------------------------------------
GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2009 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file: Remi collet
// Purpose of file:
// ----------------------------------------------------------------------
$NEEDED_ITEMS = array ('search');
define('GLPI_ROOT', '../../..');
include (GLPI_ROOT . "/inc/includes.php");
usePlugin('example',true);
$dropdown = new PluginExampleDropdown();
include (GLPI_ROOT . "/front/dropdown.common.php");
?>

View File

@ -33,63 +33,9 @@
// Purpose of file:
// ----------------------------------------------------------------------
// Class of the defined type
class pluginExample extends CommonDBTM {
function __construct () {
$this->table="glpi_plugin_example";
$this->type=PLUGIN_EXAMPLE_TYPE;
}
// Should return the localized name of the type
static function getTypeName() {
global $LANG;
return 'Example Type';
}
function getSearchOptions() {
global $LANG;
$tab = array();
$tab['common']="Header Needed";
$tab[1]['table']='glpi_plugin_example';
$tab[1]['field']='name';
$tab[1]['linkfield']='name';
$tab[1]['name']=$LANG['plugin_example']["name"];
$tab[2]['table']='glpi_plugin_example_dropdown';
$tab[2]['field']='name';
$tab[2]['linkfield']='plugin_example_dropdown_id';
$tab[2]['name']='Dropdown';
$tab[3]['table']='glpi_plugin_example';
$tab[3]['field']='serial';
$tab[3]['linkfield']='serial';
$tab[3]['name']='Serial';
$tab[3]['usehaving']=true;
$tab[30]['table']='glpi_plugin_example';
$tab[30]['field']='id';
$tab[30]['linkfield']='';
$tab[30]['name']=$LANG["common"][2];
return $tab;
}
}
// Class for a Dropdown
class pluginExampleDropdown extends CommonDropdown {
function __construct () {
$this->table="glpi_plugin_example_dropdown";
$this->type=PLUGIN_EXAMPLEDROPDOWN_TYPE;
}
static function getTypeName() {
global $LANG;
return "Plugin Example Dropdown";
}
// TODO remove this when autoload ready
foreach (glob(GLPI_ROOT . '/plugins/example/inc/*.php') as $file) {
include_once ($file);
}
// Hook called on profile change
@ -120,7 +66,7 @@ function plugin_example_getDatabaseRelations(){
// Define Dropdown tables to be manage in GLPI :
function plugin_example_getDropdown(){
// Table => Name
return array(PLUGIN_EXAMPLEDROPDOWN_TYPE => "Plugin Example Dropdown");
return array('PluginExampleDropdown' => "Plugin Example Dropdown");
}
////// SEARCH FUNCTIONS ///////(){
@ -760,8 +706,8 @@ function plugin_example_install(){
global $DB;
if (!TableExists("glpi_plugin_example")){
$query="CREATE TABLE `glpi_plugin_example` (
if (!TableExists("glpi_plugin_example_example")){
$query="CREATE TABLE `glpi_plugin_example_example` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`serial` varchar(255) collate utf8_unicode_ci NOT NULL,
@ -772,8 +718,8 @@ function plugin_example_install(){
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
";
$DB->query($query) or die("error creating glpi_plugin_example ". $DB->error());
$query="INSERT INTO `glpi_plugin_example` (`id`, `name`, `serial`, `plugin_example_dropdown_id`,
$DB->query($query) or die("error creating glpi_plugin_example_example ". $DB->error());
$query="INSERT INTO `glpi_plugin_example_example` (`id`, `name`, `serial`, `plugin_example_dropdown_id`,
`is_deleted`, `is_template`, `template_name`) VALUES
(1, 'example 1', 'serial 1', 1, 0, 0, NULL),
(2, 'example 2', 'serial 2', 2, 0, 0, NULL),

49
inc/dropdown.php Normal file
View File

@ -0,0 +1,49 @@
<?php
/*
* @version $Id: hook.php 104 2009-12-02 18:37:21Z remi $
-------------------------------------------------------------------------
GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2009 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
// ----------------------------------------------------------------------
// Class for a Dropdown
class PluginExampleDropdown extends CommonDropdown {
// From CommonDBTM
public $table = 'glpi_plugin_example_dropdown';
public $type = 'PluginExampleDropdown';
static function getTypeName() {
global $LANG;
return "Plugin Example Dropdown";
}
}
?>

81
inc/example.php Normal file
View File

@ -0,0 +1,81 @@
<?php
/*
* @version $Id: hook.php 104 2009-12-02 18:37:21Z remi $
-------------------------------------------------------------------------
GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2009 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
// ----------------------------------------------------------------------
// Class of the defined type
class PluginExampleExample extends CommonDBTM {
// From CommonDBTM
public $table = 'glpi_plugin_example_example';
public $type = 'PluginExampleExample';
// Should return the localized name of the type
static function getTypeName() {
global $LANG;
return 'Example Type';
}
function getSearchOptions() {
global $LANG;
$tab = array();
$tab['common']="Header Needed";
$tab[1]['table']='glpi_plugin_example';
$tab[1]['field']='name';
$tab[1]['linkfield']='name';
$tab[1]['name']=$LANG['plugin_example']["name"];
$tab[2]['table']='glpi_plugin_example_dropdown';
$tab[2]['field']='name';
$tab[2]['linkfield']='plugin_example_dropdown_id';
$tab[2]['name']='Dropdown';
$tab[3]['table']='glpi_plugin_example';
$tab[3]['field']='serial';
$tab[3]['linkfield']='serial';
$tab[3]['name']='Serial';
$tab[3]['usehaving']=true;
$tab[30]['table']='glpi_plugin_example';
$tab[30]['field']='id';
$tab[30]['linkfield']='';
$tab[30]['name']=$LANG["common"][2];
return $tab;
}
}
?>

View File

@ -38,10 +38,10 @@ function plugin_init_example() {
global $PLUGIN_HOOKS,$LANG,$CFG_GLPI;
// Params : plugin name - string type - ID - Array of attributes
registerPluginType('example', 'PLUGIN_EXAMPLE_TYPE', 1001, array(
'classname' => 'pluginExample',
'tablename' => 'glpi_plugin_example',
'formpage' => 'example.form.php',
registerPluginType('example', 'PLUGIN_EXAMPLE_TYPE', 'PluginExampleExample', array(
'classname' => 'PluginExampleExample',
'tablename' => 'glpi_plugin_example_example',
'formpage' => 'front/example.form.php',
'searchpage' => 'index.php',
'typename' => 'Example Type',
'deleted_tables' => false,
@ -53,11 +53,12 @@ function plugin_init_example() {
));
// Params : plugin name - string type - ID - Array of attributes
registerPluginType('example', 'PLUGIN_EXAMPLEDROPDOWN_TYPE', 1002, array(
'classname' => 'pluginExampleDropdown',
registerPluginType('example', 'PLUGIN_EXAMPLEDROPDOWN_TYPE', 'PluginExampleDropdown', array(
'classname' => 'PluginExampleDropdown',
'tablename' => 'glpi_plugin_example_dropdown',
'typename' => 'Example Dropdown Type',
'dropdown' => true));
'formpage' => 'front/dropdown.form.php',
'searchpage' => 'front/dropdown.php'));
// Display a menu entry ?
if (plugin_example_haveTypeRight(PLUGIN_EXAMPLE_TYPE,'r')) { // Right set in change_profile hook
@ -186,10 +187,6 @@ function plugin_example_haveTypeRight($type,$right){
case PLUGIN_EXAMPLE_TYPE :
// Evaluate the right from data saved in session by change_profile hook
return ($right=='r' || $_SESSION["glpi_plugin_example_profile"]=='w');
break;
case PLUGIN_EXAMPLEDROPDOWN_TYPE :
return haveRight("entity_dropdown",$right);
break;
}
}