From 2348817b184e3230ade45b27349d62ad887c584f Mon Sep 17 00:00:00 2001 From: moyooo Date: Fri, 18 May 2007 21:01:28 +0000 Subject: [PATCH] New search system git-svn-id: https://forge.glpi-project.org/svn/example/trunk@23 349b9182-4a13-0410-896f-e5e9767dd1b3 --- db.sql | 3 ++ index.php | 27 +++++++---- locales/en_GB.php | 1 + locales/fr_FR.php | 1 + setup.php | 119 ++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 136 insertions(+), 15 deletions(-) diff --git a/db.sql b/db.sql index 66e4367..6d76562 100644 --- a/db.sql +++ b/db.sql @@ -2,6 +2,9 @@ CREATE TABLE `glpi_plugin_example` ( `ID` int(11) NOT NULL, `name` varchar(255) collate utf8_unicode_ci default NULL, `FK_dropdown` int(11) NOT NULL default '0', + `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`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/index.php b/index.php index 5f6efde..29abdf2 100755 --- a/index.php +++ b/index.php @@ -32,23 +32,30 @@ // Purpose of file: // ---------------------------------------------------------------------- -// Non menu entry case -//header("Location:../../central.php"); +$NEEDED_ITEMS=array("search"); -// Entry menu case define('GLPI_ROOT', '../..'); include (GLPI_ROOT . "/inc/includes.php"); -if ($_SESSION["glpiactiveprofile"]["interface"] == "central") - commonHeader("TITRE", $_SERVER['PHP_SELF'],"plugins","example"); - else - helpHeader("TITRE", $_SERVER['PHP_SELF']); +if ($_SESSION["glpiactiveprofile"]["interface"] == "central"){ + commonHeader("TITRE", $_SERVER['PHP_SELF'],"plugins","example"); +} else { + helpHeader("TITRE", $_SERVER['PHP_SELF']); +} +$NEEDED_ITEMS=array("search","printer","contract","infocom"); -echo "This is the plugin index file"; +checkRight("computer","r"); -echo "Example of dropdown (need to create glpi_dropdown_plugin_example table) "; -dropdownValue('glpi_dropdown_plugin_example','myname',0); +commonHeader($LANG["title"][8],$_SERVER['PHP_SELF'],"plugin","example"); + +manageGetValuesInSearch(PLUGIN_EXAMPLE_TYPE); + +searchForm(PLUGIN_EXAMPLE_TYPE,$_SERVER['PHP_SELF'],$_GET["field"],$_GET["contains"],$_GET["sort"],$_GET["deleted"],$_GET["link"],$_GET["distinct"],$_GET["link2"],$_GET["contains2"],$_GET["field2"],$_GET["type2"]); + +showList(PLUGIN_EXAMPLE_TYPE,$_SERVER['PHP_SELF'],$_GET["field"],$_GET["contains"],$_GET["sort"],$_GET["order"],$_GET["start"],$_GET["deleted"],$_GET["link"],$_GET["distinct"],$_GET["link2"],$_GET["contains2"],$_GET["field2"],$_GET["type2"]); + +commonFooter(); commonFooter(); ?> diff --git a/locales/en_GB.php b/locales/en_GB.php index 4b1dce2..042baee 100644 --- a/locales/en_GB.php +++ b/locales/en_GB.php @@ -34,4 +34,5 @@ // ---------------------------------------------------------------------- $LANGEXAMPLE["test"]="test english"; +$LANGEXAMPLE["name"]="Name"; ?> diff --git a/locales/fr_FR.php b/locales/fr_FR.php index 95849b1..65039d5 100644 --- a/locales/fr_FR.php +++ b/locales/fr_FR.php @@ -35,4 +35,5 @@ $LANGEXAMPLE["test"]="test french"; +$LANGEXAMPLE["name"]="Nom"; ?> diff --git a/setup.php b/setup.php index 0b0e501..8a1eced 100755 --- a/setup.php +++ b/setup.php @@ -37,11 +37,11 @@ // Init the hooks of the plugins -Needed function plugin_init_example() { - global $PLUGIN_HOOKS,$LANGEXAMPLE,$CFG_GLPI; + global $PLUGIN_HOOKS,$LANGEXAMPLE,$LANG,$CFG_GLPI; // Display a menu entry ? $PLUGIN_HOOKS['menu_entry']['example'] = true; - $PLUGIN_HOOKS['submenu_entry']['example']['add'] = 'index.php'; + $PLUGIN_HOOKS['submenu_entry']['example']['add'] = 'example.form.php'; $PLUGIN_HOOKS['submenu_entry']['example']["".$LANGEXAMPLE["test"].""] = 'index.php'; $PLUGIN_HOOKS['submenu_entry']['example'][$LANGEXAMPLE["test"]] = 'index.php'; @@ -76,9 +76,8 @@ function plugin_init_example() { $PLUGIN_HOOKS['add_javascript']['example']="example.js"; $PLUGIN_HOOKS['add_css']['example']="example.css"; - // Define Dropdown tables to be manage in GLPI : - $PLUGIN_HOOKS['dropdown']['example']=array("glpi_dropdown_plugin_example"=>"Plugin Example Dropdown"); - $PLUGIN_HOOKS['database_relations']['example']=array("glpi_dropdown_plugin_example"=>array("glpi_plugin_example"=>"FK_dropdown")); + // Params : plugin name - string type - number - tabke - form page + pluginNewType('example',"PLUGIN_EXAMPLE_TYPE",1001,"glpi_plugin_example","example.form.php"); } @@ -88,6 +87,116 @@ function plugin_version_example(){ return array( 'name' => 'Plugin Example', 'version' => '0.0.1'); } +// Define dropdown relations +function plugin_example_getDatabaseRelations(){ + // + return array("glpi_dropdown_plugin_example"=>array("glpi_plugin_example"=>"FK_dropdown")); +} + +// Define Dropdown tables to be manage in GLPI : +function plugin_example_getDropdown(){ + // Table => Name + return array("glpi_dropdown_plugin_example"=>"Plugin Example Dropdown"); +} + +////// SEARCH FUNCTIONS ///////(){ + +// Define search option for types of the plugins +function plugin_example_getSearchOption(){ + global $LANGEXAMPLE; + $sopt=array(); + + $sopt[PLUGIN_EXAMPLE_TYPE]['common']="Header Needed"; + $sopt[PLUGIN_EXAMPLE_TYPE][1]['table']='glpi_plugin_example'; + $sopt[PLUGIN_EXAMPLE_TYPE][1]['field']='name'; + $sopt[PLUGIN_EXAMPLE_TYPE][1]['linkfield']='name'; + $sopt[PLUGIN_EXAMPLE_TYPE][1]['name']=$LANGEXAMPLE["name"]; + + $sopt[PLUGIN_EXAMPLE_TYPE][2]['table']='glpi_dropdown_plugin_example'; + $sopt[PLUGIN_EXAMPLE_TYPE][2]['field']='name'; + $sopt[PLUGIN_EXAMPLE_TYPE][2]['linkfield']='FK_dropdown'; + $sopt[PLUGIN_EXAMPLE_TYPE][2]['name']='Dropdown'; + + return $sopt; +} + +function plugin_example_addLeftJoin($type,$ref_table,$new_table,$linkfield){ + switch ($new_table){ + case "glpi_droprodown_plugin_example" : + // Standard LEFT JOIN for the example but use it for specific jointures + return " LEFT JOIN $new_table AS ON ($rt.$linkfield = $nt.ID) "; + break; + } + return ""; +} + +function plugin_example_giveItem($type,$field,$data,$num,$linkfield=""){ + global $CFG_GLPI, $INFOFORM_PAGES; + + switch ($field){ + case "glpi_plugin_example.name" : + $out= ""; + $out.= $data["ITEM_$num"]; + if ($CFG_GLPI["view_ID"]||empty($data["ITEM_$num"])) $out.= " (".$data["ID"].")"; + $out.= ""; + return $out; + break; + } + return ""; +} + +function plugin_example_addWhere($link,$nott,$type,$ID,$val){ + global $SEARCH_OPTION; + + $table=$SEARCH_OPTION[$type][$ID]["table"]; + $field=$SEARCH_OPTION[$type][$ID]["field"]; + + $SEARCH=makeTextSearch($val,$nott); + + switch ($table.".".$field){ + case "glpi_plugin_example.name" : + // Standard Where clause for the example but use it for specific jointures + $ADD=""; + if ($nott&&$val!="NULL") { + $ADD=" OR $table.$field IS NULL"; + } + + return $link." ($table.$field $SEARCH ".$ADD." ) "; + break; + } + return ""; +} + +function plugin_example_addSelect($type,$ID,$num){ + global $SEARCH_OPTION; + + $table=$SEARCH_OPTION[$type][$ID]["table"]; + $field=$SEARCH_OPTION[$type][$ID]["field"]; + + switch ($table.".".$field){ + case "glpi_plugin_example.name" : + // Standard Select clause for the example but use it for specific selection + return $table.".".$field." AS ITEM_$num, "; + break; + } + return ""; +} + +function plugin_example_addOrderBy($type,$ID,$order,$key=0){ + global $SEARCH_OPTION; + + $table=$SEARCH_OPTION[$type][$ID]["table"]; + $field=$SEARCH_OPTION[$type][$ID]["field"]; + + switch ($table.".".$field){ + case "glpi_plugin_example.name" : + // Standard Order By clause for the example but use it for specific selection + return " ORDER BY $table.$field $order "; + break; + } + return ""; +} +////////////////////////////// // Hook done on update item case function plugin_item_update_example($parm){