diff --git a/hook.php b/hook.php index 50b0ce2..d303ac2 100644 --- a/hook.php +++ b/hook.php @@ -41,35 +41,35 @@ class pluginExample extends CommonDBTM { } }; -// Hook called on profile change +// Hook called on profile change // Good place to evaluate the user right on this plugin // 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'); + $_SESSION["glpi_plugin_example_profile"]=array('example'=>'w'); } else if (haveRight('computer','r')) { - $_SESSION["glpi_plugin_example_profile"]=array('example'=>'r'); + $_SESSION["glpi_plugin_example_profile"]=array('example'=>'r'); } else { - unset($_SESSION["glpi_plugin_example_profile"]); + unset($_SESSION["glpi_plugin_example_profile"]); } - + } // 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'; @@ -97,12 +97,12 @@ function plugin_example_getSearchOption(){ $sopt[PLUGIN_EXAMPLE_TYPE][3]['linkfield']='serial'; $sopt[PLUGIN_EXAMPLE_TYPE][3]['name']='Serial'; $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]; - + return $sopt; } @@ -114,9 +114,9 @@ function plugin_example_giveItem($type,$ID,$data,$num){ switch ($table.'.'.$field){ case "glpi_plugin_example.name" : - $out= ""; + $out= ""; $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.= ""; 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 ""; @@ -153,14 +153,14 @@ function plugin_example_addWhere($link,$nott,$type,$ID,$val){ $table=$SEARCH_OPTION[$type][$ID]["table"]; $field=$SEARCH_OPTION[$type][$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=""; +// $ADD=""; // if ($nott&&$val!="NULL") { // $ADD=" OR $table.$field IS NULL"; // } @@ -176,18 +176,18 @@ function plugin_example_addHaving($link,$nott,$type,$ID,$val,$num){ $table=$SEARCH_OPTION[$type][$ID]["table"]; $field=$SEARCH_OPTION[$type][$ID]["field"]; - + $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=""; + $ADD=""; if (($nott&&$val!="NULL")||$val=='^$') { $ADD=" OR ITEM_$num IS NULL"; } - + return " $LINK ( ITEM_".$num.$SEARCH." $ADD ) "; break; } @@ -230,7 +230,7 @@ function plugin_example_addOrderBy($type,$ID,$order,$key=0){ ////////////////////////////// ////// SPECIFIC MODIF MASSIVE FUNCTIONS /////// -// Define actions : +// Define actions : function plugin_example_MassiveActions($type){ global $LANG; switch ($type){ @@ -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"]); @@ -351,7 +351,7 @@ function plugin_pre_item_update_example($input){ if (isset($input["_item_type_"])) switch ($input["_item_type_"]){ case COMPUTER_TYPE : - // Manipulate data if needed + // Manipulate data if needed addMessageAfterRedirect("Pre Update Computer Hook",true); break; } @@ -377,7 +377,7 @@ function plugin_pre_item_add_example($input){ if (isset($input["_item_type_"])) switch ($input["_item_type_"]){ case COMPUTER_TYPE : - // Manipulate data if needed + // Manipulate data if needed addMessageAfterRedirect("Pre Add Computer Hook",true); break; } @@ -402,7 +402,7 @@ function plugin_pre_item_delete_example($input){ if (isset($input["_item_type_"])) switch ($input["_item_type_"]){ case COMPUTER_TYPE : - // Manipulate data if needed + // Manipulate data if needed addMessageAfterRedirect("Pre Delete Computer Hook",true); break; } @@ -426,7 +426,7 @@ function plugin_pre_item_purge_example($input){ if (isset($input["_item_type_"])) switch ($input["_item_type_"]){ case COMPUTER_TYPE : - // Manipulate data if needed + // Manipulate data if needed addMessageAfterRedirect("Pre Purge Computer Hook",true); break; } @@ -450,7 +450,7 @@ function plugin_pre_item_restore_example($input){ if (isset($input["_item_type_"])) switch ($input["_item_type_"]){ case COMPUTER_TYPE : - // Manipulate data if needed + // Manipulate data if needed addMessageAfterRedirect("Pre Restore Computer Hook"); break; } @@ -471,14 +471,14 @@ 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; } // 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"] +// 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){ @@ -486,7 +486,7 @@ function plugin_planning_populate_example($parm){ // 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"); @@ -527,7 +527,7 @@ function plugin_get_headings_example($type,$ID,$withtemplate){ if ($ID>0 && $prof->getFromDB($ID) && $prof->fields['interface']=='central') { return array( 1 => "Test PLugin", - ); + ); } else { return array(); } @@ -537,7 +537,7 @@ function plugin_get_headings_example($type,$ID,$withtemplate){ if ($withtemplate) { return array(); // Non template case / editing an existing object - } else { + } else { return array( 1 => "Test PLugin", ); @@ -549,7 +549,7 @@ function plugin_get_headings_example($type,$ID,$withtemplate){ return array( 1 => "Test PLugin", 2 => "Test PLugin 2", - ); + ); } break; case "central": @@ -572,7 +572,7 @@ function plugin_get_headings_example($type,$ID,$withtemplate){ return false; } -// Define headings actions added by the plugin +// Define headings actions added by the plugin function plugin_headings_actions_example($type){ switch ($type){ @@ -622,21 +622,21 @@ function plugin_headings_example($type,$ID,$withtemplate=0){ break; case "prefs": // Complete form display - + $data=plugin_version_example(); - + echo "
"; break; @@ -655,7 +655,7 @@ function plugin_headings_example($type,$ID,$withtemplate=0){ // Cron function : name= cron_plugin_PLUGINNAME function cron_plugin_example(){ logInFile('example',"cron called\n"); - + // >0 : done // <0 : to be run again (not finished) // 0 : nothing to do @@ -666,7 +666,7 @@ function cron_plugin_example(){ // Do special actions for dynamic report function plugin_example_dynamicReport($parm){ if ($parm["item_type"]==PLUGIN_EXAMPLE_TYPE){ - // Do all what you want for export depending on $parm + // Do all what you want for export depending on $parm echo "Personalized export for type ".$parm["display_type"]; echo 'with additional datas :