mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-05-04 18:08:42 +02:00
some work to work with 0.80 (cleandb)
git-svn-id: https://forge.glpi-project.org/svn/example/trunk@91 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
parent
760c7de79b
commit
c3b74fddcc
63
hook.php
63
hook.php
@ -62,14 +62,14 @@ function plugin_change_profile_example() {
|
||||
// Define dropdown relations
|
||||
function plugin_example_getDatabaseRelations(){
|
||||
//
|
||||
return array("glpi_dropdown_plugin_example"=>array("glpi_plugin_example"=>"FK_dropdown"));
|
||||
return array("glpi_plugin_example_dropdown"=>array("glpi_plugin_example"=>"plugin_example_dropdown_id"));
|
||||
}
|
||||
|
||||
|
||||
// Define Dropdown tables to be manage in GLPI :
|
||||
function plugin_example_getDropdown(){
|
||||
// Table => Name
|
||||
return array("glpi_dropdown_plugin_example"=>"Plugin Example Dropdown");
|
||||
return array("glpi_plugin_example_dropdown"=>"Plugin Example Dropdown");
|
||||
}
|
||||
|
||||
////// SEARCH FUNCTIONS ///////(){
|
||||
@ -87,9 +87,9 @@ function plugin_example_getSearchOption(){
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][1]['linkfield']='name';
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][1]['name']=$LANG['plugin_example']["name"];
|
||||
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][2]['table']='glpi_dropdown_plugin_example';
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][2]['table']='glpi_plugin_example_dropdown';
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][2]['field']='name';
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][2]['linkfield']='FK_dropdown';
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][2]['linkfield']='plugin_example_dropdown_id';
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][2]['name']='Dropdown';
|
||||
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][3]['table']='glpi_plugin_example';
|
||||
@ -99,7 +99,7 @@ function plugin_example_getSearchOption(){
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][3]['usehaving']=true;
|
||||
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][30]['table']='glpi_plugin_example';
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][30]['field']='ID';
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][30]['field']='id';
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][30]['linkfield']='';
|
||||
$sopt[PLUGIN_EXAMPLE_TYPE][30]['name']=$LANG["common"][2];
|
||||
|
||||
@ -114,9 +114,9 @@ function plugin_example_giveItem($type,$ID,$data,$num){
|
||||
|
||||
switch ($table.'.'.$field){
|
||||
case "glpi_plugin_example.name" :
|
||||
$out= "<a href=\"".$CFG_GLPI["root_doc"]."/".$INFOFORM_PAGES[$type]."?ID=".$data['ID']."\">";
|
||||
$out= "<a href=\"".$CFG_GLPI["root_doc"]."/".$INFOFORM_PAGES[$type]."?ID=".$data['id']."\">";
|
||||
$out.= $data["ITEM_$num"];
|
||||
if ($CFG_GLPI["view_ID"]||empty($data["ITEM_$num"])) $out.= " (".$data["ID"].")";
|
||||
if ($_SESSION["glpiis_ids_visible"]||empty($data["ITEM_$num"])) $out.= " (".$data["id"].")";
|
||||
$out.= "</a>";
|
||||
return $out;
|
||||
break;
|
||||
@ -129,8 +129,8 @@ function plugin_example_addLeftJoin($type,$ref_table,$new_table,$linkfield){
|
||||
// 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
|
||||
switch ($new_table){
|
||||
case "glpi_dropdown_plugin_example" :
|
||||
return " LEFT JOIN $new_table ON ($ref_table.$linkfield = $new_table.ID) ";
|
||||
case "glpi_plugin_example_dropdown" :
|
||||
return " LEFT JOIN $new_table ON ($ref_table.$linkfield = $new_table.id) ";
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
@ -331,7 +331,7 @@ function plugin_example_MassiveActionsFieldsDisplay($type,$table,$field,$linkfie
|
||||
} else {
|
||||
// Linked Fields
|
||||
switch ($table.".".$field){
|
||||
case "glpi_dropdown_plugin_example.name" :
|
||||
case "glpi_plugin_example_dropdown.name" :
|
||||
echo "Not really specific - Just for example ";
|
||||
dropdown($table,$linkfield,1,$_SESSION["glpiactive_entity"]);
|
||||
//dropdownUsers($linkfield,0,"own_ticket",0,1,$_SESSION["glpiactive_entity"]);
|
||||
@ -472,7 +472,7 @@ function plugin_item_restore_example($parm){
|
||||
// Hook done on restore item case
|
||||
function plugin_item_transfer_example($parm){
|
||||
|
||||
addMessageAfterRedirect("Transfer Computer Hook ".$parm['type']." ".$parm['ID']." -> ".$parm['newID']);
|
||||
addMessageAfterRedirect("Transfer Computer Hook ".$parm['type']." ".$parm['id']." -> ".$parm['newID']);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -696,41 +696,43 @@ function plugin_example_addParamFordynamicReport($device_type){
|
||||
// Install process for plugin : need to return true if succeeded
|
||||
function plugin_example_install(){
|
||||
global $DB;
|
||||
|
||||
|
||||
if (!TableExists("glpi_plugin_example")){
|
||||
$query="CREATE TABLE `glpi_plugin_example` (
|
||||
`ID` int(11) NOT NULL auto_increment,
|
||||
`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,
|
||||
`FK_dropdown` int(11) NOT NULL default '0',
|
||||
`deleted` smallint(6) NOT NULL default '0',
|
||||
`plugin_example_dropdown_id` int(11) NOT NULL default '0',
|
||||
`is_deleted` smallint(6) NOT NULL default '0',
|
||||
`is_template` smallint(6) NOT NULL default '0',
|
||||
`tplname` varchar(255) collate utf8_unicode_ci default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
`template_name` varchar(255) collate utf8_unicode_ci default NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
";
|
||||
$DB->query($query) or die("error creating glpi_plugin_example ". $DB->error());
|
||||
$query="INSERT INTO `glpi_plugin_example` (`ID`, `name`, `serial`, `FK_dropdown`, `deleted`, `is_template`, `tplname`) VALUES
|
||||
$query="INSERT INTO `glpi_plugin_example` (`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),
|
||||
(3, 'example 3', 'serial 3', 1, 0, 0, NULL);";
|
||||
$DB->query($query) or die("error populate glpi_plugin_example ". $DB->error());
|
||||
|
||||
}
|
||||
if (!TableExists("glpi_dropdown_plugin_example")){
|
||||
if (!TableExists("glpi_plugin_example_dropdown")){
|
||||
|
||||
$query="CREATE TABLE `glpi_dropdown_plugin_example` (
|
||||
`ID` int(11) NOT NULL auto_increment,
|
||||
$query="CREATE TABLE `glpi_plugin_example_dropdown` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`name` varchar(255) collate utf8_unicode_ci default NULL,
|
||||
`comments` text collate utf8_unicode_ci,
|
||||
PRIMARY KEY (`ID`),
|
||||
`comment` text collate utf8_unicode_ci,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `name` (`name`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
|
||||
|
||||
$DB->query($query) or die("error creating glpi_dropdown_plugin_example". $DB->error());
|
||||
$query="INSERT INTO `glpi_dropdown_plugin_example` (`ID`, `name`, `comments`) VALUES
|
||||
$DB->query($query) or die("error creating glpi_plugin_example_dropdown". $DB->error());
|
||||
$query="INSERT INTO `glpi_plugin_example_dropdown` (`id`, `name`, `comment`) VALUES
|
||||
(1, 'dp 1', 'comment 1'),
|
||||
(2, 'dp2', 'comment 2');";
|
||||
$DB->query($query) or die("error populate glpi_dropdown_plugin_example". $DB->error());
|
||||
$DB->query($query) or die("error populate glpi_plugin_example_dropdown". $DB->error());
|
||||
|
||||
}
|
||||
return true;
|
||||
@ -742,12 +744,17 @@ function plugin_example_uninstall(){
|
||||
|
||||
if (TableExists("glpi_plugin_example")){
|
||||
$query="DROP TABLE `glpi_plugin_example`;";
|
||||
$DB->query($query) or die("error creating glpi_plugin_example");
|
||||
$DB->query($query) or die("error deleting glpi_plugin_example");
|
||||
}
|
||||
if (TableExists("glpi_dropdown_plugin_example")){
|
||||
|
||||
$query="DROP TABLE `glpi_dropdown_plugin_example`;";
|
||||
$DB->query($query) or die("error creating glpi_dropdown_plugin_example");
|
||||
$DB->query($query) or die("error deleting glpi_dropdown_plugin_example");
|
||||
}
|
||||
if (TableExists("glpi_plugin_example_dropdown")){
|
||||
|
||||
$query="DROP TABLE `glpi_plugin_example_dropdown`;";
|
||||
$DB->query($query) or die("error deleting glpi_plugin_example_dropdown");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -135,20 +135,20 @@ function plugin_init_example() {
|
||||
function plugin_version_example(){
|
||||
return array(
|
||||
'name' => 'Plugin Example',
|
||||
'version' => '0.1.0',
|
||||
'version' => '0.2.0',
|
||||
'author' => 'Julien Dombre',
|
||||
'homepage'=> 'http://glpi-project.org',
|
||||
'minGlpiVersion' => '0.72',// For compatibility / no install in version < 0.72
|
||||
'minGlpiVersion' => '0.80',// For compatibility / no install in version < 0.72
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Optional : check prerequisites before install : may print errors or add to message after redirect
|
||||
function plugin_example_check_prerequisites(){
|
||||
if (GLPI_VERSION>=0.72){
|
||||
if (GLPI_VERSION>=0.80){
|
||||
return true;
|
||||
} else {
|
||||
echo "GLPI version not compatible need 0.72";
|
||||
echo "GLPI version not compatible need 0.80";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user