CS + call functions

git-svn-id: https://forge.glpi-project.org/svn/example/trunk@172 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
yllen 2011-09-08 09:51:40 +00:00
parent 6188cf8ad0
commit acf0490727
6 changed files with 90 additions and 81 deletions

View File

@ -63,6 +63,8 @@ function plugin_example_getDropdown() {
return array('PluginExampleDropdown' => "Plugin Example Dropdown"); return array('PluginExampleDropdown' => "Plugin Example Dropdown");
} }
////// SEARCH FUNCTIONS ///////(){ ////// SEARCH FUNCTIONS ///////(){
// Define Additionnal search options for types (other than the plugin ones) // Define Additionnal search options for types (other than the plugin ones)
@ -100,23 +102,23 @@ function plugin_example_giveItem($type,$ID,$data,$num) {
return ""; return "";
} }
function plugin_example_displayConfigItem($type, $ID, $data, $num) { function plugin_example_displayConfigItem($type, $ID, $data, $num) {
$searchopt = &Search::getOptions($type); $searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"]; $table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"]; $field = $searchopt[$ID]["field"];
// Example of specific style options // Example of specific style options
// No need of the function if you do not have specific cases // No need of the function if you do not have specific cases
switch ($table.'.'.$field) { switch ($table.'.'.$field) {
case "glpi_plugin_example_examples.name" : case "glpi_plugin_example_examples.name" :
return " style=\"background-color:#DDDDDD;\" "; return " style=\"background-color:#DDDDDD;\" ";
break;
} }
return ""; return "";
} }
function plugin_example_addDefaultJoin($type, $ref_table, &$already_link_tables) { function plugin_example_addDefaultJoin($type, $ref_table, &$already_link_tables) {
// Example of default JOIN clause // Example of default JOIN clause
@ -125,12 +127,12 @@ function plugin_example_addDefaultJoin($type, $ref_table, &$already_link_tables)
// case "PluginExampleExample" : // case "PluginExampleExample" :
case "MyType" : case "MyType" :
return Search::addLeftJoin($type, $ref_table, $already_link_tables, return Search::addLeftJoin($type, $ref_table, $already_link_tables,
"newtable", "linkfield"); "newtable", "linkfield");
break;
} }
return ""; return "";
} }
function plugin_example_addDefaultSelect($type) { function plugin_example_addDefaultSelect($type) {
// Example of default SELECT item to be added // Example of default SELECT item to be added
@ -139,11 +141,11 @@ function plugin_example_addDefaultSelect($type) {
// case "PluginExampleExample" : // case "PluginExampleExample" :
case "MyType" : case "MyType" :
return "`mytable`.`myfield` = 'myvalue' AS MYNAME, "; return "`mytable`.`myfield` = 'myvalue' AS MYNAME, ";
break;
} }
return ""; return "";
} }
function plugin_example_addDefaultWhere($type) { function plugin_example_addDefaultWhere($type) {
// Example of default WHERE item to be added // Example of default WHERE item to be added
@ -152,13 +154,12 @@ function plugin_example_addDefaultWhere($type) {
// case "PluginExampleExample" : // case "PluginExampleExample" :
case "MyType" : case "MyType" :
return " `mytable`.`myfield` = 'myvalue' "; return " `mytable`.`myfield` = 'myvalue' ";
break;
} }
return ""; return "";
} }
function plugin_example_addLeftJoin($type,$ref_table,$new_table,$linkfield) { function plugin_example_addLeftJoin($type, $ref_table, $new_table, $linkfield) {
// Example of standard LEFT JOIN clause but use it ONLY for specific LEFT JOIN // Example of standard LEFT JOIN clause but use it ONLY for specific LEFT JOIN
// No need of the function if you do not have specific cases // No need of the function if you do not have specific cases
@ -184,8 +185,8 @@ function plugin_example_forceGroupBy($type) {
function plugin_example_addWhere($link,$nott,$type,$ID,$val) { function plugin_example_addWhere($link,$nott,$type,$ID,$val) {
$searchopt = &Search::getOptions($type); $searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"]; $table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"]; $field = $searchopt[$ID]["field"];
$SEARCH = Search::makeTextSearch($val,$nott); $SEARCH = Search::makeTextSearch($val,$nott);
@ -206,11 +207,11 @@ function plugin_example_addWhere($link,$nott,$type,$ID,$val) {
// This is not a real example because the use of Having condition in this case is not suitable // This is not a real example because the use of Having condition in this case is not suitable
function plugin_example_addHaving($link,$nott,$type,$ID,$val,$num) { function plugin_example_addHaving($link, $nott, $type, $ID, $val, $num) {
$searchopt = &Search::getOptions($type); $searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"]; $table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"]; $field = $searchopt[$ID]["field"];
$SEARCH = Search::makeTextSearch($val,$nott); $SEARCH = Search::makeTextSearch($val,$nott);
@ -232,8 +233,8 @@ function plugin_example_addHaving($link,$nott,$type,$ID,$val,$num) {
function plugin_example_addSelect($type,$ID,$num) { function plugin_example_addSelect($type,$ID,$num) {
$searchopt = &Search::getOptions($type); $searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"]; $table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"]; $field = $searchopt[$ID]["field"];
// Example of standard Select clause but use it ONLY for specific Select // Example of standard Select clause but use it ONLY for specific Select
// No need of the function if you do not have specific cases // No need of the function if you do not have specific cases
@ -248,8 +249,8 @@ function plugin_example_addSelect($type,$ID,$num) {
function plugin_example_addOrderBy($type,$ID,$order,$key=0) { function plugin_example_addOrderBy($type,$ID,$order,$key=0) {
$searchopt = &Search::getOptions($type); $searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"]; $table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"]; $field = $searchopt[$ID]["field"];
// Example of standard OrderBy clause but use it ONLY for specific order by // Example of standard OrderBy clause but use it ONLY for specific order by
// No need of the function if you do not have specific cases // No need of the function if you do not have specific cases
@ -291,9 +292,9 @@ function plugin_example_MassiveActionsDisplay($options=array()) {
case 'Computer' : case 'Computer' :
switch ($options['action']) { switch ($options['action']) {
case "plugin_example_DoIt" : case "plugin_example_DoIt" :
echo "&nbsp;<input type='hidden' name='toto' value='1'>".
echo "&nbsp;<input type='hidden' name='toto' value='1'><input type='submit' name='massiveaction' class='submit' value='". "<input type='submit' name='massiveaction' class='submit' value='".
$LANG["buttons"][2]."'>&nbsp;but do nothing :)"; $LANG["buttons"][2]."'>&nbsp;but do nothing :)";
break; break;
} }
break; break;
@ -319,13 +320,13 @@ function plugin_example_MassiveActionsProcess($data) {
switch ($data['action']) { switch ($data['action']) {
case 'plugin_example_DoIt' : case 'plugin_example_DoIt' :
if ($data['itemtype'] == 'Computer') { if ($data['itemtype'] == 'Computer') {
$comp = new Computer; $comp = new Computer();
addMessageAfterRedirect("Right it is the type I want..."); Session::addMessageAfterRedirect("Right it is the type I want...");
addMessageAfterRedirect("But... I say I will do nothing for :"); Session::addMessageAfterRedirect("But... I say I will do nothing for :");
foreach ($data['item'] as $key => $val) { foreach ($data['item'] as $key => $val) {
if ($val == 1) { if ($val == 1) {
if ($comp->getFromDB($key)) { if ($comp->getFromDB($key)) {
addMessageAfterRedirect("- ".$comp->getField("name")); Session::addMessageAfterRedirect("- ".$comp->getField("name"));
} }
} }
} }
@ -335,12 +336,12 @@ function plugin_example_MassiveActionsProcess($data) {
case 'do_nothing' : case 'do_nothing' :
if ($data['itemtype'] == 'PluginExampleExample') { if ($data['itemtype'] == 'PluginExampleExample') {
$ex = new PluginExampleExample(); $ex = new PluginExampleExample();
addMessageAfterRedirect("Right it is the type I want..."); Session::addMessageAfterRedirect("Right it is the type I want...");
addMessageAfterRedirect("But... I say I will do nothing for :"); Session::addMessageAfterRedirect("But... I say I will do nothing for :");
foreach ($data['item'] as $key => $val) { foreach ($data['item'] as $key => $val) {
if ($val == 1) { if ($val == 1) {
if ($ex->getFromDB($key)) { if ($ex->getFromDB($key)) {
addMessageAfterRedirect("- ".$ex->getField("name")); Session::addMessageAfterRedirect("- ".$ex->getField("name"));
} }
} }
} }
@ -355,11 +356,11 @@ function plugin_example_MassiveActionsProcess($data) {
function plugin_example_MassiveActionsFieldsDisplay($options=array()) { function plugin_example_MassiveActionsFieldsDisplay($options=array()) {
//$type,$table,$field,$linkfield //$type,$table,$field,$linkfield
$table = $options['options']['table']; $table = $options['options']['table'];
$field = $options['options']['field']; $field = $options['options']['field'];
$linkfield = $options['options']['linkfield']; $linkfield = $options['options']['linkfield'];
if ($table == getTableForItemType($options['itemtype'])) {
if ($table == getTableForItemType($options['itemtype'])) {
// Table fields // Table fields
switch ($table.".".$field) { switch ($table.".".$field) {
case 'glpi_plugin_example_examples.serial' : case 'glpi_plugin_example_examples.serial' :
@ -383,6 +384,7 @@ function plugin_example_MassiveActionsFieldsDisplay($options=array()) {
return false; return false;
} }
// How to display specific search fields or dropdown ? // How to display specific search fields or dropdown ?
// options must contain at least itemtype and options array // options must contain at least itemtype and options array
// MUST Use a specific AddWhere & $tab[X]['searchtype'] = 'equals'; declaration // MUST Use a specific AddWhere & $tab[X]['searchtype'] = 'equals'; declaration
@ -394,13 +396,12 @@ function plugin_example_searchOptionsValues($options=array()) {
// Table fields // Table fields
switch ($table.".".$field) { switch ($table.".".$field) {
case "glpi_plugin_example_examples.serial" : case "glpi_plugin_example_examples.serial" :
echo "Not really specific - Use your own dropdown - Just for example&nbsp;"; echo "Not really specific - Use your own dropdown - Just for example&nbsp;";
Dropdown::show(getItemTypeForTable($options['searchoption']['table']), Dropdown::show(getItemTypeForTable($options['searchoption']['table']),
array('value' => $options['value'], array('value' => $options['value'],
'name' => $options['name'], 'name' => $options['name'],
'comments' => 0)); 'comments' => 0));
// Need to return true if specific display // Need to return true if specific display
return true; return true;
} }
@ -419,17 +420,18 @@ function plugin_pre_item_update_example($item) {
} }
$item->input['comment'] .= addslashes("\nUpdate: ".date('r')); $item->input['comment'] .= addslashes("\nUpdate: ".date('r'));
*/ */
Session::addMessageAfterRedirect("Pre Update Computer Hook",true); Session::addMessageAfterRedirect("Pre Update Computer Hook", true);
} }
// Hook done on update item case // Hook done on update item case
function plugin_item_update_example($item) { function plugin_item_update_example($item) {
Session::addMessageAfterRedirect("Update Computer Hook (".implode(',',$item->updates).")",true); Session::addMessageAfterRedirect("Update Computer Hook (".implode(',',$item->updates).")", true);
return true; return true;
} }
// Hook done on get empty item case // Hook done on get empty item case
function plugin_item_empty_example($item) { function plugin_item_empty_example($item) {
@ -485,6 +487,7 @@ function plugin_pre_item_restore_example2($item) {
Session::addMessageAfterRedirect("Pre Restore Phone Hook"); Session::addMessageAfterRedirect("Pre Restore Phone Hook");
} }
// Hook done on restore item case // Hook done on restore item case
function plugin_item_restore_example($item) { function plugin_item_restore_example($item) {
@ -497,7 +500,7 @@ function plugin_item_restore_example($item) {
function plugin_item_transfer_example($parm) { function plugin_item_transfer_example($parm) {
Session::addMessageAfterRedirect("Transfer Computer Hook ".$parm['type']." ".$parm['id']." -> ". Session::addMessageAfterRedirect("Transfer Computer Hook ".$parm['type']." ".$parm['id']." -> ".
$parm['newID']); $parm['newID']);
return false; return false;
} }
@ -532,14 +535,14 @@ function plugin_display_planning_example($parm) {
// Add items in the items fields of the parm array // Add items in the items fields of the parm array
switch ($parm["type"]) { switch ($parm["type"]) {
case "in" : case "in" :
echo date("H:i",strtotime($parm["begin"]))." -> ".date("H:i",strtotime($parm["end"])).": "; echo date("H:i",strtotime($parm["begin"]))." -> ".date("H:i", strtotime($parm["end"])).": ";
break; break;
case "from" : case "from" :
break; break;
case "begin" : case "begin" :
echo $LANG["buttons"][33]." ".date("H:i",strtotime($parm["begin"])).": "; echo $LANG["buttons"][33]." ".date("H:i", strtotime($parm["begin"])).": ";
break; break;
case "end" : case "end" :
@ -558,18 +561,16 @@ function plugin_get_headings_example($item, $withtemplate) {
$prof = new Profile(); $prof = new Profile();
if ($item->fields['interface'] == 'central') { if ($item->fields['interface'] == 'central') {
return array(1 => "Test PLugin"); return array(1 => "Test PLugin");
} else {
return array();
} }
return array();
case 'Computer' : case 'Computer' :
// new object / template case // new object / template case
if ($withtemplate) { if ($withtemplate) {
return array(); return array();
// Non template case / editing an existing object // Non template case / editing an existing object
} else {
return array(1 => "Test PLugin");
} }
return array(1 => "Test PLugin");
case 'ComputerDisk' : case 'ComputerDisk' :
case 'Supplier' : case 'Supplier' :
@ -679,7 +680,7 @@ function plugin_example_addParamFordynamicReport($itemtype) {
// Return array data containing all params to add : may be single data or array data // Return array data containing all params to add : may be single data or array data
// Search config are available from session variable // Search config are available from session variable
return array('add1' => $_SESSION['glpisearch'][$itemtype]['order'], return array('add1' => $_SESSION['glpisearch'][$itemtype]['order'],
'add2' => array('tutu'=>'Second Add', 'add2' => array('tutu' => 'Second Add',
'Other Data')); 'Other Data'));
} }
// Return false or a non array data if not needed // Return false or a non array data if not needed
@ -781,14 +782,17 @@ function plugin_example_AssignToTicket($types) {
return $types; return $types;
} }
function plugin_example_get_events(NotificationTargetTicket $target) { function plugin_example_get_events(NotificationTargetTicket $target) {
$target->events['plugin_example'] = "Example event"; $target->events['plugin_example'] = "Example event";
} }
function plugin_example_get_datas(NotificationTargetTicket $target) { function plugin_example_get_datas(NotificationTargetTicket $target) {
$target->datas['##ticket.example##'] = "Example datas"; $target->datas['##ticket.example##'] = "Example datas";
} }
function plugin_example_postinit() { function plugin_example_postinit() {
global $CFG_GLPI; global $CFG_GLPI;

View File

@ -36,23 +36,24 @@
// Class of the defined type // Class of the defined type
class PluginExampleExample extends CommonDBTM { class PluginExampleExample extends CommonDBTM {
// From CommonDBTM
public $table = 'glpi_plugin_example_examples';
public $type = 'PluginExampleExample';
// Should return the localized name of the type // Should return the localized name of the type
static function getTypeName() { static function getTypeName() {
return 'Example Type'; return 'Example Type';
} }
function canCreate() { function canCreate() {
if (isset($_SESSION["glpi_plugin_example_profile"])) { if (isset($_SESSION["glpi_plugin_example_profile"])) {
return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w'); return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w');
} }
return false; return false;
} }
function canView() { function canView() {
if (isset($_SESSION["glpi_plugin_example_profile"])) { if (isset($_SESSION["glpi_plugin_example_profile"])) {
return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w' return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w'
|| $_SESSION["glpi_plugin_example_profile"]['example'] == 'r'); || $_SESSION["glpi_plugin_example_profile"]['example'] == 'r');
@ -60,6 +61,7 @@ class PluginExampleExample extends CommonDBTM {
return false; return false;
} }
function getSearchOptions() { function getSearchOptions() {
global $LANG; global $LANG;
@ -87,6 +89,7 @@ class PluginExampleExample extends CommonDBTM {
return $tab; return $tab;
} }
/** /**
* Give localized information about 1 task * Give localized information about 1 task
* *
@ -105,6 +108,7 @@ class PluginExampleExample extends CommonDBTM {
return array(); return array();
} }
/** /**
* Execute 1 task manage by the plugin * Execute 1 task manage by the plugin
* *
@ -123,16 +127,17 @@ class PluginExampleExample extends CommonDBTM {
return 1; return 1;
} }
// Hook done on before add item case // Hook done on before add item case
static function pre_item_add_example($item) { static function pre_item_add_example($item) {
addMessageAfterRedirect("Pre Add Computer Hook",true); Session::addMessageAfterRedirect("Pre Add Computer Hook", true);
} }
// Hook done on add item case // Hook done on add item case
static function item_add_example($item) { static function item_add_example($item) {
addMessageAfterRedirect("Add Computer Hook, ID=".$item->getField('id'),true); Session::addMessageAfterRedirect("Add Computer Hook, ID=".$item->getField('id'), true);
return true; return true;
} }

View File

@ -36,7 +36,6 @@ if (!defined('GLPI_ROOT')){
class PluginExampleNotificationTargetExample extends NotificationTarget { class PluginExampleNotificationTargetExample extends NotificationTarget {
function getEvents() { function getEvents() {
global $LANG;
return array ('alert' => 'alert example'); return array ('alert' => 'alert example');
} }

View File

@ -47,21 +47,23 @@ if (!defined('GLPI_ROOT')) {
class PluginExampleRuleTest extends Rule { class PluginExampleRuleTest extends Rule {
// From Rule // From Rule
public $right='rule_ocs'; public $right = 'rule_ocs';
public $can_sort=true; public $can_sort = true;
function getTitle() { function getTitle() {
global $LANG;
return 'test'; return 'test';
} }
function maxActionsCount() { function maxActionsCount() {
return 1; return 1;
} }
function getCriterias() { function getCriterias() {
global $LANG; global $LANG;
$criterias = array(); $criterias = array();
$criterias['name']['field'] = 'name'; $criterias['name']['field'] = 'name';
$criterias['name']['name'] = $LANG['help'][31]; $criterias['name']['name'] = $LANG['help'][31];
@ -70,8 +72,10 @@ class PluginExampleRuleTest extends Rule {
return $criterias; return $criterias;
} }
function getActions() { function getActions() {
global $LANG; global $LANG;
$actions = array(); $actions = array();
$actions['softwarecategories_id']['name'] = $LANG['common'][36]; $actions['softwarecategories_id']['name'] = $LANG['common'][36];
$actions['softwarecategories_id']['type'] = 'dropdown'; $actions['softwarecategories_id']['type'] = 'dropdown';
@ -79,5 +83,4 @@ class PluginExampleRuleTest extends Rule {
return $actions; return $actions;
} }
} }
?> ?>

View File

@ -40,15 +40,12 @@ if (!defined('GLPI_ROOT')) {
class PluginExampleRuleTestCollection extends RuleCollection { class PluginExampleRuleTestCollection extends RuleCollection {
// From RuleCollection // From RuleCollection
public $stop_on_first_match=true; public $stop_on_first_match = true;
public $right='rule_ocs'; public $right = 'rule_ocs';
public $menu_option='test'; public $menu_option = 'test';
function getTitle() { function getTitle() {
global $LANG;
return 'Rulesengine test'; return 'Rulesengine test';
} }
} }
?> ?>

View File

@ -51,16 +51,16 @@ function plugin_init_example() {
'addtabon' => array('Phone'))); 'addtabon' => array('Phone')));
Plugin::registerClass('PluginExampleRuleTestCollection', Plugin::registerClass('PluginExampleRuleTestCollection',
array('rulecollections_types' => true)); array('rulecollections_types' => true));
// Display a menu entry ? // Display a menu entry ?
if (isset($_SESSION["glpi_plugin_example_profile"])) { // Right set in change_profile hook if (isset($_SESSION["glpi_plugin_example_profile"])) { // Right set in change_profile hook
$PLUGIN_HOOKS['menu_entry']['example'] = 'front/example.php'; $PLUGIN_HOOKS['menu_entry']['example'] = 'front/example.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['title'] = "Search"; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['title'] = "Search";
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['page'] = '/plugins/example/front/example.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['page'] = '/plugins/example/front/example.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['search'] = '/plugins/example/front/example.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['search'] = '/plugins/example/front/example.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['add'] = '/plugins/example/front/example.form.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['add'] = '/plugins/example/front/example.form.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['config'] = '/plugins/example/index.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['config'] = '/plugins/example/index.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']["<img src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".$LANG['plugin_example']["test"]."' alt='".$LANG['plugin_example']["test"]."'>"] = '/plugins/example/index.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']["<img src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".$LANG['plugin_example']["test"]."' alt='".$LANG['plugin_example']["test"]."'>"] = '/plugins/example/index.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links'][$LANG['plugin_example']["test"]] = '/plugins/example/index.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links'][$LANG['plugin_example']["test"]] = '/plugins/example/index.php';
@ -85,10 +85,10 @@ function plugin_init_example() {
$PLUGIN_HOOKS['headings_action']['example'] = 'plugin_headings_actions_example'; $PLUGIN_HOOKS['headings_action']['example'] = 'plugin_headings_actions_example';
// Item action event // See define.php for defined ITEM_TYPE // Item action event // See define.php for defined ITEM_TYPE
$PLUGIN_HOOKS['pre_item_update']['example'] = array('Computer'=>'plugin_pre_item_update_example'); $PLUGIN_HOOKS['pre_item_update']['example'] = array('Computer' => 'plugin_pre_item_update_example');
$PLUGIN_HOOKS['item_update']['example'] = array('Computer'=>'plugin_item_update_example'); $PLUGIN_HOOKS['item_update']['example'] = array('Computer' => 'plugin_item_update_example');
$PLUGIN_HOOKS['item_empty']['example'] = array('Computer'=>'plugin_item_empty_example'); $PLUGIN_HOOKS['item_empty']['example'] = array('Computer' => 'plugin_item_empty_example');
// Example using a method in class // Example using a method in class
$PLUGIN_HOOKS['pre_item_add']['example'] = array('Computer' => array('PluginExampleExample', $PLUGIN_HOOKS['pre_item_add']['example'] = array('Computer' => array('PluginExampleExample',
@ -96,26 +96,28 @@ function plugin_init_example() {
$PLUGIN_HOOKS['item_add']['example'] = array('Computer' => array('PluginExampleExample', $PLUGIN_HOOKS['item_add']['example'] = array('Computer' => array('PluginExampleExample',
'item_add_example')); 'item_add_example'));
$PLUGIN_HOOKS['pre_item_delete']['example'] = array('Computer'=>'plugin_pre_item_delete_example'); $PLUGIN_HOOKS['pre_item_delete']['example'] = array('Computer' => 'plugin_pre_item_delete_example');
$PLUGIN_HOOKS['item_delete']['example'] = array('Computer'=>'plugin_item_delete_example'); $PLUGIN_HOOKS['item_delete']['example'] = array('Computer' => 'plugin_item_delete_example');
// Example using the same function // Example using the same function
$PLUGIN_HOOKS['pre_item_purge']['example'] = array('Computer'=>'plugin_pre_item_purge_example', $PLUGIN_HOOKS['pre_item_purge']['example'] = array('Computer' => 'plugin_pre_item_purge_example',
'Phone'=>'plugin_pre_item_purge_example'); 'Phone' => 'plugin_pre_item_purge_example');
$PLUGIN_HOOKS['item_purge']['example'] = array('Computer'=>'plugin_item_purge_example', $PLUGIN_HOOKS['item_purge']['example'] = array('Computer' => 'plugin_item_purge_example',
'Phone'=>'plugin_item_purge_example'); 'Phone' => 'plugin_item_purge_example');
// Example with 2 different functions // Example with 2 different functions
$PLUGIN_HOOKS['pre_item_restore']['example'] = array('Computer'=>'plugin_pre_item_restore_example', $PLUGIN_HOOKS['pre_item_restore']['example'] = array('Computer' => 'plugin_pre_item_restore_example',
'Phone'=>'plugin_pre_item_restore_example2'); 'Phone' => 'plugin_pre_item_restore_example2');
$PLUGIN_HOOKS['item_restore']['example'] = array('Computer'=>'plugin_item_restore_example'); $PLUGIN_HOOKS['item_restore']['example'] = array('Computer' => 'plugin_item_restore_example');
// Add event to GLPI core itemtype, event will be raised by the plugin. // Add event to GLPI core itemtype, event will be raised by the plugin.
// See plugin_example_uninstall for cleanup of notification // See plugin_example_uninstall for cleanup of notification
$PLUGIN_HOOKS['item_get_events']['example'] = array('NotificationTargetTicket'=>'plugin_example_get_events'); $PLUGIN_HOOKS['item_get_events']['example']
= array('NotificationTargetTicket' => 'plugin_example_get_events');
// Add datas to GLPI core itemtype for notifications template. // Add datas to GLPI core itemtype for notifications template.
$PLUGIN_HOOKS['item_get_datas']['example'] = array('NotificationTargetTicket'=>'plugin_example_get_datas'); $PLUGIN_HOOKS['item_get_datas']['example']
= array('NotificationTargetTicket' => 'plugin_example_get_datas');
$PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example'; $PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example';
@ -188,11 +190,10 @@ function plugin_example_check_config($verbose=false) {
if (true) { // Your configuration check if (true) { // Your configuration check
return true; return true;
} }
if ($verbose) { if ($verbose) {
echo $LANG['plugins'][2]; echo $LANG['plugins'][2];
} }
return false; return false;
} }
?> ?>