git-svn-id: https://forge.glpi-project.org/svn/example/trunk@113 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
remicollet 2009-12-12 07:17:01 +00:00
parent f33753092c
commit 89d7d18237
3 changed files with 36 additions and 36 deletions

View File

@ -83,15 +83,14 @@ function plugin_example_getAddSearchOptions($itemtype){
}
function plugin_example_giveItem($type,$ID,$data,$num){
global $CFG_GLPI, $INFOFORM_PAGES;
$searchopt=&Search::getOptions($type);
$table=$searchopt[$ID]["table"];
$field=$searchopt[$ID]["field"];
switch ($table.'.'.$field){
case "glpi_plugin_example_example.name" :
$out= "<a href=\"".$CFG_GLPI["root_doc"]."/".$INFOFORM_PAGES[$type]."?id=".$data['id']."\">";
case "glpi_plugin_example_examples.name" :
$out= "<a href=\"".getItemTypeFormURL('PluginExampleExample')."?id=".$data['id']."\">";
$out.= $data["ITEM_$num"];
if ($_SESSION["glpiis_ids_visible"]||empty($data["ITEM_$num"])) $out.= " (".$data["id"].")";
$out.= "</a>";
@ -261,28 +260,28 @@ function plugin_example_MassiveActionsProcess($data){
switch ($data['action']){
case 'plugin_example_DoIt':
if ($data['device_type']==COMPUTER_TYPE){
$ci =new CommonItem();
if ($data['itemtype']=='Computer'){
$comp = new Computer;
addMessageAfterRedirect("Right it is the type I want...");
addMessageAfterRedirect("But... I say I will do nothing for :");
foreach ($data['item'] as $key => $val){
if ($val==1) {
if ($ci->getFromDB($data["device_type"],$key)){
addMessageAfterRedirect("- ".$ci->getField("name"));
if ($comp->getFromDB($key)){
addMessageAfterRedirect("- ".$comp->getField("name"));
}
}
}
}
break;
case 'do_nothing':
if ($data['device_type']=='PluginExampleExample'){
$ci =new CommonItem();
if ($data['itemtype']=='PluginExampleExample'){
$ex =new PluginExampleExample();
addMessageAfterRedirect("Right it is the type I want...");
addMessageAfterRedirect("But... I say I will do nothing for :");
foreach ($data['item'] as $key => $val){
if ($val==1) {
if ($ci->getFromDB($data["device_type"],$key)){
addMessageAfterRedirect("- ".$ci->getField("name"));
if ($ex->getFromDB($key)){
addMessageAfterRedirect("- ".$ex->getField("name"));
}
}
}
@ -292,8 +291,8 @@ function plugin_example_MassiveActionsProcess($data){
}
// How to display specific update fields ?
function plugin_example_MassiveActionsFieldsDisplay($type,$table,$field,$linkfield){
global $LINK_ID_TABLE;
if ($table==$LINK_ID_TABLE[$type]){
if ($table==getTableForItemType($type)){
// Table fields
switch ($table.".".$field){
case 'glpi_plugin_example.serial':
@ -703,8 +702,8 @@ function plugin_example_install(){
global $DB;
if (!TableExists("glpi_plugin_example_example")){
$query="CREATE TABLE `glpi_plugin_example_example` (
if (!TableExists("glpi_plugin_example_examples")){
$query="CREATE TABLE `glpi_plugin_example_examples` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`serial` varchar(255) collate utf8_unicode_ci NOT NULL,
@ -715,8 +714,8 @@ function plugin_example_install(){
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
";
$DB->query($query) or die("error creating glpi_plugin_example_example ". $DB->error());
$query="INSERT INTO `glpi_plugin_example_example` (`id`, `name`, `serial`, `plugin_example_dropdown_id`,
$DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error());
$query="INSERT INTO `glpi_plugin_example_examples` (`id`, `name`, `serial`, `plugin_example_dropdown_id`,
`is_deleted`, `is_template`, `template_name`) VALUES
(1, 'example 1', 'serial 1', 1, 0, 0, NULL),
(2, 'example 2', 'serial 2', 2, 0, 0, NULL),

View File

@ -37,7 +37,7 @@
class PluginExampleExample extends CommonDBTM {
// From CommonDBTM
public $table = 'glpi_plugin_example_example';
public $table = 'glpi_plugin_example_examples';
public $type = 'PluginExampleExample';
// Should return the localized name of the type
@ -47,13 +47,28 @@ class PluginExampleExample extends CommonDBTM {
return 'Example Type';
}
static function canCreate() {
if (isset($_SESSION["glpi_plugin_example_profile"])) {
return ($_SESSION["glpi_plugin_example_profile"]['example']=='w');
}
return false;
}
static function canView() {
if (isset($_SESSION["glpi_plugin_example_profile"])) {
return ($_SESSION["glpi_plugin_example_profile"]['example']=='w'
|| $_SESSION["glpi_plugin_example_profile"]['example']=='r');
}
return false;
}
function getSearchOptions() {
global $LANG;
$tab = array();
$tab['common']="Header Needed";
$tab[1]['table']='glpi_plugin_example_example';
$tab[1]['table']='glpi_plugin_example_examples';
$tab[1]['field']='name';
$tab[1]['linkfield']='name';
$tab[1]['name']=$LANG['plugin_example']["name"];
@ -63,13 +78,13 @@ class PluginExampleExample extends CommonDBTM {
$tab[2]['linkfield']='plugin_example_dropdown_id';
$tab[2]['name']='Dropdown';
$tab[3]['table']='glpi_plugin_example_example';
$tab[3]['table']='glpi_plugin_example_examples';
$tab[3]['field']='serial';
$tab[3]['linkfield']='serial';
$tab[3]['name']='Serial';
$tab[3]['usehaving']=true;
$tab[30]['table']='glpi_plugin_example_example';
$tab[30]['table']='glpi_plugin_example_examples';
$tab[30]['field']='id';
$tab[30]['linkfield']='';
$tab[30]['name']=$LANG["common"][2];

View File

@ -61,7 +61,7 @@ function plugin_init_example() {
'searchpage' => 'front/dropdown.php'));
// Display a menu entry ?
if (plugin_example_haveTypeRight('PluginExampleExample','r')) { // 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['submenu_entry']['example']['options']['optionname']['title']="Search";
@ -176,19 +176,5 @@ function plugin_example_check_config($verbose=false){
return false;
}
// Define rights for the plugin types
function plugin_example_haveTypeRight($type,$right){
if (!isset($_SESSION["glpi_plugin_example_profile"])) {
// No right
return false;
}
switch ($type){
case 'PluginExampleExample' :
// Evaluate the right from data saved in session by change_profile hook
return ($right=='r' || $_SESSION["glpi_plugin_example_profile"]=='w');
}
}
?>