diff --git a/ajax/dropdown.tabs.php b/ajax/dropdown.tabs.php new file mode 100644 index 0000000..888cec6 --- /dev/null +++ b/ajax/dropdown.tabs.php @@ -0,0 +1,45 @@ + \ No newline at end of file diff --git a/front/dropdown.form.php b/front/dropdown.form.php new file mode 100644 index 0000000..9c6d061 --- /dev/null +++ b/front/dropdown.form.php @@ -0,0 +1,44 @@ + \ No newline at end of file diff --git a/front/dropdown.php b/front/dropdown.php new file mode 100644 index 0000000..af42492 --- /dev/null +++ b/front/dropdown.php @@ -0,0 +1,46 @@ + diff --git a/hook.php b/hook.php index 0303a51..c1bc856 100644 --- a/hook.php +++ b/hook.php @@ -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), diff --git a/inc/dropdown.php b/inc/dropdown.php new file mode 100644 index 0000000..7af4214 --- /dev/null +++ b/inc/dropdown.php @@ -0,0 +1,49 @@ + diff --git a/inc/example.php b/inc/example.php new file mode 100644 index 0000000..5133365 --- /dev/null +++ b/inc/example.php @@ -0,0 +1,81 @@ + diff --git a/setup.php b/setup.php index c791e8f..9a32fd9 100755 --- a/setup.php +++ b/setup.php @@ -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; } }