From 41a5750e6faba5b61eb78a24b39e0ccf83b35ea2 Mon Sep 17 00:00:00 2001 From: remicollet Date: Sun, 13 Dec 2009 17:07:33 +0000 Subject: [PATCH] Coding standard (yllen) git-svn-id: https://forge.glpi-project.org/svn/example/trunk@117 349b9182-4a13-0410-896f-e5e9767dd1b3 --- front/example.php | 6 +- hook.php | 999 +++++++++++++++++++++--------------------- inc/example.class.php | 53 ++- locales/en_GB.php | 4 +- locales/fr_FR.php | 4 +- setup.php | 191 ++++---- 6 files changed, 629 insertions(+), 628 deletions(-) diff --git a/front/example.php b/front/example.php index 262186c..a2ec4ed 100755 --- a/front/example.php +++ b/front/example.php @@ -36,10 +36,10 @@ define('GLPI_ROOT', '../../..'); include (GLPI_ROOT . "/inc/includes.php"); -if ($_SESSION["glpiactiveprofile"]["interface"] == "central"){ - commonHeader("TITRE", $_SERVER['PHP_SELF'],"plugins","example","optionname"); +if ($_SESSION["glpiactiveprofile"]["interface"] == "central") { + commonHeader("TITRE", $_SERVER['PHP_SELF'],"plugins","example","optionname"); } else { - helpHeader("TITRE", $_SERVER['PHP_SELF']); + helpHeader("TITRE", $_SERVER['PHP_SELF']); } checkTypeRight('PluginExampleExample',"r"); diff --git a/hook.php b/hook.php index 24b55dc..fdfe0a2 100644 --- a/hook.php +++ b/hook.php @@ -38,577 +38,573 @@ // And to save it in the session function plugin_change_profile_example() { - // For example : same right of computer - if (haveRight('computer','w')) { - $_SESSION["glpi_plugin_example_profile"]=array('example'=>'w'); + // For example : same right of computer + if (haveRight('computer','w')) { + $_SESSION["glpi_plugin_example_profile"] = array('example' => 'w'); - } else if (haveRight('computer','r')) { - $_SESSION["glpi_plugin_example_profile"]=array('example'=>'r'); - - } else { - unset($_SESSION["glpi_plugin_example_profile"]); - } + } else if (haveRight('computer','r')) { + $_SESSION["glpi_plugin_example_profile"] = array('example' => 'r'); + } else { + unset($_SESSION["glpi_plugin_example_profile"]); + } } + // Define dropdown relations -function plugin_example_getDatabaseRelations(){ - // - return array("glpi_plugin_example_dropdowns"=>array("glpi_plugin_example"=>"plugin_example_dropdowns_id")); +function plugin_example_getDatabaseRelations() { + return array("glpi_plugin_example_dropdowns" => array("glpi_plugin_example" => "plugin_example_dropdowns_id")); } // Define Dropdown tables to be manage in GLPI : -function plugin_example_getDropdown(){ - // Table => Name - return array('PluginExampleDropdown' => "Plugin Example Dropdown"); +function plugin_example_getDropdown() { + // Table => Name + return array('PluginExampleDropdown' => "Plugin Example Dropdown"); } ////// SEARCH FUNCTIONS ///////(){ // Define Additionnal search options for types (other than the plugin ones) -function plugin_example_getAddSearchOptions($itemtype){ - global $LANG; +function plugin_example_getAddSearchOptions($itemtype) { + global $LANG; - $sopt=array(); - if ($itemtype == COMPUTER_TYPE) { + $sopt = array(); + if ($itemtype == 'Computer') { // Just for example, not working... $sopt[1001]['table'] = 'glpi_plugin_example_dropdowns'; $sopt[1001]['field'] = 'name'; $sopt[1001]['linkfield'] = 'plugin_example_dropdowns_id'; $sopt[1001]['name'] = 'Example plugin'; } - - return $sopt; -} - -function plugin_example_giveItem($type,$ID,$data,$num){ - - $searchopt=&Search::getOptions($type); - $table=$searchopt[$ID]["table"]; - $field=$searchopt[$ID]["field"]; - - switch ($table.'.'.$field){ - case "glpi_plugin_example_examples.name" : - $out= ""; - $out.= $data["ITEM_$num"]; - if ($_SESSION["glpiis_ids_visible"]||empty($data["ITEM_$num"])) $out.= " (".$data["id"].")"; - $out.= ""; - return $out; - break; - } - return ""; -} - -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_plugin_example_dropdowns" : - return " LEFT JOIN $new_table ON ($ref_table.$linkfield = $new_table.id) "; - break; - } - return ""; + return $sopt; } +function plugin_example_giveItem($type,$ID,$data,$num) { -function plugin_example_forceGroupBy($type){ - switch ($type){ - case 'PluginExampleExample' : - // Force add GROUP BY IN REQUEST - return true; - break; - } - return false; + $searchopt = &Search::getOptions($type); + $table = $searchopt[$ID]["table"]; + $field = $searchopt[$ID]["field"]; + + switch ($table.'.'.$field) { + case "glpi_plugin_example_examples.name" : + $out = ""; + $out .= $data["ITEM_$num"]; + if ($_SESSION["glpiis_ids_visible"] || empty($data["ITEM_$num"])) { + $out .= " (".$data["id"].")"; + } + $out .= ""; + return $out; + } + return ""; } -function plugin_example_addWhere($link,$nott,$type,$ID,$val){ - $searchopt=&Search::getOptions($type); - $table=$searchopt[$ID]["table"]; - $field=$searchopt[$ID]["field"]; +function plugin_example_addLeftJoin($type,$ref_table,$new_table,$linkfield) { - $SEARCH=makeTextSearch($val,$nott); - - // Example of standard Where clause but use it ONLY for specific Where - // No need of the function if you do not have specific cases -// switch ($table.".".$field){ -// case "glpi_plugin_example.name" : -// $ADD=""; -// if ($nott&&$val!="NULL") { -// $ADD=" OR $table.$field IS NULL"; -// } -// return $link." ($table.$field $SEARCH ".$ADD." ) "; -// break; -// } - return ""; + // 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_plugin_example_dropdowns" : + return " LEFT JOIN `$new_table` ON (`$ref_table`.`$linkfield` = `$new_table`.`id`) "; + } + return ""; } + +function plugin_example_forceGroupBy($type) { + + switch ($type) { + case 'PluginExampleExample' : + // Force add GROUP BY IN REQUEST + return true; + } + return false; +} + + +function plugin_example_addWhere($link,$nott,$type,$ID,$val) { + + $searchopt = &Search::getOptions($type); + $table = $searchopt[$ID]["table"]; + $field = $searchopt[$ID]["field"]; + + $SEARCH = makeTextSearch($val,$nott); + + // Example of standard Where clause but use it ONLY for specific Where + // No need of the function if you do not have specific cases + // switch ($table.".".$field) { + // case "glpi_plugin_example.name" : + // $ADD = ""; + // if ($nott && $val!="NULL") { + // $ADD = " OR `$table`.`$field` IS NULL"; + // } + // return $link." (`$table`.`$field` $SEARCH ".$ADD." ) "; + // } + return ""; +} + + // This is not a real example because the use of Having condition in this case is not suitable -function plugin_example_addHaving($link,$nott,$type,$ID,$val,$num){ +function plugin_example_addHaving($link,$nott,$type,$ID,$val,$num) { - $searchopt=&Search::getOptions($type); - $table=$searchopt[$ID]["table"]; - $field=$searchopt[$ID]["field"]; + $searchopt = &Search::getOptions($type); + $table = $searchopt[$ID]["table"]; + $field = $searchopt[$ID]["field"]; - $SEARCH=makeTextSearch($val,$nott); + $SEARCH = makeTextSearch($val,$nott); - // Example of standard Having clause but use it ONLY for specific Having - // No need of the function if you do not have specific cases - switch ($table.".".$field){ - case "glpi_plugin_example.serial" : - $ADD=""; - if (($nott&&$val!="NULL")||$val=='^$') { - $ADD=" OR ITEM_$num IS NULL"; - } - - return " $LINK ( ITEM_".$num.$SEARCH." $ADD ) "; - break; - } - - - return ""; + // Example of standard Having clause but use it ONLY for specific Having + // No need of the function if you do not have specific cases + switch ($table.".".$field) { + case "glpi_plugin_example.serial" : + $ADD = ""; + if (($nott && $val!="NULL") + || $val == '^$') { + $ADD = " OR ITEM_$num IS NULL"; + } + return " $LINK ( ITEM_".$num.$SEARCH." $ADD ) "; + } + return ""; } -function plugin_example_addSelect($type,$ID,$num){ - $searchopt=&Search::getOptions($type); - $table=$searchopt[$ID]["table"]; - $field=$searchopt[$ID]["field"]; +function plugin_example_addSelect($type,$ID,$num) { + + $searchopt = &Search::getOptions($type); + $table = $searchopt[$ID]["table"]; + $field = $searchopt[$ID]["field"]; // Example of standard Select clause but use it ONLY for specific Select // No need of the function if you do not have specific cases -// switch ($table.".".$field){ -// case "glpi_plugin_example.name" : -// return $table.".".$field." AS ITEM_$num, "; -// break; -// } - return ""; +// switch ($table.".".$field) { +// case "glpi_plugin_example.name" : +// return $table.".".$field." AS ITEM_$num, "; +// } + return ""; } -function plugin_example_addOrderBy($type,$ID,$order,$key=0){ - $searchopt=&Search::getOptions($type); - $table=$searchopt[$ID]["table"]; - $field=$searchopt[$ID]["field"]; +function plugin_example_addOrderBy($type,$ID,$order,$key=0) { + + $searchopt = &Search::getOptions($type); + $table = $searchopt[$ID]["table"]; + $field = $searchopt[$ID]["field"]; // Example of standard OrderBy clause but use it ONLY for specific order by // No need of the function if you do not have specific cases -// switch ($table.".".$field){ -// case "glpi_plugin_example.name" : -// return " ORDER BY $table.$field $order "; -// break; -// } - return ""; +// switch ($table.".".$field) { +// case "glpi_plugin_example.name" : +// return " ORDER BY $table.$field $order "; +// } + return ""; } + + ////////////////////////////// ////// SPECIFIC MODIF MASSIVE FUNCTIONS /////// // Define actions : -function plugin_example_MassiveActions($type){ - global $LANG; - switch ($type){ - // New action for core and other plugin types : name = plugin_PLUGINNAME_actionname - case COMPUTER_TYPE : - return array( - "plugin_example_DoIt"=>"plugin_example_DoIt", - ); - break; +function plugin_example_MassiveActions($type) { + global $LANG; - // Actions for types provided by the plugin - case 'PluginExampleExample' : - return array( - // GLPI core one - "add_document"=>$LANG["document"][16], - // Specific one - "do_nothing"=>'Do Nothing - just for fun' - ); - break; - } - return array(); + switch ($type) { + // New action for core and other plugin types : name = plugin_PLUGINNAME_actionname + case 'Computer' : + return array("plugin_example_DoIt" => "plugin_example_DoIt"); + + // Actions for types provided by the plugin + case 'PluginExampleExample' : + return array("add_document" => $LANG["document"][16], // GLPI core one + "do_nothing" => 'Do Nothing - just for fun'); // Specific one + } + return array(); } + // How to display specific actions ? -function plugin_example_MassiveActionsDisplay($type,$action){ - global $LANG; - switch ($type){ - case COMPUTER_TYPE: - switch ($action){ - case "plugin_example_DoIt": - echo "  but do nothing :)"; - break; - } - break; - case 'PluginExampleExample': - switch ($action){ - // No case for add_document : use GLPI core one - case "do_nothing": - echo "  but do nothing :)"; - break; - } - break; - } - return ""; +function plugin_example_MassiveActionsDisplay($type,$action) { + global $LANG; + + switch ($type) { + case 'Computer' : + switch ($action) { + case "plugin_example_DoIt" : + echo "  but do nothing :)"; + break; + } + break; + + case 'PluginExampleExample' : + switch ($action) { + // No case for add_document : use GLPI core one + case "do_nothing" : + echo "  but do nothing :)"; + break; + } + break; + } + return ""; } + // How to process specific actions ? -function plugin_example_MassiveActionsProcess($data){ - global $LANG; +function plugin_example_MassiveActionsProcess($data) { + global $LANG; - - switch ($data['action']){ - case 'plugin_example_DoIt': - if ($data['itemtype']=='Computer'){ + switch ($data['action']) { + case 'plugin_example_DoIt' : + 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 ($comp->getFromDB($key)){ - addMessageAfterRedirect("- ".$comp->getField("name")); - } - } - } - } - break; - case 'do_nothing': - 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 ($ex->getFromDB($key)){ - addMessageAfterRedirect("- ".$ex->getField("name")); - } - } - } - } - break; - } + 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 ($comp->getFromDB($key)) { + addMessageAfterRedirect("- ".$comp->getField("name")); + } + } + } + } + break; + + case 'do_nothing' : + 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 ($ex->getFromDB($key)) { + addMessageAfterRedirect("- ".$ex->getField("name")); + } + } + } + } + break; + } } + + // How to display specific update fields ? -function plugin_example_MassiveActionsFieldsDisplay($type,$table,$field,$linkfield){ +function plugin_example_MassiveActionsFieldsDisplay($type,$table,$field,$linkfield) { - if ($table==getTableForItemType($type)){ - // Table fields - switch ($table.".".$field){ - case 'glpi_plugin_example.serial': - echo "Not really specific - Just for example "; - autocompletionTextField($linkfield,$table,$field); - // Dropdown::showYesNo($linkfield); - // Need to return true if specific display - return true; - break; - } + if ($table == getTableForItemType($type)) { + // Table fields + switch ($table.".".$field) { + case 'glpi_plugin_example.serial' : + echo "Not really specific - Just for example "; + autocompletionTextField($linkfield,$table,$field); + // Dropdown::showYesNo($linkfield); + // Need to return true if specific display + return true; + } - } else { - // Linked Fields - switch ($table.".".$field){ - case "glpi_plugin_example_dropdowns.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"]); - // Need to return true if specific display - return true; - break; - } - } - // Need to return false on non display item - return false; + } else { + // Linked Fields + switch ($table.".".$field) { + case "glpi_plugin_example_dropdowns.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"]); + // Need to return true if specific display + return true; + } + } + // Need to return false on non display item + return false; } + ////////////////////////////// // Hook done on before update item case -function plugin_pre_item_update_example($input){ - if (isset($input["_item_type_"])) - switch ($input["_item_type_"]){ - case COMPUTER_TYPE : - // Manipulate data if needed - addMessageAfterRedirect("Pre Update Computer Hook",true); - break; - } - return $input; +function plugin_pre_item_update_example($input) { + + if (isset($input["_item_type_"])) { + switch ($input["_item_type_"]) { + case 'Computer' : + // Manipulate data if needed + addMessageAfterRedirect("Pre Update Computer Hook",true); + break; + } + } + return $input; } // Hook done on update item case -function plugin_item_update_example($parm){ +function plugin_item_update_example($parm) { - if (isset($parm["type"])) - switch ($parm["type"]){ - case COMPUTER_TYPE : - addMessageAfterRedirect("Update Computer Hook",true); - return true; - break; - } - return false; + if (isset($parm["type"])) { + switch ($parm["type"]){ + case 'Computer' : + addMessageAfterRedirect("Update Computer Hook",true); + return true; + } + } + return false; } + // Hook done on before add item case -function plugin_pre_item_add_example($input){ - if (isset($input["_item_type_"])) - switch ($input["_item_type_"]){ - case COMPUTER_TYPE : - // Manipulate data if needed - addMessageAfterRedirect("Pre Add Computer Hook",true); - break; - } - return $input; +function plugin_pre_item_add_example($input) { + + if (isset($input["_item_type_"])) { + switch ($input["_item_type_"]) { + case 'Computer' : + // Manipulate data if needed + addMessageAfterRedirect("Pre Add Computer Hook",true); + break; + } + } + return $input; } + // Hook done on add item case -function plugin_item_add_example($parm){ +function plugin_item_add_example($parm) { - if (isset($parm["type"])) - switch ($parm["type"]){ - case COMPUTER_TYPE : - addMessageAfterRedirect("Add Computer Hook",true); - return true; - break; - } - return false; + if (isset($parm["type"])) { + switch ($parm["type"]) { + case 'Computer' : + addMessageAfterRedirect("Add Computer Hook",true); + return true; + } + } + return false; } + // Hook done on before delete item case -function plugin_pre_item_delete_example($input){ - if (isset($input["_item_type_"])) - switch ($input["_item_type_"]){ - case COMPUTER_TYPE : - // Manipulate data if needed - addMessageAfterRedirect("Pre Delete Computer Hook",true); - break; - } - return $input; -} -// Hook done on delete item case -function plugin_item_delete_example($parm){ +function plugin_pre_item_delete_example($input) { - if (isset($parm["type"])) - switch ($parm["type"]){ - case COMPUTER_TYPE : - addMessageAfterRedirect("Delete Computer Hook",true); - return true; - break; - } - return false; + if (isset($input["_item_type_"])) { + switch ($input["_item_type_"]) { + case 'Computer' : + // Manipulate data if needed + addMessageAfterRedirect("Pre Delete Computer Hook",true); + break; + } + } + return $input; } + +// Hook done on delete item case +function plugin_item_delete_example($parm) { + + if (isset($parm["type"])) { + switch ($parm["type"]) { + case 'Computer' : + addMessageAfterRedirect("Delete Computer Hook",true); + return true; + } + } + return false; +} + + // Hook done on before purge item case -function plugin_pre_item_purge_example($input){ - if (isset($input["_item_type_"])) - switch ($input["_item_type_"]){ - case COMPUTER_TYPE : - // Manipulate data if needed - addMessageAfterRedirect("Pre Purge Computer Hook",true); - break; - } - return $input; -} -// Hook done on purge item case -function plugin_item_purge_example($parm){ +function plugin_pre_item_purge_example($input) { - if (isset($parm["type"])) - switch ($parm["type"]){ - case COMPUTER_TYPE : - addMessageAfterRedirect("Purge Computer Hook",true); - return true; - break; - } - return false; + if (isset($input["_item_type_"])) { + switch ($input["_item_type_"]) { + case 'Computer' : + // Manipulate data if needed + addMessageAfterRedirect("Pre Purge Computer Hook",true); + break; + } + } + return $input; } + +// Hook done on purge item case +function plugin_item_purge_example($parm) { + + if (isset($parm["type"])) { + switch ($parm["type"]) { + case 'Computer' : + addMessageAfterRedirect("Purge Computer Hook",true); + return true; + } + } + return false; +} + + // Hook done on before restore item case -function plugin_pre_item_restore_example($input){ - if (isset($input["_item_type_"])) - switch ($input["_item_type_"]){ - case COMPUTER_TYPE : - // Manipulate data if needed - addMessageAfterRedirect("Pre Restore Computer Hook"); - break; - } - return $input; -} -// Hook done on restore item case -function plugin_item_restore_example($parm){ +function plugin_pre_item_restore_example($input) { - if (isset($parm["type"])) - switch ($parm["type"]){ - case COMPUTER_TYPE : - addMessageAfterRedirect("Restore Computer Hook"); - return true; - break; - } - return false; + if (isset($input["_item_type_"])) { + switch ($input["_item_type_"]) { + case 'Computer' : + // Manipulate data if needed + addMessageAfterRedirect("Pre Restore Computer Hook"); + break; + } + } + return $input; } + // Hook done on restore item case -function plugin_item_transfer_example($parm){ +function plugin_item_restore_example($parm) { - addMessageAfterRedirect("Transfer Computer Hook ".$parm['type']." ".$parm['id']." -> ".$parm['newID']); - - return false; + if (isset($parm["type"])) { + switch ($parm["type"]) { + case 'Computer' : + addMessageAfterRedirect("Restore Computer Hook"); + return true; + } + } + return false; } + +// Hook done on restore item case +function plugin_item_transfer_example($parm) { + + addMessageAfterRedirect("Transfer Computer Hook ".$parm['type']." ".$parm['id']." -> ". + $parm['newID']); + + return false; +} + + // Parm contains begin, end and who // Create data to be displayed in the planning of $parm["who"] or $parm["who_group"] between $parm["begin"] and $parm["end"] -function plugin_planning_populate_example($parm){ +function plugin_planning_populate_example($parm) { - // Add items in the items fields of the parm array - // Items need to have an unique index beginning by the begin date of the item to display - // needed to be correcly displayed + // Add items in the items fields of the parm array + // Items need to have an unique index beginning by the begin date of the item to display + // needed to be correcly displayed + $parm["items"][$parm["begin"]."$$$"."plugin_example1"]["plugin"] = "example"; + $parm["items"][$parm["begin"]."$$$"."plugin_example1"]["begin"] = date("Y-m-d 17:00:00"); + $parm["items"][$parm["begin"]."$$$"."plugin_example1"]["end"] = date("Y-m-d 18:00:00"); + $parm["items"][$parm["begin"]."$$$"."plugin_example1"]["name"] = "test planning example 1 "; + // Set the ID using the ID of the item in the database to have unique ID + $ID = date("Ymd"); // Current date for example + $parm["items"][$parm["begin"]."$$$"."plugin_example1"]["planningID"] = "plugin_example".$ID; - $parm["items"][$parm["begin"]."$$$"."plugin_example1"]["plugin"]="example"; - $parm["items"][$parm["begin"]."$$$"."plugin_example1"]["begin"]=date("Y-m-d 17:00:00"); - $parm["items"][$parm["begin"]."$$$"."plugin_example1"]["end"]=date("Y-m-d 18:00:00"); - $parm["items"][$parm["begin"]."$$$"."plugin_example1"]["name"]="test planning example 1 "; - // Set the ID using the ID of the item in the database to have unique ID - $ID=date("Ymd"); // Current date for example - $parm["items"][$parm["begin"]."$$$"."plugin_example1"]["planningID"]="plugin_example".$ID; - - return $parm; + return $parm; } + // Display the planning item -function plugin_display_planning_example($parm){ - // $parm["type"] say begin end in or from type - // Add items in the items fields of the parm array - global $LANG; - switch ($parm["type"]){ - case "in": - echo date("H:i",strtotime($parm["begin"]))." -> ".date("H:i",strtotime($parm["end"])).": "; - break; - case "from": - break; - case "begin"; - echo $LANG["buttons"][33]." ".date("H:i",strtotime($parm["begin"])).": "; - break; - case "end"; - echo $LANG["buttons"][32]." ".date("H:i",strtotime($parm["end"])).": "; - break; - } - echo $parm["name"]; +function plugin_display_planning_example($parm) { + global $LANG; + + // $parm["type"] say begin end in or from type + // Add items in the items fields of the parm array + switch ($parm["type"]) { + case "in" : + echo date("H:i",strtotime($parm["begin"]))." -> ".date("H:i",strtotime($parm["end"])).": "; + break; + + case "from" : + break; + + case "begin" : + echo $LANG["buttons"][33]." ".date("H:i",strtotime($parm["begin"])).": "; + break; + + case "end" : + echo $LANG["buttons"][32]." ".date("H:i",strtotime($parm["end"])).": "; + break; + } + echo $parm["name"]; } + // Define headings added by the plugin -function plugin_get_headings_example($item, $withtemplate){ - switch (get_class($item)){ - case 'Profile': +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", - ); + 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", - ); + 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", - ); + 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; + case 'Central' : + case 'Preference': + case 'Notification': + return array(1 => "Test PLugin"); } return false; } + // Define headings actions added by the plugin -function plugin_headings_actions_example($item){ +function plugin_headings_actions_example($item) { - switch (get_class($item)){ + switch (get_class($item)) { case 'Profile' : case 'Computer' : - return array( - 1 => "plugin_headings_example", - ); + return array(1 => "plugin_headings_example"); - break; case 'ComputerDisk' : case 'Supplier' : - return array( - 1 => "plugin_headings_example", - 2 => "plugin_headings_example", - ); + return array(1 => "plugin_headings_example", + 2 => "plugin_headings_example"); - 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 array(1 => "plugin_headings_example"); } return false; } + // Example of an action heading -function plugin_headings_example($item, $withtemplate=0){ +function plugin_headings_example($item, $withtemplate=0) { global $LANG; - if (!$withtemplate){ - echo "
"; - switch (get_class($item)){ - case 'Central': + + if (!$withtemplate) { + echo "
"; + switch (get_class($item)) { + case 'Central' : echo "Plugin central action ".$LANG['plugin_example']["test"]; break; - case 'Preference': + case 'Preference' : // Complete form display - $data=plugin_version_example(); + $data = plugin_version_example(); echo "
"; echo ""; - echo ""; - echo ""; + echo ""; + echo ""; echo ""; echo ""; @@ -617,18 +613,19 @@ function plugin_headings_example($item, $withtemplate=0){ echo ""; break; - case 'Notification': + 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'); + echo "Plugin function with headings CLASS=".get_class($item)." id=".$item->getField('id'); break; } echo ""; } } + /** * Execute 1 task manage by the plugin * @@ -640,12 +637,14 @@ function plugin_headings_example($item, $withtemplate=0){ * 0 : nothing to do */ function plugin_example_cron_sample1_run($task) { + $task->log("Example log message from hook"); $task->setVolume(mt_rand(0,$task->fields['param'])); return 1; } + /** * Give localized information about 1 task * @@ -657,126 +656,134 @@ function plugin_example_cron_info($name) { global $LANG; switch ($name) { - case 'sample1': - return array ( - 'description' => $LANG['plugin_example']['test'] . " (hook)", // Mandatory - 'parameter' => $LANG['plugin_example']['test']); // Optional - break; + case 'sample1' : + return array('description' => $LANG['plugin_example']['test'] . " (hook)", // Mandatory + 'parameter' => $LANG['plugin_example']['test']); // Optional } return array(); } // Do special actions for dynamic report -function plugin_example_dynamicReport($parm){ - if ($parm["item_type"]=='PluginExampleExample'){ - // Do all what you want for export depending on $parm - echo "Personalized export for type ".$parm["display_type"]; - echo 'with additional datas :
'; - echo "Single data : add1
"; - print $parm['add1'].'
'; - echo "Array data : add2
"; - printCleanArray($parm['add2']); - // Return true if personalized display is done - return true; - } - // Return false if no specific display is done, then use standard display - return false; +function plugin_example_dynamicReport($parm) { + + if ($parm["item_type"] == 'PluginExampleExample') { + // Do all what you want for export depending on $parm + echo "Personalized export for type ".$parm["display_type"]; + echo 'with additional datas :
'; + echo "Single data : add1
"; + print $parm['add1'].'
'; + echo "Array data : add2
"; + printCleanArray($parm['add2']); + // Return true if personalized display is done + return true; + } + // Return false if no specific display is done, then use standard display + return false; } + // Add parameters to printPager in search system -function plugin_example_addParamFordynamicReport($device_type){ - if ($device_type=='PluginExampleExample'){ - // Return array data containing all params to add : may be single data or array data - // Search config are available from session variable - return array( - 'add1' => $_SESSION['glpisearch'][$device_type]['order'], - 'add2' => array('tutu'=>'Second Add','Other Data')); - } - // Return false or a non array data if not needed - return false; +function plugin_example_addParamFordynamicReport($itemtype) { + + if ($itemtype == 'PluginExampleExample') { + // Return array data containing all params to add : may be single data or array data + // Search config are available from session variable + return array('add1' => $_SESSION['glpisearch'][$itemtype]['order'], + 'add2' => array('tutu'=>'Second Add', + 'Other Data')); + } + // Return false or a non array data if not needed + return false; } + // Install process for plugin : need to return true if succeeded -function plugin_example_install(){ - global $DB; +function plugin_example_install() { + global $DB; + 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, + `plugin_example_dropdowns_id` int(11) NOT NULL default '0', + `is_deleted` tinyint(1) NOT NULL default '0', + `is_template` tinyint(1) NOT NULL default '0', + `template_name` varchar(255) collate utf8_unicode_ci default NULL, + PRIMARY KEY (`id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; - 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, - `plugin_example_dropdowns_id` int(11) NOT NULL default '0', - `is_deleted` smallint(6) NOT NULL default '0', - `is_template` smallint(6) NOT NULL default '0', - `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_examples ". $DB->error()); - $query="INSERT INTO `glpi_plugin_example_examples` (`id`, `name`, `serial`, `plugin_example_dropdowns_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_plugin_example_dropdowns")){ + $DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error()); - $query="CREATE TABLE `glpi_plugin_example_dropdowns` ( - `id` int(11) NOT NULL auto_increment, - `name` varchar(255) collate utf8_unicode_ci default NULL, - `comment` text collate utf8_unicode_ci, - PRIMARY KEY (`id`), - KEY `name` (`name`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; + $query = "INSERT INTO `glpi_plugin_example_examples` + (`id`, `name`, `serial`, `plugin_example_dropdowns_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()); + } - $DB->query($query) or die("error creating glpi_plugin_example_dropdowns". $DB->error()); - $query="INSERT INTO `glpi_plugin_example_dropdowns` (`id`, `name`, `comment`) VALUES - (1, 'dp 1', 'comment 1'), - (2, 'dp2', 'comment 2');"; - $DB->query($query) or die("error populate glpi_plugin_example_dropdowns". $DB->error()); + if (!TableExists("glpi_plugin_example_dropdowns")) { + $query = "CREATE TABLE `glpi_plugin_example_dropdowns` ( + `id` int(11) NOT NULL auto_increment, + `name` varchar(255) collate utf8_unicode_ci default NULL, + `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_plugin_example_dropdowns". $DB->error()); + + $query = "INSERT INTO `glpi_plugin_example_dropdowns` + (`id`, `name`, `comment`) + VALUES (1, 'dp 1', 'comment 1'), + (2, 'dp2', 'comment 2')"; + + $DB->query($query) or die("error populate glpi_plugin_example_dropdowns". $DB->error()); + + } // To be called for each task the plugin manage // 1 task in hook.php - CronTask::Register('example', 'sample1', HOUR_TIMESTAMP*2, array('param'=>50)); + CronTask::Register('example', 'sample1', HOUR_TIMESTAMP*2, array('param' => 50)); // 1 task in class - CronTask::Register('example', 'sample2', DAY_TIMESTAMP, array('itemtype'=>'PluginExampleExample')); - return true; + CronTask::Register('example', 'sample2', DAY_TIMESTAMP, array('itemtype' => 'PluginExampleExample')); + return true; } + // Uninstall process for plugin : need to return true if succeeded -function plugin_example_uninstall(){ +function plugin_example_uninstall() { global $DB; // Old version tables - if (TableExists("glpi_dropdown_plugin_example")){ - $query="DROP TABLE `glpi_dropdown_plugin_example`;"; + if (TableExists("glpi_dropdown_plugin_example")) { + $query = "DROP TABLE `glpi_dropdown_plugin_example`"; $DB->query($query) or die("error deleting glpi_dropdown_plugin_example"); } - if (TableExists("glpi_plugin_example")){ - $query="DROP TABLE `glpi_plugin_example`;"; + if (TableExists("glpi_plugin_example")) { + $query = "DROP TABLE `glpi_plugin_example`"; $DB->query($query) or die("error deleting glpi_plugin_example"); } // Current version tables - if (TableExists("glpi_plugin_example_example")){ - $query="DROP TABLE `glpi_plugin_example_example`;"; + if (TableExists("glpi_plugin_example_example")) { + $query = "DROP TABLE `glpi_plugin_example_example`"; $DB->query($query) or die("error deleting glpi_plugin_example_example"); } - if (TableExists("glpi_plugin_example_dropdowns")){ - $query="DROP TABLE `glpi_plugin_example_dropdowns`;"; + if (TableExists("glpi_plugin_example_dropdowns")) { + $query = "DROP TABLE `glpi_plugin_example_dropdowns`;"; $DB->query($query) or die("error deleting glpi_plugin_example_dropdowns"); } return true; } -function plugin_example_AssignToTicket($types) -{ - $types['PluginExampleExample'] = "Example"; - return $types; + +function plugin_example_AssignToTicket($types) { + + $types['PluginExampleExample'] = "Example"; + return $types; } -?> +?> \ No newline at end of file diff --git a/inc/example.class.php b/inc/example.class.php index 73e0738..00b4d77 100644 --- a/inc/example.class.php +++ b/inc/example.class.php @@ -42,22 +42,20 @@ class PluginExampleExample extends CommonDBTM { // Should return the localized name of the type static function getTypeName() { - global $LANG; - return 'Example Type'; } static function canCreate() { if (isset($_SESSION["glpi_plugin_example_profile"])) { - return ($_SESSION["glpi_plugin_example_profile"]['example']=='w'); + 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 ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w' + || $_SESSION["glpi_plugin_example_profile"]['example'] == 'r'); } return false; } @@ -66,28 +64,28 @@ class PluginExampleExample extends CommonDBTM { global $LANG; $tab = array(); - $tab['common']="Header Needed"; + $tab['common'] = "Header Needed"; - $tab[1]['table']='glpi_plugin_example_examples'; - $tab[1]['field']='name'; - $tab[1]['linkfield']='name'; - $tab[1]['name']=$LANG['plugin_example']["name"]; + $tab[1]['table'] = 'glpi_plugin_example_examples'; + $tab[1]['field'] = 'name'; + $tab[1]['linkfield'] = 'name'; + $tab[1]['name'] = $LANG['plugin_example']["name"]; - $tab[2]['table']='glpi_plugin_example_dropdowns'; - $tab[2]['field']='name'; - $tab[2]['linkfield']='plugin_example_dropdowns_id'; - $tab[2]['name']='Dropdown'; + $tab[2]['table'] = 'glpi_plugin_example_dropdowns'; + $tab[2]['field'] = 'name'; + $tab[2]['linkfield'] = 'plugin_example_dropdowns_id'; + $tab[2]['name'] = 'Dropdown'; - $tab[3]['table']='glpi_plugin_example_examples'; - $tab[3]['field']='serial'; - $tab[3]['linkfield']='serial'; - $tab[3]['name']='Serial'; - $tab[3]['usehaving']=true; + $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_examples'; - $tab[30]['field']='id'; - $tab[30]['linkfield']=''; - $tab[30]['name']=$LANG["common"][2]; + $tab[30]['table'] = 'glpi_plugin_example_examples'; + $tab[30]['field'] = 'id'; + $tab[30]['linkfield'] = ''; + $tab[30]['name'] = $LANG["common"][2]; return $tab; } @@ -103,11 +101,9 @@ class PluginExampleExample extends CommonDBTM { global $LANG; switch ($name) { - case 'sample2': - return array ( - 'description' => $LANG['plugin_example']['test']." (class)", - 'parameter' => $LANG['plugin_example']['test']); - break; + case 'sample2' : + return array('description' => $LANG['plugin_example']['test']." (class)", + 'parameter' => $LANG['plugin_example']['test']); } return array(); } @@ -123,6 +119,7 @@ class PluginExampleExample extends CommonDBTM { * 0 : nothing to do */ static function cronSample2($task) { + $task->log("Example log message from class"); $task->setVolume(mt_rand(0,10)); diff --git a/locales/en_GB.php b/locales/en_GB.php index 4d3cd43..830acff 100644 --- a/locales/en_GB.php +++ b/locales/en_GB.php @@ -33,6 +33,6 @@ // Purpose of file: // ---------------------------------------------------------------------- -$LANG['plugin_example']["test"]="test english"; -$LANG['plugin_example']["name"]="Name"; +$LANG['plugin_example']["test"] = "english test"; +$LANG['plugin_example']["name"] = "Name"; ?> diff --git a/locales/fr_FR.php b/locales/fr_FR.php index 42c54e8..f8ceb1e 100644 --- a/locales/fr_FR.php +++ b/locales/fr_FR.php @@ -34,6 +34,6 @@ // ---------------------------------------------------------------------- -$LANG['plugin_example']["test"]="test french"; -$LANG['plugin_example']["name"]="Nom"; +$LANG['plugin_example']["test"] = "test français"; +$LANG['plugin_example']["name"] = "Nom"; ?> diff --git a/setup.php b/setup.php index 5246db1..fe741f7 100755 --- a/setup.php +++ b/setup.php @@ -35,141 +35,138 @@ // Init the hooks of the plugins -Needed function plugin_init_example() { - global $PLUGIN_HOOKS,$LANG,$CFG_GLPI; - - // Params : plugin name - string type - ID - Array of attributes - Plugin::registerClass('PluginExampleExample', array( - 'classname' => 'PluginExampleExample', - 'formpage' => 'front/example.form.php', - 'deleted_tables' => false, - 'template_tables' => false, - 'specif_entities_tables' => false, - 'recursive_type' => false, - //'linkuser_types' => true, - //'linkgroup_types' => true - )); + global $PLUGIN_HOOKS,$LANG,$CFG_GLPI; // Params : plugin name - string type - ID - Array of attributes - Plugin::registerClass('PluginExampleDropdown', array( - 'classname' => 'PluginExampleDropdown', - 'typename' => 'Example Dropdown Type', - 'formpage' => 'front/dropdown.form.php')); + Plugin::registerClass('PluginExampleExample', + array('classname' => 'PluginExampleExample', + 'formpage' => 'front/example.form.php', + 'deleted_tables' => false, + 'template_tables' => false, + 'specif_entities_tables' => false, + 'recursive_type' => false)); - // Display a menu entry ? - if (isset($_SESSION["glpi_plugin_example_profile"])) { // Right set in change_profile hook + // Params : plugin name - string type - ID - Array of attributes + Plugin::registerClass('PluginExampleDropdown', + array('classname' => 'PluginExampleDropdown', + 'typename' => 'Example Dropdown Type', + 'formpage' => 'front/dropdown.form.php')); + + // Display a menu entry ? + 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"; - $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['page']='/plugins/example/front/example.php'; - $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['search']='/plugins/example/front/example.php'; - $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['add'] = '/plugins/example/front/example.form.php'; - $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['config'] = '/plugins/example/index.php'; - $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']["".$LANG["] = '/plugins/example/index.php'; - $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links'][$LANG['plugin_example']["test"]] = '/plugins/example/index.php'; + $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['title'] = "Search"; + $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['page'] = '/plugins/example/front/example.php'; + $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['search'] = '/plugins/example/front/example.php'; + $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['add'] = '/plugins/example/front/example.form.php'; + $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['config'] = '/plugins/example/index.php'; + $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']["".$LANG["] = '/plugins/example/index.php'; + $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links'][$LANG['plugin_example']["test"]] = '/plugins/example/index.php'; - $PLUGIN_HOOKS["helpdesk_menu_entry"]['example'] = true; - } + $PLUGIN_HOOKS["helpdesk_menu_entry"]['example'] = true; + } - // Config page - if (haveRight('config','w')) { - $PLUGIN_HOOKS['config_page']['example'] = 'config.php'; - } + // Config page + if (haveRight('config','w')) { + $PLUGIN_HOOKS['config_page']['example'] = 'config.php'; + } - // Init session - //$PLUGIN_HOOKS['init_session']['example'] = 'plugin_init_session_example'; - // Change profile - $PLUGIN_HOOKS['change_profile']['example'] = 'plugin_change_profile_example'; - // Change entity - //$PLUGIN_HOOKS['change_entity']['example'] = 'plugin_change_entity_example'; + // Init session + //$PLUGIN_HOOKS['init_session']['example'] = 'plugin_init_session_example'; + // Change profile + $PLUGIN_HOOKS['change_profile']['example'] = 'plugin_change_profile_example'; + // Change entity + //$PLUGIN_HOOKS['change_entity']['example'] = 'plugin_change_entity_example'; + // Onglets management + $PLUGIN_HOOKS['headings']['example'] = 'plugin_get_headings_example'; + $PLUGIN_HOOKS['headings_action']['example'] = 'plugin_headings_actions_example'; - // Onglets management - $PLUGIN_HOOKS['headings']['example'] = 'plugin_get_headings_example'; - $PLUGIN_HOOKS['headings_action']['example'] = 'plugin_headings_actions_example'; + // Item action event // See define.php for defined ITEM_TYPE + $PLUGIN_HOOKS['pre_item_update']['example'] = 'plugin_pre_item_update_example'; + $PLUGIN_HOOKS['item_update']['example'] = 'plugin_item_update_example'; - // Item action event // See define.php for defined ITEM_TYPE - $PLUGIN_HOOKS['pre_item_update']['example'] = 'plugin_pre_item_update_example'; - $PLUGIN_HOOKS['item_update']['example'] = 'plugin_item_update_example'; + $PLUGIN_HOOKS['pre_item_add']['example'] = 'plugin_pre_item_add_example'; + $PLUGIN_HOOKS['item_add']['example'] = 'plugin_item_add_example'; - $PLUGIN_HOOKS['pre_item_add']['example'] = 'plugin_pre_item_add_example'; - $PLUGIN_HOOKS['item_add']['example'] = 'plugin_item_add_example'; + $PLUGIN_HOOKS['pre_item_delete']['example'] = 'plugin_pre_item_delete_example'; + $PLUGIN_HOOKS['item_delete']['example'] = 'plugin_item_delete_example'; - $PLUGIN_HOOKS['pre_item_delete']['example'] = 'plugin_pre_item_delete_example'; - $PLUGIN_HOOKS['item_delete']['example'] = 'plugin_item_delete_example'; + $PLUGIN_HOOKS['pre_item_purge']['example'] = 'plugin_pre_item_purge_example'; + $PLUGIN_HOOKS['item_purge']['example'] = 'plugin_item_purge_example'; - $PLUGIN_HOOKS['pre_item_purge']['example'] = 'plugin_pre_item_purge_example'; - $PLUGIN_HOOKS['item_purge']['example'] = 'plugin_item_purge_example'; + $PLUGIN_HOOKS['pre_item_restore']['example'] = 'plugin_pre_item_restore_example'; + $PLUGIN_HOOKS['item_restore']['example'] = 'plugin_item_restore_example'; - $PLUGIN_HOOKS['pre_item_restore']['example'] = 'plugin_pre_item_restore_example'; - $PLUGIN_HOOKS['item_restore']['example'] = 'plugin_item_restore_example'; + $PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example'; - $PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example'; + //redirect appel http://localhost/glpi/index.php?redirect=plugin_example_2 (ID 2 du form) + $PLUGIN_HOOKS['redirect_page']['example'] = 'example.form.php'; - //redirect appel http://localhost/glpi/index.php?redirect=plugin_example_2 (ID 2 du form) - $PLUGIN_HOOKS['redirect_page']['example']="example.form.php"; + //function to populate planning + $PLUGIN_HOOKS['planning_populate']['example'] = 'plugin_planning_populate_example'; - //function to populate planning - $PLUGIN_HOOKS['planning_populate']['example']="plugin_planning_populate_example"; + //function to display planning items + $PLUGIN_HOOKS['display_planning']['example'] = 'plugin_display_planning_example'; - //function to display planning items - $PLUGIN_HOOKS['display_planning']['example']="plugin_display_planning_example"; + // Massive Action definition + $PLUGIN_HOOKS['use_massive_action']['example'] = 1; - // Massive Action definition - $PLUGIN_HOOKS['use_massive_action']['example']=1; + $PLUGIN_HOOKS['assign_to_ticket']['example'] = 1; - $PLUGIN_HOOKS['assign_to_ticket']['example']=1; + // Add specific files to add to the header : javascript or css + $PLUGIN_HOOKS['add_javascript']['example'] = 'example.js'; + $PLUGIN_HOOKS['add_css']['example'] = 'example.css'; - // Add specific files to add to the header : javascript or css - $PLUGIN_HOOKS['add_javascript']['example']="example.js"; - $PLUGIN_HOOKS['add_css']['example']="example.css"; + // Retrieve others datas from LDAP + //$PLUGIN_HOOKS['retrieve_more_data_from_ldap']['example']="plugin_retrieve_more_data_from_ldap_example"; - // Retrieve others datas from LDAP - //$PLUGIN_HOOKS['retrieve_more_data_from_ldap']['example']="plugin_retrieve_more_data_from_ldap_example"; - - // Reports - $PLUGIN_HOOKS['reports']['example'] = array('report.php'=>'New Report', 'report.php?other'=>'New Report 2',); - - // Stats - $PLUGIN_HOOKS['stats']['example'] = array('stat.php'=>'New stat', 'stat.php?other'=>'New stats 2',); + // Reports + $PLUGIN_HOOKS['reports']['example'] = array('report.php' => 'New Report', + 'report.php?other' => 'New Report 2'); + // Stats + $PLUGIN_HOOKS['stats']['example'] = array('stat.php' => 'New stat', + 'stat.php?other' => 'New stats 2',); } // Get the name and the version of the plugin - Needed -function plugin_version_example(){ - return array( - 'name' => 'Plugin Example', - 'version' => '0.2.0', - 'author' => 'Julien Dombre', - 'homepage'=> 'http://glpi-project.org', - 'minGlpiVersion' => '0.80',// For compatibility / no install in version < 0.72 - ); +function plugin_version_example() { + + return array('name' => 'Plugin Example', + 'version' => '0.2.0', + 'author' => 'Julien Dombre', + 'homepage' => 'https://forge.indepnet.net/projects/show/example', + '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.80){ - return true; - } else { - echo "GLPI version not compatible need 0.80"; - } +function plugin_example_check_prerequisites() { + + if (GLPI_VERSION >= 0.80) { + return true; + } else { + echo "GLPI version not compatible need 0.80"; + } } // Check configuration process for plugin : need to return true if succeeded // Can display a message only if failure and $verbose is true -function plugin_example_check_config($verbose=false){ - global $LANG; +function plugin_example_check_config($verbose=false) { + global $LANG; - if (true) { // Your configuration check - return true; - } - if ($verbose) { - echo $LANG['plugins'][2]; - } - return false; + if (true) { // Your configuration check + return true; + } + if ($verbose) { + echo $LANG['plugins'][2]; + } + return false; } -?> +?> \ No newline at end of file
".$data['name']; - echo " - ".$data['version']; + echo "
".$data['name']." - ".$data['version']; echo "
Name of the pref"; - echo "Input to set the pref
Name of the prefInput to set the pref