diff --git a/hook.php b/hook.php index d6994a2..26c5a74 100644 --- a/hook.php +++ b/hook.php @@ -502,135 +502,137 @@ function plugin_display_planning_example($parm){ } // Define headings added by the plugin -function plugin_get_headings_example($type,$ID,$withtemplate){ - switch ($type){ - case PROFILE_TYPE: - $prof = new Profile(); - if ($ID>0 && $prof->getFromDB($ID) && $prof->fields['interface']=='central') { - return array( - 1 => "Test PLugin", - ); - } else { - return array(); - } - break; - case COMPUTER_TYPE : - // new object / template case - if ($withtemplate) { - return array(); - // Non template case / editing an existing object - } else { - return array( - 1 => "Test PLugin", - ); - } - break; - case COMPUTERDISK_TYPE : - case ENTERPRISE_TYPE : - if ($ID>0) { // Not in create mode - return array( - 1 => "Test PLugin", - 2 => "Test PLugin 2", - ); - } - break; - case "central": - return array( - 1 => "Test PLugin", - ); - break; - case "prefs": - return array( - 1 => "Test PLugin", - ); - break; - case "mailing": - return array( - 1 => "Test PLugin", - ); - break; +function plugin_get_headings_example($item, $withtemplate){ + switch (get_class($item)){ + case 'Profile': + $prof = new Profile(); + if ($item->fields['interface']=='central') { + return array( + 1 => "Test PLugin", + ); + } else { + return array(); + } + break; + case 'Computer' : + // new object / template case + if ($withtemplate) { + return array(); + // Non template case / editing an existing object + } else { + return array( + 1 => "Test PLugin", + ); + } + break; + case 'ComputerDisk' : + case 'Supplier' : + if ($item->getField('id')) { // Not in create mode + return array( + 1 => "Test PLugin", + 2 => "Test PLugin 2", + ); + } + break; + case 'Central': + return array( + 1 => "Test PLugin", + ); + break; + case 'Preference': + return array( + 1 => "Test PLugin", + ); + break; + case 'Notification': + return array( + 1 => "Test PLugin", + ); + break; - } - return false; + } + return false; } // Define headings actions added by the plugin -function plugin_headings_actions_example($type){ +function plugin_headings_actions_example($item){ - switch ($type){ - case PROFILE_TYPE : - case COMPUTER_TYPE : - return array( - 1 => "plugin_headings_example", - ); + switch (get_class($item)){ + case 'Profile' : + case 'Computer' : + return array( + 1 => "plugin_headings_example", + ); - break; - case COMPUTERDISK_TYPE : - case ENTERPRISE_TYPE : - return array( - 1 => "plugin_headings_example", - 2 => "plugin_headings_example", - ); + break; + case 'ComputerDisk' : + case 'Supplier' : + return array( + 1 => "plugin_headings_example", + 2 => "plugin_headings_example", + ); - break; - case "central" : - return array( - 1 => "plugin_headings_example", - ); - break; - case "prefs" : - return array( - 1 => "plugin_headings_example", - ); - break; - case "mailing" : - return array( - 1 => "plugin_headings_example", - ); - break; + break; + case 'Central' : + return array( + 1 => "plugin_headings_example", + ); + break; + case 'Preference' : + return array( + 1 => "plugin_headings_example", + ); + break; + case 'Notification' : + return array( + 1 => "plugin_headings_example", + ); + break; - } - return false; + } + return false; } // Example of an action heading -function plugin_headings_example($type,$ID,$withtemplate=0){ - global $LANG; - if (!$withtemplate){ - echo "
"; - switch ($type){ - case "central": - echo "Plugin central action ".$LANG['plugin_example']["test"]; - break; - case "prefs": - // Complete form display +function plugin_headings_example($item, $withtemplate=0){ + global $LANG; + if (!$withtemplate){ + echo "
"; + switch (get_class($item)){ + case 'Central': + echo "Plugin central action ".$LANG['plugin_example']["test"]; + break; - $data=plugin_version_example(); + case 'Preference': + // Complete form display + $data=plugin_version_example(); - echo "
"; - echo ""; - echo ""; + echo ""; + echo "
".$data['name']; - echo " - ".$data['version']; - echo "
"; + echo ""; - echo ""; + echo ""; - echo ""; - echo ""; + echo ""; + echo ""; - echo "
".$data['name']; + echo " - ".$data['version']; + echo "
Name of the pref"; - echo "Input to set the pref
Name of the pref"; + echo "Input to set the pref
"; - echo "
"; - break; - case "mailing": - echo "Plugin mailing action ".$LANG['plugin_example']["test"]; - break; - default : - echo "Plugin function with headings TYPE=".$type." ID=".$ID; - break; - } - echo "
"; - } + echo ""; + echo ""; + break; + + case 'Notification': + echo "Plugin mailing action ".$LANG['plugin_example']["test"]; + break; + + default : + echo "Plugin function with headings CLASS=".get_class($item)." ID=".$item->getField('id'); + break; + } + echo "
"; + } } /**