neww hook for headings

git-svn-id: https://forge.glpi-project.org/svn/example/trunk@110 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
remicollet 2009-12-08 06:13:41 +00:00
parent d9c913419d
commit 2636ea6042

228
hook.php
View File

@ -502,135 +502,137 @@ function plugin_display_planning_example($parm){
} }
// Define headings added by the plugin // Define headings added by the plugin
function plugin_get_headings_example($type,$ID,$withtemplate){ function plugin_get_headings_example($item, $withtemplate){
switch ($type){ switch (get_class($item)){
case PROFILE_TYPE: case 'Profile':
$prof = new Profile(); $prof = new Profile();
if ($ID>0 && $prof->getFromDB($ID) && $prof->fields['interface']=='central') { if ($item->fields['interface']=='central') {
return array( return array(
1 => "Test PLugin", 1 => "Test PLugin",
); );
} else { } else {
return array(); return array();
} }
break; break;
case COMPUTER_TYPE : 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 { } else {
return array( return array(
1 => "Test PLugin", 1 => "Test PLugin",
); );
} }
break; break;
case COMPUTERDISK_TYPE : case 'ComputerDisk' :
case ENTERPRISE_TYPE : case 'Supplier' :
if ($ID>0) { // Not in create mode if ($item->getField('id')) { // Not in create mode
return array( return array(
1 => "Test PLugin", 1 => "Test PLugin",
2 => "Test PLugin 2", 2 => "Test PLugin 2",
); );
} }
break; break;
case "central": case 'Central':
return array( return array(
1 => "Test PLugin", 1 => "Test PLugin",
); );
break; break;
case "prefs": case 'Preference':
return array( return array(
1 => "Test PLugin", 1 => "Test PLugin",
); );
break; break;
case "mailing": case 'Notification':
return array( return array(
1 => "Test PLugin", 1 => "Test PLugin",
); );
break; break;
} }
return false; return false;
} }
// Define headings actions added by the plugin // Define headings actions added by the plugin
function plugin_headings_actions_example($type){ function plugin_headings_actions_example($item){
switch ($type){ switch (get_class($item)){
case PROFILE_TYPE : case 'Profile' :
case COMPUTER_TYPE : case 'Computer' :
return array( return array(
1 => "plugin_headings_example", 1 => "plugin_headings_example",
); );
break; break;
case COMPUTERDISK_TYPE : case 'ComputerDisk' :
case ENTERPRISE_TYPE : case 'Supplier' :
return array( return array(
1 => "plugin_headings_example", 1 => "plugin_headings_example",
2 => "plugin_headings_example", 2 => "plugin_headings_example",
); );
break; break;
case "central" : case 'Central' :
return array( return array(
1 => "plugin_headings_example", 1 => "plugin_headings_example",
); );
break; break;
case "prefs" : case 'Preference' :
return array( return array(
1 => "plugin_headings_example", 1 => "plugin_headings_example",
); );
break; break;
case "mailing" : case 'Notification' :
return array( return array(
1 => "plugin_headings_example", 1 => "plugin_headings_example",
); );
break; break;
} }
return false; return false;
} }
// Example of an action heading // Example of an action heading
function plugin_headings_example($type,$ID,$withtemplate=0){ function plugin_headings_example($item, $withtemplate=0){
global $LANG; global $LANG;
if (!$withtemplate){ if (!$withtemplate){
echo "<div align='center'>"; echo "<div align='center'>";
switch ($type){ switch (get_class($item)){
case "central": case 'Central':
echo "Plugin central action ".$LANG['plugin_example']["test"]; echo "Plugin central action ".$LANG['plugin_example']["test"];
break; break;
case "prefs":
// Complete form display
$data=plugin_version_example(); case 'Preference':
// Complete form display
$data=plugin_version_example();
echo "<form action='Where to post form'>"; echo "<form action='Where to post form'>";
echo "<table class='tab_cadre_fixe'>"; echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='3'>".$data['name']; echo "<tr><th colspan='3'>".$data['name'];
echo " - ".$data['version']; echo " - ".$data['version'];
echo "</th></tr>"; echo "</th></tr>";
echo "<tr class='tab_bg_1'><td>Name of the pref"; echo "<tr class='tab_bg_1'><td>Name of the pref";
echo "</td><td>Input to set the pref</td>"; echo "</td><td>Input to set the pref</td>";
echo "<td><input class='submit' type='submit' name='submit' value='submit'></td>"; echo "<td><input class='submit' type='submit' name='submit' value='submit'></td>";
echo "</tr>"; echo "</tr>";
echo "</table>"; echo "</table>";
echo "</form>"; echo "</form>";
break; break;
case "mailing":
echo "Plugin mailing action ".$LANG['plugin_example']["test"]; case 'Notification':
break; echo "Plugin mailing action ".$LANG['plugin_example']["test"];
default : break;
echo "Plugin function with headings TYPE=".$type." ID=".$ID;
break; default :
} echo "Plugin function with headings CLASS=".get_class($item)." ID=".$item->getField('id');
echo "</div>"; break;
} }
echo "</div>";
}
} }
/** /**