From 0ee472bd2ade80a3ae74a69f98352ffb37dbe419 Mon Sep 17 00:00:00 2001 From: remicollet Date: Wed, 16 Dec 2009 09:24:50 +0000 Subject: [PATCH] fix add hook + remove static in canView / canCreate git-svn-id: https://forge.glpi-project.org/svn/example/trunk@121 349b9182-4a13-0410-896f-e5e9767dd1b3 --- hook.php | 30 ++++++++++++++---------------- inc/example.class.php | 4 ++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/hook.php b/hook.php index 34fa9c1..49aeeec 100644 --- a/hook.php +++ b/hook.php @@ -351,29 +351,27 @@ function plugin_item_update_example($parm) { // Hook done on before add item case -function plugin_pre_item_add_example($input) { +function plugin_pre_item_add_example($item) { - if (isset($input["_item_type_"])) { - switch ($input["_item_type_"]) { - case 'Computer' : - // Manipulate data if needed - addMessageAfterRedirect("Pre Add Computer Hook",true); - break; - } + switch (get_class($item)) { + case 'Computer' : + // Manipulate data if needed + if (isset($item->input['comment'])) { + //$item->input['comment'] .= addslashes("\nFrom Example plugin"); + } + addMessageAfterRedirect("Pre Add Computer Hook",true); + break; } - return $input; } // Hook done on add item case -function plugin_item_add_example($parm) { +function plugin_item_add_example($item) { - if (isset($parm["type"])) { - switch ($parm["type"]) { - case 'Computer' : - addMessageAfterRedirect("Add Computer Hook",true); - return true; - } + switch (get_class($item)) { + case 'Computer' : + addMessageAfterRedirect("Add Computer Hook, ID=".$item->getField('id'),true); + return true; } return false; } diff --git a/inc/example.class.php b/inc/example.class.php index 00b4d77..8fa8fe0 100644 --- a/inc/example.class.php +++ b/inc/example.class.php @@ -45,14 +45,14 @@ class PluginExampleExample extends CommonDBTM { return 'Example Type'; } - static function canCreate() { + function canCreate() { if (isset($_SESSION["glpi_plugin_example_profile"])) { return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w'); } return false; } - static function canView() { + function canView() { if (isset($_SESSION["glpi_plugin_example_profile"])) { return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w' || $_SESSION["glpi_plugin_example_profile"]['example'] == 'r');