'w'); } else if (Session::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")); } // Define Dropdown tables to be manage in GLPI : 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; $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; } return ""; } function plugin_example_displayConfigItem($type, $ID, $data, $num) { $searchopt = &Search::getOptions($type); $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; // Example of specific style options // No need of the function if you do not have specific cases switch ($table.'.'.$field) { case "glpi_plugin_example_examples.name" : return " style=\"background-color:#DDDDDD;\" "; break; } return ""; } function plugin_example_addDefaultJoin($type, $ref_table, &$already_link_tables) { // Example of default JOIN clause // No need of the function if you do not have specific cases switch ($type) { // case "PluginExampleExample" : case "MyType" : return Search::addLeftJoin($type, $ref_table, $already_link_tables, "newtable", "linkfield"); break; } return ""; } function plugin_example_addDefaultSelect($type) { // Example of default SELECT item to be added // No need of the function if you do not have specific cases switch ($type) { // case "PluginExampleExample" : case "MyType" : return "`mytable`.`myfield` = 'myvalue' AS MYNAME, "; break; } return ""; } function plugin_example_addDefaultWhere($type) { // Example of default WHERE item to be added // No need of the function if you do not have specific cases switch ($type) { // case "PluginExampleExample" : case "MyType" : return " `mytable`.`myfield` = 'myvalue' "; 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`) "; } 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 = 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." ) ";*/ case "glpi_plugin_example_examples.serial" : return $link." `$table`.`$field` = '$val' "; } 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) { $searchopt = &Search::getOptions($type); $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; $SEARCH = 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 ) "; } return ""; } 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, "; // } return ""; } 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 "; // } 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' : 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 ? // options contain at least itemtype and and action function plugin_example_MassiveActionsDisplay($options=array()) { global $LANG; switch ($options['itemtype']) { case 'Computer' : switch ($options['action']) { case "plugin_example_DoIt" : echo " but do nothing :)"; break; } break; case 'PluginExampleExample' : switch ($options['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; 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; } } // How to display specific update fields ? // options must contain at least itemtype and options array function plugin_example_MassiveActionsFieldsDisplay($options=array()) { //$type,$table,$field,$linkfield $table = $options['options']['table']; $field = $options['options']['field']; $linkfield = $options['options']['linkfield']; if ($table == getTableForItemType($options['itemtype'])) { // Table fields switch ($table.".".$field) { case 'glpi_plugin_example_examples.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 "; // Need to return true if specific display return true; } } // Need to return false on non display item return false; } // How to display specific search fields or dropdown ? // options must contain at least itemtype and options array // MUST Use a specific AddWhere & $tab[X]['searchtype'] = 'equals'; declaration function plugin_example_searchOptionsValues($options=array()) { global $LANG; $table = $options['searchoption']['table']; $field = $options['searchoption']['field']; // Table fields switch ($table.".".$field) { case "glpi_plugin_example_examples.serial" : echo "Not really specific - Use your own dropdown - Just for example "; Dropdown::show(getItemTypeForTable($options['searchoption']['table']), array('value' => $options['value'], 'name' => $options['name'], 'comments' => 0)); // Need to return true if specific display return true; } return false; } ////////////////////////////// // Hook done on before update item case function plugin_pre_item_update_example($item) { /* Manipulate data if needed if (!isset($item->input['comment'])) { $item->input['comment'] = addslashes($item->fields['comment']); } $item->input['comment'] .= addslashes("\nUpdate: ".date('r')); */ addMessageAfterRedirect("Pre Update Computer Hook",true); } // Hook done on update item case function plugin_item_update_example($item) { addMessageAfterRedirect("Update Computer Hook (".implode(',',$item->updates).")",true); return true; } // Hook done on get empty item case function plugin_item_empty_example($item) { addMessageAfterRedirect("Empty Computer Hook",true); return true; } // Hook done on before delete item case function plugin_pre_item_delete_example($object) { // Manipulate data if needed addMessageAfterRedirect("Pre Delete Computer Hook",true); } // Hook done on delete item case function plugin_item_delete_example($object) { addMessageAfterRedirect("Delete Computer Hook",true); return true; } // Hook done on before purge item case function plugin_pre_item_purge_example($object) { // Manipulate data if needed addMessageAfterRedirect("Pre Purge Computer Hook",true); } // Hook done on purge item case function plugin_item_purge_example($object) { addMessageAfterRedirect("Purge Computer Hook",true); return true; } // Hook done on before restore item case function plugin_pre_item_restore_example($item) { // Manipulate data if needed addMessageAfterRedirect("Pre Restore Computer Hook"); } // Hook done on before restore item case function plugin_pre_item_restore_example2($item) { // Manipulate data if needed addMessageAfterRedirect("Pre Restore Phone Hook"); } // Hook done on restore item case function plugin_item_restore_example($item) { addMessageAfterRedirect("Restore Computer Hook"); return true; } // 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) { // 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; return $parm; } // Display the planning item 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' : $prof = new Profile(); if ($item->fields['interface'] == 'central') { return array(1 => "Test PLugin"); } else { return array(); } case 'Computer' : // new object / template case if ($withtemplate) { return array(); // Non template case / editing an existing object } else { return array(1 => "Test PLugin"); } case 'ComputerDisk' : case 'Supplier' : if ($item->getField('id')) { // Not in create mode return array(1 => "Test PLugin", 2 => "Test PLugin 2"); } 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) { switch (get_class($item)) { case 'Profile' : case 'Computer' : return array(1 => "plugin_headings_example"); case 'ComputerDisk' : case 'Supplier' : return array(1 => "plugin_headings_example", 2 => "plugin_headings_example"); case 'Central' : case 'Preference' : case 'Notification' : return array(1 => "plugin_headings_example"); } return false; } // Example of an action heading function plugin_headings_example($item, $withtemplate=0) { global $LANG; if (!$withtemplate) { echo "