diff --git a/front/devicecamera.form.php b/front/devicecamera.form.php new file mode 100644 index 0000000..5b75494 --- /dev/null +++ b/front/devicecamera.form.php @@ -0,0 +1,39 @@ +. + -------------------------------------------------------------------------- + */ + +// ---------------------------------------------------------------------- +// Original Author of file: +// Purpose of file: +// ---------------------------------------------------------------------- + +include ('../../../inc/includes.php'); + +$dropdown = new PluginExampleDeviceCamera(); +include (GLPI_ROOT . "/front/dropdown.common.form.php"); +?> \ No newline at end of file diff --git a/front/devicecamera.php b/front/devicecamera.php new file mode 100644 index 0000000..f04da77 --- /dev/null +++ b/front/devicecamera.php @@ -0,0 +1,39 @@ +. + -------------------------------------------------------------------------- + */ + +// ---------------------------------------------------------------------- +// Original Author of file: +// Purpose of file: +// ---------------------------------------------------------------------- + +include ('../../../inc/includes.php'); + +$dropdown = new PluginExampleDeviceCamera(); +include (GLPI_ROOT . "/front/dropdown.common.php"); +?> diff --git a/hook.php b/hook.php index 4d946a6..e438610 100644 --- a/hook.php +++ b/hook.php @@ -521,6 +521,38 @@ function plugin_example_install() { } + if (!TableExists('glpi_plugin_example_devicecameras')) { + $query = "CREATE TABLE `glpi_plugin_example_devicecameras` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `designation` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `comment` text COLLATE utf8_unicode_ci, + `manufacturers_id` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + KEY `designation` (`designation`), + KEY `manufacturers_id` (`manufacturers_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + + $DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error()); + } + + if (!TableExists('glpi_plugin_example_items_devicecameras')) { + $query = "CREATE TABLE `glpi_plugin_example_items_devicecameras` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `items_id` int(11) NOT NULL DEFAULT '0', + `itemtype` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `plugin_example_devicecameras_id` int(11) NOT NULL DEFAULT '0', + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', + `is_dynamic` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + KEY `computers_id` (`items_id`), + KEY `plugin_example_devicecameras_id` (`plugin_example_devicecameras_id`), + KEY `is_deleted` (`is_deleted`), + KEY `is_dynamic` (`is_dynamic`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + + $DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error()); + } + // To be called for each task the plugin manage // task in class CronTask::Register('PluginExampleExample', 'Sample', DAY_TIMESTAMP, array('param' => 50)); @@ -562,6 +594,14 @@ function plugin_example_uninstall() { $query = "DROP TABLE `glpi_plugin_example_dropdowns`;"; $DB->query($query) or die("error deleting glpi_plugin_example_dropdowns"); } + if (TableExists("glpi_plugin_example_devicecameras")) { + $query = "DROP TABLE `glpi_plugin_example_devicecameras`;"; + $DB->query($query) or die("error deleting glpi_plugin_example_devicecameras"); + } + if (TableExists("glpi_plugin_example_items_devicecameras")) { + $query = "DROP TABLE `glpi_plugin_example_items_devicecameras`;"; + $DB->query($query) or die("error deleting glpi_plugin_example_items_devicecameras"); + } return true; } @@ -587,7 +627,7 @@ function plugin_example_postinit() { global $CFG_GLPI; // All plugins are initialized, so all types are registered - foreach ($CFG_GLPI["infocom_types"] as $type) { + foreach (Infocom::getItemtypesThatCanHave() as $type) { // do something } } diff --git a/inc/devicecamera.class.php b/inc/devicecamera.class.php new file mode 100644 index 0000000..cb31d44 --- /dev/null +++ b/inc/devicecamera.class.php @@ -0,0 +1,49 @@ +. + -------------------------------------------------------------------------- + */ + +// ---------------------------------------------------------------------- +// Original Author of file: +// Purpose of file: +// ---------------------------------------------------------------------- + +// Class of the defined type + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access directly to this file"); +} + +/// Class DeviceCamera +class PluginExampleDeviceCamera extends CommonDevice { + + static function getTypeName($nb=0) { + return _n('Camera', 'Cameras', $nb); + } + +} +?> \ No newline at end of file diff --git a/inc/item_devicecamera.class.php b/inc/item_devicecamera.class.php new file mode 100644 index 0000000..81d8c67 --- /dev/null +++ b/inc/item_devicecamera.class.php @@ -0,0 +1,52 @@ +. + -------------------------------------------------------------------------- + */ + +// ---------------------------------------------------------------------- +// Original Author of file: +// Purpose of file: +// ---------------------------------------------------------------------- + +// Class of the defined type + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access directly to this file"); +} + +/** + * Relation between item and devices +**/ +class PluginExampleItem_DeviceCamera extends Item_Devices { + + static public $itemtype_2 = 'PluginExampleDeviceCamera'; + static public $items_id_2 = 'plugin_example_devicecameras_id'; + + static protected $notable = false; + +} +?> diff --git a/setup.php b/setup.php index 3ce6bae..775b51e 100755 --- a/setup.php +++ b/setup.php @@ -56,6 +56,9 @@ function plugin_init_example() { Plugin::registerClass('PluginExampleRuleTestCollection', array('rulecollections_types' => true)); + Plugin::registerClass('PluginExampleDeviceCamera', + array('device_types' => true)); + // Display a menu entry ? if (isset($_SESSION["glpi_plugin_example_profile"])) { // Right set in change_profile hook $PLUGIN_HOOKS['menu_toadd']['example'] = array('plugins' => 'PluginExampleExample',