mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-08-23 22:35:48 +02:00
20
.github/dependabot.yml
vendored
Normal file
20
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
version: 2
|
||||
updates:
|
||||
# Ensure GitHub Actions are used in their latest version
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
|
||||
# Strategy for composer dependencies
|
||||
- package-ecosystem: "composer"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
allow:
|
||||
- dependency-type: "direct"
|
||||
open-pull-requests-limit: 100
|
||||
versioning-strategy: "increase"
|
||||
groups:
|
||||
dev-dependencies:
|
||||
dependency-type: "development"
|
21
.php-cs-fixer.php
Normal file
21
.php-cs-fixer.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use PhpCsFixer\Config;
|
||||
use PhpCsFixer\Finder;
|
||||
|
||||
$finder = Finder::create()
|
||||
->in(__DIR__)
|
||||
->name('*.php')
|
||||
->ignoreVCSIgnored(true);
|
||||
|
||||
$config = new Config();
|
||||
|
||||
$rules = [
|
||||
'@PER-CS2.0' => true,
|
||||
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']], // For PHP 7.4 compatibility
|
||||
];
|
||||
|
||||
return $config
|
||||
->setRules($rules)
|
||||
->setFinder($finder)
|
||||
->setUsingCache(false);
|
@@ -3,7 +3,8 @@
|
||||
"php": ">=7.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"glpi-project/tools": "^0.5"
|
||||
"friendsofphp/php-cs-fixer": "^3.75",
|
||||
"glpi-project/tools": "^0.7.5"
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
|
2028
composer.lock
generated
2028
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -37,13 +37,13 @@
|
||||
//header("Location:../../central.php");
|
||||
|
||||
// Entry menu case
|
||||
include ("../../../inc/includes.php");
|
||||
include('../../../inc/includes.php');
|
||||
|
||||
Session::checkRight("config", UPDATE);
|
||||
Session::checkRight('config', UPDATE);
|
||||
|
||||
// To be available when plugin in not activated
|
||||
Plugin::load('example');
|
||||
|
||||
Html::header("TITRE", $_SERVER['PHP_SELF'], "config", "plugins");
|
||||
echo __("This is the plugin config page", 'example');
|
||||
Html::header('TITRE', $_SERVER['PHP_SELF'], 'config', 'plugins');
|
||||
echo __('This is the plugin config page', 'example');
|
||||
Html::footer();
|
||||
|
@@ -39,4 +39,4 @@ include ('../../../inc/includes.php');
|
||||
Session::checkLoginUser();
|
||||
|
||||
$dropdown = new DeviceCamera();
|
||||
include (GLPI_ROOT . "/front/dropdown.common.form.php");
|
||||
include(GLPI_ROOT . '/front/dropdown.common.form.php');
|
||||
|
@@ -37,4 +37,4 @@ include ('../../../inc/includes.php');
|
||||
Session::checkLoginUser();
|
||||
|
||||
$dropdown = new DeviceCamera();
|
||||
include (GLPI_ROOT . "/front/dropdown.common.php");
|
||||
include(GLPI_ROOT . '/front/dropdown.common.php');
|
||||
|
@@ -41,4 +41,4 @@ Session::checkLoginUser();
|
||||
Plugin::load('example', true);
|
||||
|
||||
$dropdown = new Dropdown();
|
||||
include (GLPI_ROOT . "/front/dropdown.common.form.php");
|
||||
include(GLPI_ROOT . '/front/dropdown.common.form.php');
|
||||
|
@@ -41,4 +41,4 @@ Session::checkLoginUser();
|
||||
Plugin::load('example', true);
|
||||
|
||||
$dropdown = new Dropdown();
|
||||
include (GLPI_ROOT . "/front/dropdown.common.php");
|
||||
include(GLPI_ROOT . '/front/dropdown.common.php');
|
||||
|
@@ -38,10 +38,10 @@ use GlpiPlugin\Example\Example;
|
||||
include('../../../inc/includes.php');
|
||||
Session::checkLoginUser();
|
||||
|
||||
if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
|
||||
Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", Example::class, "");
|
||||
if ($_SESSION['glpiactiveprofile']['interface'] == 'central') {
|
||||
Html::header('TITRE', $_SERVER['PHP_SELF'], 'plugins', Example::class, '');
|
||||
} else {
|
||||
Html::helpHeader("TITRE", $_SERVER['PHP_SELF']);
|
||||
Html::helpHeader('TITRE', $_SERVER['PHP_SELF']);
|
||||
}
|
||||
|
||||
$example = new Example();
|
||||
|
@@ -38,10 +38,10 @@ use GlpiPlugin\Example\Example;
|
||||
include('../../../inc/includes.php');
|
||||
Session::checkRight(Example::$rightname, READ);
|
||||
|
||||
if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
|
||||
Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", Example::class, "");
|
||||
if ($_SESSION['glpiactiveprofile']['interface'] == 'central') {
|
||||
Html::header('TITRE', $_SERVER['PHP_SELF'], 'plugins', Example::class, '');
|
||||
} else {
|
||||
Html::helpHeader("TITRE", $_SERVER['PHP_SELF']);
|
||||
Html::helpHeader('TITRE', $_SERVER['PHP_SELF']);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -32,28 +32,28 @@ include ('../../../inc/includes.php');
|
||||
|
||||
Session::checkLoginUser();
|
||||
|
||||
if (isset($_GET["popup"])) {
|
||||
$_SESSION["glpipopup"]["name"] = $_GET["popup"];
|
||||
if (isset($_GET['popup'])) {
|
||||
$_SESSION['glpipopup']['name'] = $_GET['popup'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION["glpipopup"]["name"])) {
|
||||
switch ($_SESSION["glpipopup"]["name"]) {
|
||||
case "test_rule" :
|
||||
if (isset($_SESSION['glpipopup']['name'])) {
|
||||
switch ($_SESSION['glpipopup']['name']) {
|
||||
case 'test_rule':
|
||||
Html::popHeader(__('Test'), $_SERVER['PHP_SELF']);
|
||||
include "../../../front/rule.test.php";
|
||||
include '../../../front/rule.test.php';
|
||||
break;
|
||||
|
||||
case "test_all_rules" :
|
||||
case 'test_all_rules':
|
||||
Html::popHeader(__('Test rules engine'), $_SERVER['PHP_SELF']);
|
||||
include "../../../front/rulesengine.test.php";
|
||||
include '../../../front/rulesengine.test.php';
|
||||
break;
|
||||
|
||||
case "show_cache" :
|
||||
case 'show_cache':
|
||||
Html::popHeader(__('Cache information'), $_SERVER['PHP_SELF']);
|
||||
include "../../../front/rule.cache.php";
|
||||
include '../../../front/rule.cache.php';
|
||||
break;
|
||||
}
|
||||
echo "<div class='center'><br><a href='javascript:window.close()'>".__('Back')."</a>";
|
||||
echo "</div>";
|
||||
echo "<div class='center'><br><a href='javascript:window.close()'>" . __('Back') . '</a>';
|
||||
echo '</div>';
|
||||
Html::popFooter();
|
||||
}
|
||||
|
@@ -40,4 +40,4 @@ Session::checkLoginUser();
|
||||
|
||||
$rulecollection = new RuleTestCollection();
|
||||
|
||||
include (GLPI_ROOT . "/front/rule.common.form.php");
|
||||
include(GLPI_ROOT . '/front/rule.common.form.php');
|
||||
|
@@ -40,4 +40,4 @@ Session::checkLoginUser();
|
||||
|
||||
$rulecollection = new RuleTestCollection();
|
||||
|
||||
include (GLPI_ROOT . "/front/rule.common.php");
|
||||
include(GLPI_ROOT . '/front/rule.common.php');
|
||||
|
404
hook.php
404
hook.php
@@ -37,21 +37,24 @@ use GlpiPlugin\Example\Dropdown;
|
||||
use GlpiPlugin\Example\Example;
|
||||
use Dropdown as GlpiDropdown;
|
||||
|
||||
function plugin_change_profile_example() {
|
||||
function plugin_change_profile_example()
|
||||
{
|
||||
// Some logic that runs when the profile is changed
|
||||
}
|
||||
|
||||
|
||||
// Define dropdown relations
|
||||
function plugin_example_getDatabaseRelations() {
|
||||
return ["glpi_plugin_example_dropdowns" => ["glpi_plugin_example" => "plugin_example_dropdowns_id"]];
|
||||
function plugin_example_getDatabaseRelations()
|
||||
{
|
||||
return ['glpi_plugin_example_dropdowns' => ['glpi_plugin_example' => 'plugin_example_dropdowns_id']];
|
||||
}
|
||||
|
||||
|
||||
// Define Dropdown tables to be manage in GLPI :
|
||||
function plugin_example_getDropdown() {
|
||||
function plugin_example_getDropdown()
|
||||
{
|
||||
// Table => Name
|
||||
return [Dropdown::class => __("Plugin Example Dropdown", 'example')];
|
||||
return [Dropdown::class => __('Plugin Example Dropdown', 'example')];
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +62,8 @@ function plugin_example_getDropdown() {
|
||||
////// SEARCH FUNCTIONS ///////(){
|
||||
|
||||
// Define Additionnal search options for types (other than the plugin ones)
|
||||
function plugin_example_getAddSearchOptions($itemtype) {
|
||||
function plugin_example_getAddSearchOptions($itemtype)
|
||||
{
|
||||
$sopt = [];
|
||||
if ($itemtype == 'Computer') {
|
||||
// Just for example, not working...
|
||||
@@ -68,10 +72,12 @@ function plugin_example_getAddSearchOptions($itemtype) {
|
||||
$sopt[1001]['linkfield'] = 'plugin_example_dropdowns_id';
|
||||
$sopt[1001]['name'] = __('Example plugin', 'example');
|
||||
}
|
||||
|
||||
return $sopt;
|
||||
}
|
||||
|
||||
function plugin_example_getAddSearchOptionsNew($itemtype) {
|
||||
function plugin_example_getAddSearchOptionsNew($itemtype)
|
||||
{
|
||||
$options = [];
|
||||
if ($itemtype == 'Computer') {
|
||||
//Just for example, not working
|
||||
@@ -80,155 +86,182 @@ function plugin_example_getAddSearchOptionsNew($itemtype) {
|
||||
'table' => 'glpi_plugin_example_dropdowns',
|
||||
'field' => 'name',
|
||||
'linkfield' => 'plugin_example_dropdowns_id',
|
||||
'name' => __('Example plugin new', 'example')
|
||||
'name' => __('Example plugin new', 'example'),
|
||||
];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
// See also GlpiPlugin\Example\Example::getSpecificValueToDisplay()
|
||||
function plugin_example_giveItem($type, $ID, $data, $num) {
|
||||
function plugin_example_giveItem($type, $ID, $data, $num)
|
||||
{
|
||||
$searchopt = &Search::getOptions($type);
|
||||
$table = $searchopt[$ID]["table"];
|
||||
$field = $searchopt[$ID]["field"];
|
||||
$table = $searchopt[$ID]['table'];
|
||||
$field = $searchopt[$ID]['field'];
|
||||
|
||||
switch ($table . '.' . $field) {
|
||||
case "glpi_plugin_example_examples.name" :
|
||||
$out = "<a href='".Toolbox::getItemTypeFormURL(Example::class)."?id=".$data['id']."'>";
|
||||
case 'glpi_plugin_example_examples.name':
|
||||
$out = "<a href='" . Toolbox::getItemTypeFormURL(Example::class) . '?id=' . $data['id'] . "'>";
|
||||
$out .= $data[$num][0]['name'];
|
||||
if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][0]['name'])) {
|
||||
$out .= " (".$data["id"].")";
|
||||
if ($_SESSION['glpiis_ids_visible'] || empty($data[$num][0]['name'])) {
|
||||
$out .= ' (' . $data['id'] . ')';
|
||||
}
|
||||
$out .= "</a>";
|
||||
$out .= '</a>';
|
||||
|
||||
return $out;
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_displayConfigItem($type, $ID, $data, $num) {
|
||||
function plugin_example_displayConfigItem($type, $ID, $data, $num)
|
||||
{
|
||||
$searchopt = &Search::getOptions($type);
|
||||
$table = $searchopt[$ID]["table"];
|
||||
$field = $searchopt[$ID]["field"];
|
||||
$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;\" ";
|
||||
case 'glpi_plugin_example_examples.name':
|
||||
return ' style="background-color:#DDDDDD;" ';
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_addDefaultJoin($type, $ref_table, &$already_link_tables) {
|
||||
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 Example::class :
|
||||
case "MyType" :
|
||||
return Search::addLeftJoin($type, $ref_table, $already_link_tables,
|
||||
"newtable", "linkfield");
|
||||
case 'MyType':
|
||||
return Search::addLeftJoin(
|
||||
$type,
|
||||
$ref_table,
|
||||
$already_link_tables,
|
||||
'newtable',
|
||||
'linkfield',
|
||||
);
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_addDefaultSelect($type) {
|
||||
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 Example::class :
|
||||
case "MyType" :
|
||||
case 'MyType':
|
||||
return "`mytable`.`myfield` = 'myvalue' AS MYNAME, ";
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_addDefaultWhere($type) {
|
||||
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 Example::class :
|
||||
case "MyType" :
|
||||
case 'MyType':
|
||||
return " `mytable`.`myfield` = 'myvalue' ";
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_addLeftJoin($type, $ref_table, $new_table, $linkfield) {
|
||||
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" :
|
||||
case 'glpi_plugin_example_dropdowns':
|
||||
return " LEFT JOIN `$new_table` ON (`$ref_table`.`$linkfield` = `$new_table`.`id`) ";
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_forceGroupBy($type) {
|
||||
function plugin_example_forceGroupBy($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case Example::class:
|
||||
// Force add GROUP BY IN REQUEST
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_addWhere($link, $nott, $type, $ID, $val, $searchtype) {
|
||||
function plugin_example_addWhere($link, $nott, $type, $ID, $val, $searchtype)
|
||||
{
|
||||
$searchopt = &Search::getOptions($type);
|
||||
$table = $searchopt[$ID]["table"];
|
||||
$field = $searchopt[$ID]["field"];
|
||||
$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) {
|
||||
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" :
|
||||
case 'glpi_plugin_example_examples.serial':
|
||||
return $link . " `$table`.`$field` = '$val' ";
|
||||
}
|
||||
return "";
|
||||
|
||||
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"];
|
||||
$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")
|
||||
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 "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_addSelect($type, $ID, $num) {
|
||||
function plugin_example_addSelect($type, $ID, $num)
|
||||
{
|
||||
$searchopt = &Search::getOptions($type);
|
||||
$table = $searchopt[$ID]["table"];
|
||||
$field = $searchopt[$ID]["field"];
|
||||
$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
|
||||
@@ -236,14 +269,15 @@ function plugin_example_addSelect($type, $ID, $num) {
|
||||
// case "glpi_plugin_example.name" :
|
||||
// return $table.".".$field." AS ITEM_$num, ";
|
||||
// }
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_addOrderBy($type, $ID, $order, $key = 0) {
|
||||
function plugin_example_addOrderBy($type, $ID, $order, $key = 0)
|
||||
{
|
||||
$searchopt = &Search::getOptions($type);
|
||||
$table = $searchopt[$ID]["table"];
|
||||
$field = $searchopt[$ID]["field"];
|
||||
$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
|
||||
@@ -251,7 +285,7 @@ function plugin_example_addOrderBy($type, $ID, $order, $key = 0) {
|
||||
// case "glpi_plugin_example.name" :
|
||||
// return " ORDER BY $table.$field $order ";
|
||||
// }
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
@@ -260,22 +294,24 @@ function plugin_example_addOrderBy($type, $ID, $order, $key = 0) {
|
||||
|
||||
|
||||
// Define actions :
|
||||
function plugin_example_MassiveActions($type) {
|
||||
function plugin_example_MassiveActions($type)
|
||||
{
|
||||
switch ($type) {
|
||||
// New action for core and other plugin types : name = plugin_PLUGINNAME_actionname
|
||||
case 'Computer':
|
||||
return [Example::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'DoIt' =>
|
||||
__("plugin_example_DoIt", 'example')];
|
||||
return [Example::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'DoIt' => __('plugin_example_DoIt', 'example')];
|
||||
|
||||
// Actions for types provided by the plugin are included inside the classes
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
// How to display specific update fields ?
|
||||
// options must contain at least itemtype and options array
|
||||
function plugin_example_MassiveActionsFieldsDisplay($options = []) {
|
||||
function plugin_example_MassiveActionsFieldsDisplay($options = [])
|
||||
{
|
||||
//$type,$table,$field,$linkfield
|
||||
|
||||
$table = $options['options']['table'];
|
||||
@@ -284,23 +320,25 @@ function plugin_example_MassiveActionsFieldsDisplay($options = []) {
|
||||
|
||||
if ($table == getTableForItemType($options['itemtype'])) {
|
||||
// Table fields
|
||||
switch ($table.".".$field) {
|
||||
switch ($table . '.' . $field) {
|
||||
case 'glpi_plugin_example_examples.serial':
|
||||
echo __("Not really specific - Just for example", 'example');
|
||||
echo __('Not really specific - Just for example', 'example');
|
||||
|
||||
// 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", 'example');
|
||||
switch ($table . '.' . $field) {
|
||||
case 'glpi_plugin_example_dropdowns.name':
|
||||
echo __('Not really specific - Just for example', 'example');
|
||||
|
||||
// Need to return true if specific display
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Need to return false on non display item
|
||||
return false;
|
||||
}
|
||||
@@ -309,21 +347,26 @@ function plugin_example_MassiveActionsFieldsDisplay($options = []) {
|
||||
// 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 = []) {
|
||||
function plugin_example_searchOptionsValues($options = [])
|
||||
{
|
||||
$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", 'example');
|
||||
GlpiDropdown::show(getItemTypeForTable($options['searchoption']['table']),
|
||||
switch ($table . '.' . $field) {
|
||||
case 'glpi_plugin_example_examples.serial':
|
||||
echo __('Not really specific - Use your own dropdown - Just for example', 'example');
|
||||
GlpiDropdown::show(
|
||||
getItemTypeForTable($options['searchoption']['table']),
|
||||
['value' => $options['value'],
|
||||
'name' => $options['name'],
|
||||
'comments' => 0]);
|
||||
'comments' => 0],
|
||||
);
|
||||
|
||||
// Need to return true if specific display
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -331,112 +374,136 @@ function plugin_example_searchOptionsValues($options = []) {
|
||||
//////////////////////////////
|
||||
|
||||
// Hook done on before update item case
|
||||
function plugin_pre_item_update_example($item) {
|
||||
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'));
|
||||
*/
|
||||
Session::addMessageAfterRedirect(__("Pre Update Computer Hook", 'example'), true);
|
||||
Session::addMessageAfterRedirect(__('Pre Update Computer Hook', 'example'), true);
|
||||
}
|
||||
|
||||
|
||||
// Hook done on update item case
|
||||
function plugin_item_update_example($item) {
|
||||
Session::addMessageAfterRedirect(sprintf(__("Update Computer Hook (%s)", 'example'), implode(',', $item->updates)), true);
|
||||
function plugin_item_update_example($item)
|
||||
{
|
||||
Session::addMessageAfterRedirect(sprintf(__('Update Computer Hook (%s)', 'example'), implode(',', $item->updates)), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Hook done on get empty item case
|
||||
function plugin_item_empty_example($item) {
|
||||
function plugin_item_empty_example($item)
|
||||
{
|
||||
if (empty($_SESSION['Already displayed "Empty Computer Hook"'])) {
|
||||
Session::addMessageAfterRedirect(__("Empty Computer Hook", 'example'), true);
|
||||
Session::addMessageAfterRedirect(__('Empty Computer Hook', 'example'), true);
|
||||
$_SESSION['Already displayed "Empty Computer Hook"'] = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Hook done on before delete item case
|
||||
function plugin_pre_item_delete_example($object) {
|
||||
function plugin_pre_item_delete_example($object)
|
||||
{
|
||||
// Manipulate data if needed
|
||||
Session::addMessageAfterRedirect(__("Pre Delete Computer Hook", 'example'), true);
|
||||
Session::addMessageAfterRedirect(__('Pre Delete Computer Hook', 'example'), true);
|
||||
}
|
||||
|
||||
|
||||
// Hook done on delete item case
|
||||
function plugin_item_delete_example($object) {
|
||||
Session::addMessageAfterRedirect(__("Delete Computer Hook", 'example'), true);
|
||||
function plugin_item_delete_example($object)
|
||||
{
|
||||
Session::addMessageAfterRedirect(__('Delete Computer Hook', 'example'), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Hook done on before purge item case
|
||||
function plugin_pre_item_purge_example($object) {
|
||||
function plugin_pre_item_purge_example($object)
|
||||
{
|
||||
// Manipulate data if needed
|
||||
Session::addMessageAfterRedirect(__("Pre Purge Computer Hook", 'example'), true);
|
||||
Session::addMessageAfterRedirect(__('Pre Purge Computer Hook', 'example'), true);
|
||||
}
|
||||
|
||||
|
||||
// Hook done on purge item case
|
||||
function plugin_item_purge_example($object) {
|
||||
Session::addMessageAfterRedirect(__("Purge Computer Hook", 'example'), true);
|
||||
function plugin_item_purge_example($object)
|
||||
{
|
||||
Session::addMessageAfterRedirect(__('Purge Computer Hook', 'example'), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Hook done on before restore item case
|
||||
function plugin_pre_item_restore_example($item) {
|
||||
function plugin_pre_item_restore_example($item)
|
||||
{
|
||||
// Manipulate data if needed
|
||||
Session::addMessageAfterRedirect(__("Pre Restore Computer Hook", 'example'));
|
||||
Session::addMessageAfterRedirect(__('Pre Restore Computer Hook', 'example'));
|
||||
}
|
||||
|
||||
|
||||
// Hook done on before restore item case
|
||||
function plugin_pre_item_restore_example2($item) {
|
||||
function plugin_pre_item_restore_example2($item)
|
||||
{
|
||||
// Manipulate data if needed
|
||||
Session::addMessageAfterRedirect(__("Pre Restore Phone Hook", 'example'));
|
||||
Session::addMessageAfterRedirect(__('Pre Restore Phone Hook', 'example'));
|
||||
}
|
||||
|
||||
|
||||
// Hook done on restore item case
|
||||
function plugin_item_restore_example($item) {
|
||||
Session::addMessageAfterRedirect(__("Restore Computer Hook", 'example'));
|
||||
function plugin_item_restore_example($item)
|
||||
{
|
||||
Session::addMessageAfterRedirect(__('Restore Computer Hook', 'example'));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Hook done on restore item case
|
||||
function plugin_item_transfer_example($parm) {
|
||||
function plugin_item_transfer_example($parm)
|
||||
{
|
||||
//TRANS: %1$s is the source type, %2$d is the source ID, %3$d is the destination ID
|
||||
Session::addMessageAfterRedirect(sprintf(__('Transfer Computer Hook %1$s %2$d -> %3$d', 'example'), $parm['type'], $parm['id'],
|
||||
$parm['newID']));
|
||||
Session::addMessageAfterRedirect(sprintf(
|
||||
__('Transfer Computer Hook %1$s %2$d -> %3$d', 'example'),
|
||||
$parm['type'],
|
||||
$parm['id'],
|
||||
$parm['newID'],
|
||||
));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do special actions for dynamic report
|
||||
function plugin_example_dynamicReport($parm) {
|
||||
if ($parm["item_type"] == Example::class) {
|
||||
function plugin_example_dynamicReport($parm)
|
||||
{
|
||||
if ($parm['item_type'] == Example::class) {
|
||||
// Do all what you want for export depending on $parm
|
||||
echo "Personalized export for type ".$parm["display_type"];
|
||||
echo 'Personalized export for type ' . $parm['display_type'];
|
||||
echo 'with additional datas : <br>';
|
||||
echo "Single data : add1 <br>";
|
||||
echo 'Single data : add1 <br>';
|
||||
print $parm['add1'] . '<br>';
|
||||
echo "Array data : add2 <br>";
|
||||
echo 'Array data : add2 <br>';
|
||||
Html::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 Html::printPager in search system
|
||||
function plugin_example_addParamFordynamicReport($itemtype) {
|
||||
function plugin_example_addParamFordynamicReport($itemtype)
|
||||
{
|
||||
if ($itemtype == Example::class) {
|
||||
// Return array data containing all params to add : may be single data or array data
|
||||
// Search config are available from session variable
|
||||
@@ -444,6 +511,7 @@ function plugin_example_addParamFordynamicReport($itemtype) {
|
||||
'add2' => ['tutu' => 'Second Add',
|
||||
'Other Data']];
|
||||
}
|
||||
|
||||
// Return false or a non array data if not needed
|
||||
return false;
|
||||
}
|
||||
@@ -454,7 +522,8 @@ function plugin_example_addParamFordynamicReport($itemtype) {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function plugin_example_install() {
|
||||
function plugin_example_install()
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$migration = new Migration(PLUGIN_EXAMPLE_VERSION);
|
||||
@@ -470,7 +539,7 @@ function plugin_example_install() {
|
||||
$default_collation = DBConnection::getDefaultCollation();
|
||||
$default_key_sign = DBConnection::getDefaultPrimaryKeySignOption();
|
||||
|
||||
if (!$DB->tableExists("glpi_plugin_example_examples")) {
|
||||
if (!$DB->tableExists('glpi_plugin_example_examples')) {
|
||||
$query = "CREATE TABLE `glpi_plugin_example_examples` (
|
||||
`id` int {$default_key_sign} NOT NULL auto_increment,
|
||||
`name` varchar(255) default NULL,
|
||||
@@ -482,7 +551,7 @@ function plugin_example_install() {
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
|
||||
|
||||
$DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error());
|
||||
$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`,
|
||||
@@ -490,10 +559,10 @@ function plugin_example_install() {
|
||||
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 populate glpi_plugin_example ' . $DB->error());
|
||||
}
|
||||
|
||||
if (!$DB->tableExists("glpi_plugin_example_dropdowns")) {
|
||||
if (!$DB->tableExists('glpi_plugin_example_dropdowns')) {
|
||||
$query = "CREATE TABLE `glpi_plugin_example_dropdowns` (
|
||||
`id` int {$default_key_sign} NOT NULL auto_increment,
|
||||
`name` varchar(255) default NULL,
|
||||
@@ -502,15 +571,14 @@ function plugin_example_install() {
|
||||
KEY `name` (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
|
||||
|
||||
$DB->query($query) or die("error creating glpi_plugin_example_dropdowns". $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());
|
||||
|
||||
$DB->query($query) or die('error populate glpi_plugin_example_dropdowns' . $DB->error());
|
||||
}
|
||||
|
||||
if (!$DB->tableExists('glpi_plugin_example_devicecameras')) {
|
||||
@@ -524,7 +592,7 @@ function plugin_example_install() {
|
||||
KEY `manufacturers_id` (`manufacturers_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
|
||||
|
||||
$DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error());
|
||||
$DB->query($query) or die('error creating glpi_plugin_example_examples ' . $DB->error());
|
||||
}
|
||||
|
||||
if (!$DB->tableExists('glpi_plugin_example_items_devicecameras')) {
|
||||
@@ -542,12 +610,13 @@ function plugin_example_install() {
|
||||
KEY `is_dynamic` (`is_dynamic`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
|
||||
|
||||
$DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error());
|
||||
$DB->query($query) or die('error creating glpi_plugin_example_examples ' . $DB->error());
|
||||
}
|
||||
|
||||
// To be called for each task the plugin manage
|
||||
// task in class
|
||||
CronTask::Register(Example::class, 'Sample', DAY_TIMESTAMP, ['param' => 50]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -557,7 +626,8 @@ function plugin_example_install() {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function plugin_example_uninstall() {
|
||||
function plugin_example_uninstall()
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$config = new Config();
|
||||
@@ -573,52 +643,58 @@ function plugin_example_uninstall() {
|
||||
$notif->delete($data);
|
||||
}
|
||||
// Old version tables
|
||||
if ($DB->tableExists("glpi_dropdown_plugin_example")) {
|
||||
$query = "DROP TABLE `glpi_dropdown_plugin_example`";
|
||||
$DB->query($query) or die("error deleting glpi_dropdown_plugin_example");
|
||||
if ($DB->tableExists('glpi_dropdown_plugin_example')) {
|
||||
$query = 'DROP TABLE `glpi_dropdown_plugin_example`';
|
||||
$DB->query($query) or die('error deleting glpi_dropdown_plugin_example');
|
||||
}
|
||||
if ($DB->tableExists("glpi_plugin_example")) {
|
||||
$query = "DROP TABLE `glpi_plugin_example`";
|
||||
$DB->query($query) or die("error deleting glpi_plugin_example");
|
||||
if ($DB->tableExists('glpi_plugin_example')) {
|
||||
$query = 'DROP TABLE `glpi_plugin_example`';
|
||||
$DB->query($query) or die('error deleting glpi_plugin_example');
|
||||
}
|
||||
// Current version tables
|
||||
if ($DB->tableExists("glpi_plugin_example_example")) {
|
||||
$query = "DROP TABLE `glpi_plugin_example_example`";
|
||||
$DB->query($query) or die("error deleting glpi_plugin_example_example");
|
||||
if ($DB->tableExists('glpi_plugin_example_example')) {
|
||||
$query = 'DROP TABLE `glpi_plugin_example_example`';
|
||||
$DB->query($query) or die('error deleting glpi_plugin_example_example');
|
||||
}
|
||||
if ($DB->tableExists("glpi_plugin_example_dropdowns")) {
|
||||
$query = "DROP TABLE `glpi_plugin_example_dropdowns`;";
|
||||
$DB->query($query) or die("error deleting glpi_plugin_example_dropdowns");
|
||||
if ($DB->tableExists('glpi_plugin_example_dropdowns')) {
|
||||
$query = 'DROP TABLE `glpi_plugin_example_dropdowns`;';
|
||||
$DB->query($query) or die('error deleting glpi_plugin_example_dropdowns');
|
||||
}
|
||||
if ($DB->tableExists("glpi_plugin_example_devicecameras")) {
|
||||
$query = "DROP TABLE `glpi_plugin_example_devicecameras`;";
|
||||
$DB->query($query) or die("error deleting glpi_plugin_example_devicecameras");
|
||||
if ($DB->tableExists('glpi_plugin_example_devicecameras')) {
|
||||
$query = 'DROP TABLE `glpi_plugin_example_devicecameras`;';
|
||||
$DB->query($query) or die('error deleting glpi_plugin_example_devicecameras');
|
||||
}
|
||||
if ($DB->tableExists("glpi_plugin_example_items_devicecameras")) {
|
||||
$query = "DROP TABLE `glpi_plugin_example_items_devicecameras`;";
|
||||
$DB->query($query) or die("error deleting glpi_plugin_example_items_devicecameras");
|
||||
if ($DB->tableExists('glpi_plugin_example_items_devicecameras')) {
|
||||
$query = 'DROP TABLE `glpi_plugin_example_items_devicecameras`;';
|
||||
$DB->query($query) or die('error deleting glpi_plugin_example_items_devicecameras');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_AssignToTicket($types) {
|
||||
$types[Example::class] = "Example";
|
||||
function plugin_example_AssignToTicket($types)
|
||||
{
|
||||
$types[Example::class] = 'Example';
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_get_events(NotificationTargetTicket $target) {
|
||||
$target->events['plugin_example'] = __("Example event", 'example');
|
||||
function plugin_example_get_events(NotificationTargetTicket $target)
|
||||
{
|
||||
$target->events['plugin_example'] = __('Example event', 'example');
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_get_datas(NotificationTargetTicket $target) {
|
||||
$target->data['##ticket.example##'] = __("Example datas", 'example');
|
||||
function plugin_example_get_datas(NotificationTargetTicket $target)
|
||||
{
|
||||
$target->data['##ticket.example##'] = __('Example datas', 'example');
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_postinit() {
|
||||
function plugin_example_postinit()
|
||||
{
|
||||
global $CFG_GLPI;
|
||||
|
||||
// All plugins are initialized, so all types are registered
|
||||
@@ -636,7 +712,8 @@ function plugin_example_postinit() {
|
||||
*
|
||||
* @return un tableau
|
||||
**/
|
||||
function plugin_retrieve_more_data_from_ldap_example(array $datas) {
|
||||
function plugin_retrieve_more_data_from_ldap_example(array $datas)
|
||||
{
|
||||
return $datas;
|
||||
}
|
||||
|
||||
@@ -648,47 +725,54 @@ function plugin_retrieve_more_data_from_ldap_example(array $datas) {
|
||||
*
|
||||
* @return un tableau
|
||||
**/
|
||||
function plugin_retrieve_more_field_from_ldap_example($fields) {
|
||||
function plugin_retrieve_more_field_from_ldap_example($fields)
|
||||
{
|
||||
return $fields;
|
||||
}
|
||||
|
||||
// Check to add to status page
|
||||
function plugin_example_Status($param) {
|
||||
function plugin_example_Status($param)
|
||||
{
|
||||
// Do checks (no check for example)
|
||||
$ok = true;
|
||||
echo "example plugin: example";
|
||||
echo 'example plugin: example';
|
||||
if ($ok) {
|
||||
echo "_OK";
|
||||
echo '_OK';
|
||||
} else {
|
||||
echo "_PROBLEM";
|
||||
echo '_PROBLEM';
|
||||
// Only set ok to false if trouble (global status)
|
||||
$param['ok'] = false;
|
||||
}
|
||||
echo "\n";
|
||||
|
||||
return $param;
|
||||
}
|
||||
|
||||
function plugin_example_display_central() {
|
||||
function plugin_example_display_central()
|
||||
{
|
||||
echo "<tr><th colspan='2'>";
|
||||
echo "<div style='text-align:center; font-size:2em'>";
|
||||
echo __("Plugin example displays on central page", "example");
|
||||
echo "</div>";
|
||||
echo "</th></tr>";
|
||||
echo __('Plugin example displays on central page', 'example');
|
||||
echo '</div>';
|
||||
echo '</th></tr>';
|
||||
}
|
||||
|
||||
function plugin_example_display_login() {
|
||||
function plugin_example_display_login()
|
||||
{
|
||||
echo "<div style='text-align:center; font-size:2em'>";
|
||||
echo __("Plugin example displays on login page", "example");
|
||||
echo "</div>";
|
||||
echo __('Plugin example displays on login page', 'example');
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
function plugin_example_infocom_hook($params) {
|
||||
function plugin_example_infocom_hook($params)
|
||||
{
|
||||
echo "<tr><th colspan='4'>";
|
||||
echo __("Plugin example displays on central page", "example");
|
||||
echo "</th></tr>";
|
||||
echo __('Plugin example displays on central page', 'example');
|
||||
echo '</th></tr>';
|
||||
}
|
||||
|
||||
function plugin_example_filter_actors(array $params = []): array {
|
||||
function plugin_example_filter_actors(array $params = []): array
|
||||
{
|
||||
$itemtype = $params['params']['itemtype'];
|
||||
$items_id = $params['params']['items_id'];
|
||||
|
||||
@@ -704,7 +788,8 @@ function plugin_example_filter_actors(array $params = []): array {
|
||||
return $params;
|
||||
}
|
||||
|
||||
function plugin_example_set_impact_icon(array $params) {
|
||||
function plugin_example_set_impact_icon(array $params)
|
||||
{
|
||||
$itemtype = $params['itemtype'];
|
||||
$items_id = $params['items_id'];
|
||||
|
||||
@@ -712,5 +797,6 @@ function plugin_example_set_impact_icon(array $params) {
|
||||
if ($item instanceof Computer && $item->getFromDB($items_id)) {
|
||||
return Plugin::getWebDir('example', true, false) . '/public/computer_icon.svg';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@@ -38,12 +38,12 @@
|
||||
|
||||
// Entry menu case
|
||||
define('GLPI_ROOT', '../..');
|
||||
include (GLPI_ROOT . "/inc/includes.php");
|
||||
include(GLPI_ROOT . '/inc/includes.php');
|
||||
|
||||
Session::checkRight(Config::$rightname, UPDATE);
|
||||
|
||||
Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins");
|
||||
Html::header('TITRE', $_SERVER['PHP_SELF'], 'plugins');
|
||||
|
||||
echo "This is the plugin report page";
|
||||
echo 'This is the plugin report page';
|
||||
|
||||
Html::footer();
|
||||
|
58
setup.php
58
setup.php
@@ -52,7 +52,8 @@ define('PLUGIN_EXAMPLE_MAX_GLPI', '10.0.99');
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_init_example() {
|
||||
function plugin_init_example()
|
||||
{
|
||||
global $PLUGIN_HOOKS,$CFG_GLPI;
|
||||
|
||||
// Params : plugin name - string type - ID - Array of attributes
|
||||
@@ -68,16 +69,22 @@ function plugin_init_example() {
|
||||
|
||||
$types = ['Central', 'Computer', 'ComputerDisk', 'Notification', 'Phone',
|
||||
'Preference', 'Profile', 'Supplier'];
|
||||
Plugin::registerClass(Example::class,
|
||||
Plugin::registerClass(
|
||||
Example::class,
|
||||
['notificationtemplates_types' => true,
|
||||
'addtabon' => $types,
|
||||
'link_types' => true]);
|
||||
'link_types' => true],
|
||||
);
|
||||
|
||||
Plugin::registerClass(RuleTestCollection::class,
|
||||
['rulecollections_types' => true]);
|
||||
Plugin::registerClass(
|
||||
RuleTestCollection::class,
|
||||
['rulecollections_types' => true],
|
||||
);
|
||||
|
||||
Plugin::registerClass(DeviceCamera::class,
|
||||
['device_types' => true]);
|
||||
Plugin::registerClass(
|
||||
DeviceCamera::class,
|
||||
['device_types' => true],
|
||||
);
|
||||
|
||||
if (version_compare(GLPI_VERSION, '9.1', 'ge')) {
|
||||
if (class_exists(Example::class)) {
|
||||
@@ -187,7 +194,7 @@ function plugin_init_example() {
|
||||
'properties' => [
|
||||
'name' => 'robots',
|
||||
'content' => 'noindex, nofollow',
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'tag' => 'link',
|
||||
@@ -196,7 +203,7 @@ function plugin_init_example() {
|
||||
'type' => 'application/rss+xml',
|
||||
'title' => 'The company RSS feed',
|
||||
'href' => 'https://example.org/feed.xml',
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -212,7 +219,7 @@ function plugin_init_example() {
|
||||
'properties' => [
|
||||
'name' => 'robots',
|
||||
'content' => 'noindex, nofollow',
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'tag' => 'link',
|
||||
@@ -221,7 +228,7 @@ function plugin_init_example() {
|
||||
'type' => 'application/rss+xml',
|
||||
'title' => 'The company RSS feed',
|
||||
'href' => 'https://example.org/feed.xml',
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -246,9 +253,9 @@ function plugin_init_example() {
|
||||
// CSRF compliance : All actions must be done via POST and forms closed by Html::closeForm();
|
||||
$PLUGIN_HOOKS[Hooks::CSRF_COMPLIANT]['example'] = true;
|
||||
|
||||
$PLUGIN_HOOKS[Hooks::DISPLAY_CENTRAL]['example'] = "plugin_example_display_central";
|
||||
$PLUGIN_HOOKS[Hooks::DISPLAY_LOGIN]['example'] = "plugin_example_display_login";
|
||||
$PLUGIN_HOOKS[Hooks::INFOCOM]['example'] = "plugin_example_infocom_hook";
|
||||
$PLUGIN_HOOKS[Hooks::DISPLAY_CENTRAL]['example'] = 'plugin_example_display_central';
|
||||
$PLUGIN_HOOKS[Hooks::DISPLAY_LOGIN]['example'] = 'plugin_example_display_login';
|
||||
$PLUGIN_HOOKS[Hooks::INFOCOM]['example'] = 'plugin_example_infocom_hook';
|
||||
|
||||
// pre_show and post_show for tabs and items,
|
||||
// see GlpiPlugin\Example\Showtabitem class for implementation explanations
|
||||
@@ -268,7 +275,7 @@ function plugin_init_example() {
|
||||
|
||||
// Add new actions to timeline
|
||||
$PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['example'] = [
|
||||
ItemForm::class, 'timelineActions'
|
||||
ItemForm::class, 'timelineActions',
|
||||
];
|
||||
|
||||
// declare this plugin as an import plugin for Computer itemtype
|
||||
@@ -276,10 +283,10 @@ function plugin_init_example() {
|
||||
|
||||
// add additional informations on Computer::showForm
|
||||
$PLUGIN_HOOKS[Hooks::AUTOINVENTORY_INFORMATION]['example'] = [
|
||||
Computer::class => [Computer::class, 'showInfo']
|
||||
Computer::class => [Computer::class, 'showInfo'],
|
||||
];
|
||||
|
||||
$PLUGIN_HOOKS[Hooks::FILTER_ACTORS]['example'] = "plugin_example_filter_actors";
|
||||
$PLUGIN_HOOKS[Hooks::FILTER_ACTORS]['example'] = 'plugin_example_filter_actors';
|
||||
|
||||
// add new cards to dashboard grid
|
||||
$PLUGIN_HOOKS['dashboard_types']['example'] = [Example::class, 'dashboardTypes'];
|
||||
@@ -287,7 +294,7 @@ function plugin_init_example() {
|
||||
|
||||
// Dashboard filter
|
||||
$PLUGIN_HOOKS[Hooks::DASHBOARD_FILTERS]['example'] = [
|
||||
ComputerModelFilter::class
|
||||
ComputerModelFilter::class,
|
||||
];
|
||||
|
||||
//TODO: remove check when GLPI 11.0.0 is released
|
||||
@@ -304,7 +311,8 @@ function plugin_init_example() {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function plugin_version_example() {
|
||||
function plugin_version_example()
|
||||
{
|
||||
return [
|
||||
'name' => 'Plugin Example',
|
||||
'version' => PLUGIN_EXAMPLE_VERSION,
|
||||
@@ -315,8 +323,8 @@ function plugin_version_example() {
|
||||
'glpi' => [
|
||||
'min' => PLUGIN_EXAMPLE_MIN_GLPI,
|
||||
'max' => PLUGIN_EXAMPLE_MAX_GLPI,
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -327,10 +335,12 @@ function plugin_version_example() {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function plugin_example_check_prerequisites() {
|
||||
function plugin_example_check_prerequisites()
|
||||
{
|
||||
if (false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -341,7 +351,8 @@ function plugin_example_check_prerequisites() {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function plugin_example_check_config($verbose = false) {
|
||||
function plugin_example_check_config($verbose = false)
|
||||
{
|
||||
if (true) { // Your configuration check
|
||||
return true;
|
||||
}
|
||||
@@ -349,5 +360,6 @@ function plugin_example_check_config($verbose = false) {
|
||||
if ($verbose) {
|
||||
echo __('Installed / not configured', 'example');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use CommonDBChild;
|
||||
use Session;
|
||||
|
||||
@@ -43,12 +44,11 @@ use Session;
|
||||
// enhancements.
|
||||
// For CommonDBRelation, the variable are quiet equivalent, but they use _1 and _2 for each side
|
||||
// parent
|
||||
class Child extends CommonDBChild {
|
||||
|
||||
class Child extends CommonDBChild
|
||||
{
|
||||
// A child rely on an item. If $itemtype=='itemtype', then that is a variable item.
|
||||
static public $itemtype = 'itemtype';
|
||||
static public $items_id = 'items_id';
|
||||
|
||||
public static $itemtype = 'itemtype';
|
||||
public static $items_id = 'items_id';
|
||||
|
||||
// With 0.84, you have to specify each right (create, view, update and delete), because
|
||||
// CommonDBChild(s) and CommonDBRelation(s) mainly depend on the rights on the parent item
|
||||
@@ -59,48 +59,43 @@ class Child extends CommonDBChild {
|
||||
// - CommonDBConnexity::HAVE_SAME_RIGHT_ON_ITEM we must have at least update right
|
||||
// on the item
|
||||
// * $mustBeAttached: some CommonDBChild can be free, without any parent.
|
||||
static function canCreate() {
|
||||
|
||||
public static function canCreate()
|
||||
{
|
||||
return (Session::haveRight('internet', UPDATE)
|
||||
&& parent::canCreate());
|
||||
}
|
||||
|
||||
|
||||
static function canView() {
|
||||
|
||||
public static function canView()
|
||||
{
|
||||
return (Session::haveRight('internet', READ)
|
||||
&& parent::canView());
|
||||
}
|
||||
|
||||
|
||||
static function canUpdate() {
|
||||
|
||||
public static function canUpdate()
|
||||
{
|
||||
return (Session::haveRight('internet', UPDATE)
|
||||
&& parent::canUpdate());
|
||||
}
|
||||
|
||||
|
||||
static function canDelete() {
|
||||
|
||||
public static function canDelete()
|
||||
{
|
||||
return (Session::haveRight('internet', DELETE)
|
||||
&& parent::canDelete());
|
||||
}
|
||||
|
||||
|
||||
// By default, post_addItem, post_updateItem and post_deleteFromDB are defined.
|
||||
// They define the history to add to the parents
|
||||
// This method define the name to set inside the history of the parent.
|
||||
// All these methods use $log_history_add, $log_history_update and $log_history_delete to
|
||||
// define the level of log (Log::HISTORY_ADD_DEVICE, Log::HISTORY_UPDATE_DEVICE ...)
|
||||
function getHistoryName_for_item($case) {
|
||||
}
|
||||
public function getHistoryName_for_item($case) {}
|
||||
|
||||
// CommonDBChild also check if we can add or updatethe item regarding the new item
|
||||
// ($input[static::$itemtype] and $input[static::$items_id]).
|
||||
// But don't forget to call parent::prepareInputForAdd()
|
||||
function prepareInputForAdd($input) {
|
||||
public function prepareInputForAdd($input)
|
||||
{
|
||||
// My preparation on $input
|
||||
return parent::prepareInputForAdd($input);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use CommonDBTM;
|
||||
|
||||
// Class of the defined type
|
||||
@@ -42,10 +43,10 @@ if (!defined('GLPI_ROOT')) {
|
||||
die("Sorry. You can't access directly to this file");
|
||||
}
|
||||
|
||||
class Computer extends CommonDBTM {
|
||||
|
||||
static function showInfo() {
|
||||
|
||||
class Computer extends CommonDBTM
|
||||
{
|
||||
public static function showInfo()
|
||||
{
|
||||
echo '<table class="tab_glpi" width="100%">';
|
||||
echo '<tr>';
|
||||
echo '<th>' . __('More information') . '</th>';
|
||||
@@ -58,26 +59,24 @@ class Computer extends CommonDBTM {
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
|
||||
static function item_can($item) {
|
||||
|
||||
public static function item_can($item)
|
||||
{
|
||||
if (($item->getType() == 'Computer')
|
||||
&& ($item->right == READ)
|
||||
&& ($item->fields['groups_id'] > 0)
|
||||
&& !in_array($item->fields['groups_id'], $_SESSION["glpigroups"])) {
|
||||
&& !in_array($item->fields['groups_id'], $_SESSION['glpigroups'])) {
|
||||
$item->right = 0; // unknown, so denied.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static function add_default_where($in) {
|
||||
|
||||
public static function add_default_where($in)
|
||||
{
|
||||
list($itemtype, $condition) = $in;
|
||||
if ($itemtype == 'Computer') {
|
||||
$table = getTableForItemType($itemtype);
|
||||
$condition .= " (".$table.".groups_id NOT IN (".implode(',', $_SESSION["glpigroups"])."))";
|
||||
}
|
||||
return [$itemtype, $condition];
|
||||
$condition .= ' (' . $table . '.groups_id NOT IN (' . implode(',', $_SESSION['glpigroups']) . '))';
|
||||
}
|
||||
|
||||
return [$itemtype, $condition];
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@
|
||||
*/
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use CommonDBTM;
|
||||
use CommonGLPI;
|
||||
use Config as GlpiConfig;
|
||||
@@ -37,29 +38,33 @@ use Html;
|
||||
use Session;
|
||||
use Toolbox;
|
||||
|
||||
class Config extends CommonDBTM {
|
||||
|
||||
static protected $notable = true;
|
||||
|
||||
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
|
||||
class Config extends CommonDBTM
|
||||
{
|
||||
protected static $notable = true;
|
||||
|
||||
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
||||
{
|
||||
if (!$withtemplate) {
|
||||
if ($item->getType() == 'Config') {
|
||||
return __('Example plugin');
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
static function configUpdate($input) {
|
||||
public static function configUpdate($input)
|
||||
{
|
||||
$input['configuration'] = 1 - $input['configuration'];
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
function showFormExample() {
|
||||
public function showFormExample()
|
||||
{
|
||||
global $CFG_GLPI;
|
||||
|
||||
if (!Session::haveRight("config", UPDATE)) {
|
||||
if (!Session::haveRight('config', UPDATE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -68,29 +73,28 @@ class Config extends CommonDBTM {
|
||||
echo "<form name='form' action=\"" . Toolbox::getItemTypeFormURL('Config') . "\" method='post'>";
|
||||
echo "<div class='center' id='tabsbody'>";
|
||||
echo "<table class='tab_cadre_fixe'>";
|
||||
echo "<tr><th colspan='4'>" . __('Example setup') . "</th></tr>";
|
||||
echo "<td >" . __('My boolean choice :') . "</td>";
|
||||
echo "<tr><th colspan='4'>" . __('Example setup') . '</th></tr>';
|
||||
echo '<td >' . __('My boolean choice :') . '</td>';
|
||||
echo "<td colspan='3'>";
|
||||
echo "<input type='hidden' name='config_class' value='" . __CLASS__ . "'>";
|
||||
echo "<input type='hidden' name='config_context' value='plugin:Example'>";
|
||||
Dropdown::showYesNo("configuration", $my_config['configuration']);
|
||||
echo "</td></tr>";
|
||||
Dropdown::showYesNo('configuration', $my_config['configuration']);
|
||||
echo '</td></tr>';
|
||||
|
||||
echo "<tr class='tab_bg_2'>";
|
||||
echo "<td colspan='4' class='center'>";
|
||||
echo "<input type='submit' name='update' class='submit' value=\""._sx('button', 'Save')."\">";
|
||||
echo "</td></tr>";
|
||||
echo "<input type='submit' name='update' class='submit' value=\"" . _sx('button', 'Save') . '">';
|
||||
echo '</td></tr>';
|
||||
|
||||
echo "</table></div>";
|
||||
echo '</table></div>';
|
||||
Html::closeForm();
|
||||
}
|
||||
|
||||
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
|
||||
|
||||
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
|
||||
{
|
||||
if ($item->getType() == 'Config') {
|
||||
$config = new self();
|
||||
$config->showFormExample();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use CommonDevice;
|
||||
|
||||
// Class of the defined type
|
||||
@@ -43,10 +44,10 @@ if (!defined('GLPI_ROOT')) {
|
||||
}
|
||||
|
||||
/// Class DeviceCamera
|
||||
class DeviceCamera extends CommonDevice {
|
||||
|
||||
static function getTypeName($nb = 0) {
|
||||
class DeviceCamera extends CommonDevice
|
||||
{
|
||||
public static function getTypeName($nb = 0)
|
||||
{
|
||||
return _n('Camera', 'Cameras', $nb);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -55,14 +55,15 @@ along with GLPI. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use Document as GlpiDocument;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
die("Sorry. You can't access this file directly");
|
||||
}
|
||||
|
||||
class Document extends GlpiDocument {
|
||||
|
||||
class Document extends GlpiDocument
|
||||
{
|
||||
/**
|
||||
* Return the table used to store this object. Overloads the implementation in CommonDBTM
|
||||
*
|
||||
@@ -70,7 +71,8 @@ class Document extends GlpiDocument {
|
||||
*
|
||||
* @return string
|
||||
**/
|
||||
public static function getTable($classname = null) {
|
||||
public static function getTable($classname = null)
|
||||
{
|
||||
if ($classname === null) {
|
||||
$classname = get_called_class();
|
||||
}
|
||||
@@ -87,7 +89,8 @@ class Document extends GlpiDocument {
|
||||
* @param array $input
|
||||
* @return array|false
|
||||
*/
|
||||
public function prepareInputForAdd($input) {
|
||||
public function prepareInputForAdd($input)
|
||||
{
|
||||
$input['_only_if_upload_succeed'] = true;
|
||||
if (!isset($_FILES['file'])) {
|
||||
return false;
|
||||
@@ -110,7 +113,8 @@ class Document extends GlpiDocument {
|
||||
* @param array $input
|
||||
* @return array|false
|
||||
*/
|
||||
public function prepareInputForUpdate($input) {
|
||||
public function prepareInputForUpdate($input)
|
||||
{
|
||||
// Do not allow update of document
|
||||
return false;
|
||||
}
|
||||
@@ -121,7 +125,8 @@ class Document extends GlpiDocument {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function post_getFromDB() {
|
||||
public function post_getFromDB()
|
||||
{
|
||||
// Check the user can view this itemtype and can view this item
|
||||
if ($this->canView() && $this->canViewItem()) {
|
||||
if (isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/octet-stream'
|
||||
@@ -136,12 +141,13 @@ class Document extends GlpiDocument {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function sendFile() {
|
||||
protected function sendFile()
|
||||
{
|
||||
$streamSource = GLPI_DOC_DIR . '/' . $this->fields['filepath'];
|
||||
|
||||
// Ensure the file exists
|
||||
if (!file_exists($streamSource) || !is_file($streamSource)) {
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -156,7 +162,7 @@ class Document extends GlpiDocument {
|
||||
// Open the file
|
||||
$fileHandle = @fopen($streamSource, 'rb');
|
||||
if (!$fileHandle) {
|
||||
header ("HTTP/1.0 500 Internal Server Error");
|
||||
header('HTTP/1.0 500 Internal Server Error');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -175,7 +181,7 @@ class Document extends GlpiDocument {
|
||||
// seek to the begining of the range
|
||||
$currentPosition = $begin;
|
||||
if (fseek($fileHandle, $begin, SEEK_SET) < 0) {
|
||||
header("HTTP/1.0 500 Internal Server Error");
|
||||
header('HTTP/1.0 500 Internal Server Error');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -183,10 +189,10 @@ class Document extends GlpiDocument {
|
||||
// example : less bytes than the expected range
|
||||
// send meta data
|
||||
// setup client's cache behavior
|
||||
header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
|
||||
header('Expires: Mon, 26 Nov 1962 00:00:00 GMT');
|
||||
header('Pragma: private'); /// IE BUG + SSL
|
||||
header('Cache-control: private, must-revalidate'); /// IE BUG + SSL
|
||||
header("Content-disposition: attachment; filename=\"" . $this->fields['filename'] . "\"");
|
||||
header('Content-disposition: attachment; filename="' . $this->fields['filename'] . '"');
|
||||
header("Content-type: $mimeType");
|
||||
header("Last-Modified: $time");
|
||||
header('Accept-Ranges: bytes');
|
||||
@@ -208,7 +214,7 @@ class Document extends GlpiDocument {
|
||||
set_time_limit(10);
|
||||
$content = fread($fileHandle, min(1024 * 16, $end - $currentPosition + 1));
|
||||
if ($content === false) {
|
||||
header("HTTP/1.0 500 Internal Server Error", true); // Replace previously sent headers
|
||||
header('HTTP/1.0 500 Internal Server Error', true); // Replace previously sent headers
|
||||
exit(0);
|
||||
} else {
|
||||
print $content;
|
||||
@@ -220,5 +226,4 @@ class Document extends GlpiDocument {
|
||||
// End now to prevent any unwanted bytes
|
||||
exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -32,18 +32,20 @@
|
||||
// Original Author of file:
|
||||
// Purpose of file:
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use CommonDropdown;
|
||||
|
||||
// Class for a Dropdown
|
||||
class Dropdown extends CommonDropdown {
|
||||
|
||||
|
||||
static function getTypeName($nb = 0) {
|
||||
|
||||
class Dropdown extends CommonDropdown
|
||||
{
|
||||
public static function getTypeName($nb = 0)
|
||||
{
|
||||
if ($nb > 0) {
|
||||
return __('Plugin Example Dropdowns', 'example');
|
||||
}
|
||||
|
||||
return __('Plugin Example Dropdowns', 'example');
|
||||
}
|
||||
}
|
||||
|
308
src/Example.php
308
src/Example.php
@@ -34,6 +34,7 @@
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use CommonDBTM;
|
||||
use CommonGLPI;
|
||||
use Computer;
|
||||
@@ -43,33 +44,36 @@ use MassiveAction;
|
||||
use Session;
|
||||
|
||||
// Class of the defined type
|
||||
class Example extends CommonDBTM {
|
||||
|
||||
static $tags = '[EXAMPLE_ID]';
|
||||
class Example extends CommonDBTM
|
||||
{
|
||||
public static $tags = '[EXAMPLE_ID]';
|
||||
public static $rightname = 'plugin_example';
|
||||
|
||||
// Should return the localized name of the type
|
||||
static function getTypeName($nb = 0) {
|
||||
public static function getTypeName($nb = 0)
|
||||
{
|
||||
return 'Example Type';
|
||||
}
|
||||
|
||||
static function getMenuName() {
|
||||
public static function getMenuName()
|
||||
{
|
||||
return __('Example plugin');
|
||||
}
|
||||
|
||||
static function getAdditionalMenuLinks() {
|
||||
public static function getAdditionalMenuLinks()
|
||||
{
|
||||
global $CFG_GLPI;
|
||||
$links = [];
|
||||
|
||||
$links['config'] = '/plugins/example/index.php';
|
||||
$links["<img src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".__s('Show all')."' alt='".__s('Show all')."'>"] = '/plugins/example/index.php';
|
||||
$links["<img src='" . $CFG_GLPI['root_doc'] . "/pics/menu_showall.png' title='" . __s('Show all') . "' alt='" . __s('Show all') . "'>"] = '/plugins/example/index.php';
|
||||
$links[__s('Test link', 'example')] = '/plugins/example/index.php';
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
function defineTabs($options = []) {
|
||||
|
||||
public function defineTabs($options = [])
|
||||
{
|
||||
$ong = [];
|
||||
$this->addDefaultFormTab($ong);
|
||||
$this->addStandardTab('Link', $ong, $options);
|
||||
@@ -77,7 +81,8 @@ class Example extends CommonDBTM {
|
||||
return $ong;
|
||||
}
|
||||
|
||||
function showForm($ID, array $options = []) {
|
||||
public function showForm($ID, array $options = [])
|
||||
{
|
||||
global $CFG_GLPI;
|
||||
|
||||
$this->initForm($ID, $options);
|
||||
@@ -85,23 +90,23 @@ class Example extends CommonDBTM {
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
|
||||
echo "<td>" . __('ID') . "</td>";
|
||||
echo "<td>";
|
||||
echo '<td>' . __('ID') . '</td>';
|
||||
echo '<td>';
|
||||
echo $ID;
|
||||
echo "</td>";
|
||||
echo '</td>';
|
||||
|
||||
$this->showFormButtons($options);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function rawSearchOptions() {
|
||||
|
||||
public function rawSearchOptions()
|
||||
{
|
||||
$tab = [];
|
||||
|
||||
$tab[] = [
|
||||
'id' => 'common',
|
||||
'name' => __('Header Needed')
|
||||
'name' => __('Header Needed'),
|
||||
];
|
||||
|
||||
$tab[] = [
|
||||
@@ -139,7 +144,6 @@ class Example extends CommonDBTM {
|
||||
return $tab;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Give localized information about 1 task
|
||||
*
|
||||
@@ -147,17 +151,17 @@ class Example extends CommonDBTM {
|
||||
*
|
||||
* @return array of strings
|
||||
*/
|
||||
static function cronInfo($name) {
|
||||
|
||||
public static function cronInfo($name)
|
||||
{
|
||||
switch ($name) {
|
||||
case 'Sample':
|
||||
return ['description' => __('Cron description for example', 'example'),
|
||||
'parameter' => __('Cron parameter for example', 'example')];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute 1 task manage by the plugin
|
||||
*
|
||||
@@ -168,9 +172,9 @@ class Example extends CommonDBTM {
|
||||
* <0 : to be run again (not finished)
|
||||
* 0 : nothing to do
|
||||
*/
|
||||
static function cronSample($task) {
|
||||
|
||||
$task->log("Example log message from class");
|
||||
public static function cronSample($task)
|
||||
{
|
||||
$task->log('Example log message from class');
|
||||
$r = mt_rand(0, $task->fields['param']);
|
||||
usleep(1000000 + $r * 1000);
|
||||
$task->setVolume($r);
|
||||
@@ -178,33 +182,34 @@ class Example extends CommonDBTM {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Hook done on before add item case (data from form, not altered)
|
||||
static function pre_item_add_computer(Computer $item) {
|
||||
public static function pre_item_add_computer(Computer $item)
|
||||
{
|
||||
if (isset($item->input['name']) && empty($item->input['name'])) {
|
||||
Session::addMessageAfterRedirect("Pre Add Computer Hook KO (name empty)", true);
|
||||
Session::addMessageAfterRedirect('Pre Add Computer Hook KO (name empty)', true);
|
||||
|
||||
return $item->input = false;
|
||||
} else {
|
||||
Session::addMessageAfterRedirect("Pre Add Computer Hook OK", true);
|
||||
Session::addMessageAfterRedirect('Pre Add Computer Hook OK', true);
|
||||
}
|
||||
}
|
||||
|
||||
// Hook done on before add item case (data altered by object prepareInputForAdd)
|
||||
static function post_prepareadd_computer(Computer $item) {
|
||||
Session::addMessageAfterRedirect("Post prepareAdd Computer Hook", true);
|
||||
public static function post_prepareadd_computer(Computer $item)
|
||||
{
|
||||
Session::addMessageAfterRedirect('Post prepareAdd Computer Hook', true);
|
||||
}
|
||||
|
||||
|
||||
// Hook done on add item case
|
||||
static function item_add_computer(Computer $item) {
|
||||
public static function item_add_computer(Computer $item)
|
||||
{
|
||||
Session::addMessageAfterRedirect('Add Computer Hook, ID=' . $item->getID(), true);
|
||||
|
||||
Session::addMessageAfterRedirect("Add Computer Hook, ID=".$item->getID(), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
|
||||
|
||||
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
||||
{
|
||||
if (!$withtemplate) {
|
||||
switch ($item->getType()) {
|
||||
case 'Profile':
|
||||
@@ -215,37 +220,39 @@ class Example extends CommonDBTM {
|
||||
|
||||
case 'Phone':
|
||||
if ($_SESSION['glpishow_count_on_tabs']) {
|
||||
return self::createTabEntry(__('Example', 'example'),
|
||||
countElementsInTable($this->getTable()));
|
||||
return self::createTabEntry(
|
||||
__('Example', 'example'),
|
||||
countElementsInTable($this->getTable()),
|
||||
);
|
||||
}
|
||||
|
||||
return __('Example', 'example');
|
||||
|
||||
case 'ComputerDisk':
|
||||
case 'Supplier':
|
||||
return [1 => __("Test Plugin", 'example'),
|
||||
2 => __("Test Plugin 2", 'example')];
|
||||
return [1 => __('Test Plugin', 'example'),
|
||||
2 => __('Test Plugin 2', 'example')];
|
||||
|
||||
case 'Computer':
|
||||
case 'Central':
|
||||
case 'Preference':
|
||||
case 'Notification':
|
||||
return [1 => __("Test Plugin", 'example')];
|
||||
return [1 => __('Test Plugin', 'example')];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
|
||||
|
||||
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
|
||||
{
|
||||
switch ($item->getType()) {
|
||||
case 'Phone':
|
||||
echo __("Plugin Example on Phone", 'example');
|
||||
echo __('Plugin Example on Phone', 'example');
|
||||
break;
|
||||
|
||||
case 'Central':
|
||||
echo __("Plugin central action", 'example');
|
||||
echo __('Plugin central action', 'example');
|
||||
break;
|
||||
|
||||
case 'Preference':
|
||||
@@ -254,21 +261,21 @@ class Example extends CommonDBTM {
|
||||
|
||||
echo "<form action='Where to post form'>";
|
||||
echo "<table class='tab_cadre_fixe'>";
|
||||
echo "<tr><th colspan='3'>".$data['name']." - ".$data['version'];
|
||||
echo "</th></tr>";
|
||||
echo "<tr><th colspan='3'>" . $data['name'] . ' - ' . $data['version'];
|
||||
echo '</th></tr>';
|
||||
|
||||
echo "<tr class='tab_bg_1'><td>Name of the pref</td>";
|
||||
echo "<td>Input to set the pref</td>";
|
||||
echo '<td>Input to set the pref</td>';
|
||||
|
||||
echo "<td><input class='submit' type='submit' name='submit' value='submit'></td>";
|
||||
echo "</tr>";
|
||||
echo '</tr>';
|
||||
|
||||
echo "</table>";
|
||||
echo "</form>";
|
||||
echo '</table>';
|
||||
echo '</form>';
|
||||
break;
|
||||
|
||||
case 'Notification':
|
||||
echo __("Plugin mailing action", 'example');
|
||||
echo __('Plugin mailing action', 'example');
|
||||
break;
|
||||
|
||||
case 'ComputerDisk':
|
||||
@@ -285,37 +292,40 @@ class Example extends CommonDBTM {
|
||||
printf(__('Plugin example CLASS=%1$s id=%2$d', 'example'), $item->getType(), $item->getField('id'));
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static function getSpecificValueToDisplay($field, $values, array $options = []) {
|
||||
|
||||
public static function getSpecificValueToDisplay($field, $values, array $options = [])
|
||||
{
|
||||
if (!is_array($values)) {
|
||||
$values = [$field => $values];
|
||||
}
|
||||
switch ($field) {
|
||||
case 'serial':
|
||||
return "S/N: ".$values[$field];
|
||||
return 'S/N: ' . $values[$field];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// 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"]
|
||||
static function populatePlanning($parm) {
|
||||
|
||||
public static function populatePlanning($parm)
|
||||
{
|
||||
// Add items in the output array
|
||||
// Items need to have an unique index beginning by the begin date of the item to display
|
||||
// needed to be correcly displayed
|
||||
$output = [];
|
||||
$key = $parm["begin"]."$$$"."plugin_example1";
|
||||
$output[$key]["begin"] = date("Y-m-d 17:00:00");
|
||||
$output[$key]["end"] = date("Y-m-d 18:00:00");
|
||||
$output[$key]["name"] = __("test planning example 1", 'example');
|
||||
$key = $parm['begin'] . '$$$' . 'plugin_example1';
|
||||
$output[$key]['begin'] = date('Y-m-d 17:00:00');
|
||||
$output[$key]['end'] = date('Y-m-d 18:00:00');
|
||||
$output[$key]['name'] = __('test planning example 1', 'example');
|
||||
// Specify the itemtype to be able to use specific display system
|
||||
$output[$key]["itemtype"] = Example::class;
|
||||
$output[$key]['itemtype'] = Example::class;
|
||||
// Set the ID using the ID of the item in the database to have unique ID
|
||||
$output[$key][getForeignKeyFieldForItemType(Example::class)] = 1;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
@@ -329,33 +339,36 @@ class Example extends CommonDBTM {
|
||||
*
|
||||
* @return Nothing (display function)
|
||||
**/
|
||||
static function displayPlanningItem(array $val, $who, $type = "", $complete = 0) {
|
||||
|
||||
public static function displayPlanningItem(array $val, $who, $type = '', $complete = 0)
|
||||
{
|
||||
// $parm["type"] say begin end in or from type
|
||||
// Add items in the items fields of the parm array
|
||||
switch ($type) {
|
||||
case "in" :
|
||||
case 'in':
|
||||
//TRANS: %1$s is the start time of a planned item, %2$s is the end
|
||||
printf(__('From %1$s to %2$s :'),
|
||||
date("H:i", strtotime($val["begin"])), date("H:i", strtotime($val["end"])));
|
||||
printf(
|
||||
__('From %1$s to %2$s :'),
|
||||
date('H:i', strtotime($val['begin'])),
|
||||
date('H:i', strtotime($val['end'])),
|
||||
);
|
||||
break;
|
||||
|
||||
case "through" :
|
||||
echo Html::resume_text($val["name"], 80);
|
||||
case 'through':
|
||||
echo Html::resume_text($val['name'], 80);
|
||||
break;
|
||||
|
||||
case "begin" :
|
||||
case 'begin':
|
||||
//TRANS: %s is the start time of a planned item
|
||||
printf(__('Start at %s:'), date("H:i", strtotime($val["begin"])));
|
||||
printf(__('Start at %s:'), date('H:i', strtotime($val['begin'])));
|
||||
break;
|
||||
|
||||
case "end" :
|
||||
case 'end':
|
||||
//TRANS: %s is the end time of a planned item
|
||||
printf(__('End at %s:'), date("H:i", strtotime($val["end"])));
|
||||
printf(__('End at %s:'), date('H:i', strtotime($val['end'])));
|
||||
break;
|
||||
}
|
||||
echo "<br>";
|
||||
echo Html::resume_text($val["name"], 80);
|
||||
echo '<br>';
|
||||
echo Html::resume_text($val['name'], 80);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,8 +380,8 @@ class Example extends CommonDBTM {
|
||||
*
|
||||
* @return string
|
||||
**/
|
||||
static function getHistoryEntry($data) {
|
||||
|
||||
public static function getHistoryEntry($data)
|
||||
{
|
||||
switch ($data['linked_action'] - Log::HISTORY_PLUGIN) {
|
||||
case 0:
|
||||
return __('History from plugin example', 'example');
|
||||
@@ -377,58 +390,65 @@ class Example extends CommonDBTM {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
////// SPECIFIC MODIF MASSIVE FUNCTIONS ///////
|
||||
function getSpecificMassiveActions($checkitem = null) {
|
||||
|
||||
public function getSpecificMassiveActions($checkitem = null)
|
||||
{
|
||||
$actions = parent::getSpecificMassiveActions($checkitem);
|
||||
|
||||
$actions['Document_Item'.MassiveAction::CLASS_ACTION_SEPARATOR.'add'] =
|
||||
_x('button', 'Add a document'); // GLPI core one
|
||||
$actions[__CLASS__.MassiveAction::CLASS_ACTION_SEPARATOR.'do_nothing'] =
|
||||
__('Do Nothing - just for fun', 'example'); // Specific one
|
||||
$actions['Document_Item' . MassiveAction::CLASS_ACTION_SEPARATOR . 'add'] = _x('button', 'Add a document'); // GLPI core one
|
||||
$actions[__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'do_nothing'] = __('Do Nothing - just for fun', 'example'); // Specific one
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
static function showMassiveActionsSubForm(MassiveAction $ma) {
|
||||
|
||||
public static function showMassiveActionsSubForm(MassiveAction $ma)
|
||||
{
|
||||
switch ($ma->getAction()) {
|
||||
case 'DoIt':
|
||||
echo " <input type='hidden' name='toto' value='1'>" .
|
||||
Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']) .
|
||||
" ".__('Write in item history', 'example');
|
||||
' ' . __('Write in item history', 'example');
|
||||
|
||||
return true;
|
||||
case 'do_nothing':
|
||||
echo " ".Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']).
|
||||
" ".__('but do nothing :)', 'example');
|
||||
echo ' ' . Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']) .
|
||||
' ' . __('but do nothing :)', 'example');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::showMassiveActionsSubForm($ma);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since version 0.85
|
||||
*
|
||||
* @see CommonDBTM::processMassiveActionsForOneItemtype()
|
||||
**/
|
||||
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item,
|
||||
array $ids) {
|
||||
public static function processMassiveActionsForOneItemtype(
|
||||
MassiveAction $ma,
|
||||
CommonDBTM $item,
|
||||
array $ids
|
||||
) {
|
||||
global $DB;
|
||||
|
||||
switch ($ma->getAction()) {
|
||||
case 'DoIt':
|
||||
if ($item->getType() == 'Computer') {
|
||||
Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example'));
|
||||
Session::addMessageAfterRedirect(__('Right it is the type I want...', 'example'));
|
||||
Session::addMessageAfterRedirect(__('Write in item history', 'example'));
|
||||
$changes = [0, 'old value', 'new value'];
|
||||
foreach ($ids as $id) {
|
||||
if ($item->getFromDB($id)) {
|
||||
Session::addMessageAfterRedirect("- ".$item->getField("name"));
|
||||
Log::history($id, 'Computer', $changes, Example::class,
|
||||
Log::HISTORY_PLUGIN);
|
||||
Session::addMessageAfterRedirect('- ' . $item->getField('name'));
|
||||
Log::history(
|
||||
$id,
|
||||
'Computer',
|
||||
$changes,
|
||||
Example::class,
|
||||
Log::HISTORY_PLUGIN,
|
||||
);
|
||||
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
|
||||
} else {
|
||||
// Example of ko count
|
||||
@@ -439,16 +459,19 @@ class Example extends CommonDBTM {
|
||||
// When nothing is possible ...
|
||||
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
case 'do_nothing':
|
||||
If ($item->getType() == Example::class) {
|
||||
Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example'));
|
||||
Session::addMessageAfterRedirect(__("But... I say I will do nothing for:",
|
||||
'example'));
|
||||
if ($item->getType() == Example::class) {
|
||||
Session::addMessageAfterRedirect(__('Right it is the type I want...', 'example'));
|
||||
Session::addMessageAfterRedirect(__(
|
||||
'But... I say I will do nothing for:',
|
||||
'example',
|
||||
));
|
||||
foreach ($ids as $id) {
|
||||
if ($item->getFromDB($id)) {
|
||||
Session::addMessageAfterRedirect("- ".$item->getField("name"));
|
||||
Session::addMessageAfterRedirect('- ' . $item->getField('name'));
|
||||
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
|
||||
} else {
|
||||
// Example for noright / Maybe do it with can function is better
|
||||
@@ -458,64 +481,66 @@ class Example extends CommonDBTM {
|
||||
} else {
|
||||
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
|
||||
}
|
||||
Return;
|
||||
|
||||
return;
|
||||
}
|
||||
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
|
||||
}
|
||||
|
||||
static function generateLinkContents($link, CommonDBTM $item) {
|
||||
public static function generateLinkContents($link, CommonDBTM $item)
|
||||
{
|
||||
if (strstr($link, '[EXAMPLE_ID]')) {
|
||||
$link = str_replace('[EXAMPLE_ID]', $item->getID(), $link);
|
||||
|
||||
if (strstr($link, "[EXAMPLE_ID]")) {
|
||||
$link = str_replace("[EXAMPLE_ID]", $item->getID(), $link);
|
||||
return [$link];
|
||||
}
|
||||
|
||||
return parent::generateLinkContents($link, $item);
|
||||
}
|
||||
|
||||
|
||||
static function dashboardTypes() {
|
||||
public static function dashboardTypes()
|
||||
{
|
||||
return [
|
||||
'example' => [
|
||||
'label' => __("Plugin Example", 'example'),
|
||||
'function' => Example::class . "::cardWidget",
|
||||
'image' => "https://via.placeholder.com/100x86?text=example",
|
||||
'label' => __('Plugin Example', 'example'),
|
||||
'function' => Example::class . '::cardWidget',
|
||||
'image' => 'https://via.placeholder.com/100x86?text=example',
|
||||
],
|
||||
'example_static' => [
|
||||
'label' => __("Plugin Example (static)", 'example'),
|
||||
'function' => Example::class . "::cardWidgetWithoutProvider",
|
||||
'image' => "https://via.placeholder.com/100x86?text=example+static",
|
||||
'label' => __('Plugin Example (static)', 'example'),
|
||||
'function' => Example::class . '::cardWidgetWithoutProvider',
|
||||
'image' => 'https://via.placeholder.com/100x86?text=example+static',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
static function dashboardCards($cards = []) {
|
||||
public static function dashboardCards($cards = [])
|
||||
{
|
||||
if (is_null($cards)) {
|
||||
$cards = [];
|
||||
}
|
||||
$new_cards = [
|
||||
'plugin_example_card' => [
|
||||
'widgettype' => ["example"],
|
||||
'label' => __("Plugin Example card"),
|
||||
'provider' => Example::class . "::cardDataProvider",
|
||||
'widgettype' => ['example'],
|
||||
'label' => __('Plugin Example card'),
|
||||
'provider' => Example::class . '::cardDataProvider',
|
||||
],
|
||||
'plugin_example_card_without_provider' => [
|
||||
'widgettype' => ["example_static"],
|
||||
'label' => __("Plugin Example card without provider"),
|
||||
'widgettype' => ['example_static'],
|
||||
'label' => __('Plugin Example card without provider'),
|
||||
],
|
||||
'plugin_example_card_with_core_widget' => [
|
||||
'widgettype' => ["bigNumber"],
|
||||
'label' => __("Plugin Example card with core provider"),
|
||||
'provider' => Example::class . "::cardBigNumberProvider",
|
||||
'widgettype' => ['bigNumber'],
|
||||
'label' => __('Plugin Example card with core provider'),
|
||||
'provider' => Example::class . '::cardBigNumberProvider',
|
||||
],
|
||||
];
|
||||
|
||||
return array_merge($cards, $new_cards);
|
||||
}
|
||||
|
||||
|
||||
static function cardWidget(array $params = []) {
|
||||
public static function cardWidget(array $params = [])
|
||||
{
|
||||
$default = [
|
||||
'data' => [],
|
||||
'title' => '',
|
||||
@@ -527,22 +552,23 @@ class Example extends CommonDBTM {
|
||||
$p = array_merge($default, $params);
|
||||
|
||||
// you need to encapsulate your html in div.card to benefit core style
|
||||
$html = "<div class='card' style='background-color: {$p["color"]};'>";
|
||||
$html = "<div class='card' style='background-color: {$p['color']};'>";
|
||||
$html .= "<h2>{$p['title']}</h2>";
|
||||
$html.= "<ul>";
|
||||
$html .= '<ul>';
|
||||
foreach ($p['data'] as $line) {
|
||||
$html .= "<li>$line</li>";
|
||||
}
|
||||
$html.= "</ul>";
|
||||
$html.= "</div>";
|
||||
$html .= '</ul>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
static function cardDataProvider(array $params = []) {
|
||||
public static function cardDataProvider(array $params = [])
|
||||
{
|
||||
$default_params = [
|
||||
'label' => null,
|
||||
'icon' => "fas fa-smile-wink",
|
||||
'icon' => 'fas fa-smile-wink',
|
||||
];
|
||||
$params = array_merge($default_params, $params);
|
||||
|
||||
@@ -553,11 +579,12 @@ class Example extends CommonDBTM {
|
||||
'test1',
|
||||
'test2',
|
||||
'test3',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
static function cardWidgetWithoutProvider(array $params = []) {
|
||||
public static function cardWidgetWithoutProvider(array $params = [])
|
||||
{
|
||||
$default = [
|
||||
// this property is "pretty" mandatory,
|
||||
// as it contains the colors selected when adding widget on the grid send
|
||||
@@ -567,7 +594,7 @@ class Example extends CommonDBTM {
|
||||
$p = array_merge($default, $params);
|
||||
|
||||
// you need to encapsulate your html in div.card to benefit core style
|
||||
$html = "<div class='card' style='background-color: {$p["color"]};'>
|
||||
$html = "<div class='card' style='background-color: {$p['color']};'>
|
||||
static html (+optional javascript) as card is not matched with a data provider
|
||||
|
||||
<img src='https://www.linux.org/images/logo.png'>
|
||||
@@ -576,7 +603,8 @@ class Example extends CommonDBTM {
|
||||
return $html;
|
||||
}
|
||||
|
||||
static function cardBigNumberProvider(array $params = []) {
|
||||
public static function cardBigNumberProvider(array $params = [])
|
||||
{
|
||||
$default_params = [
|
||||
'label' => null,
|
||||
'icon' => null,
|
||||
@@ -585,9 +613,9 @@ class Example extends CommonDBTM {
|
||||
|
||||
return [
|
||||
'number' => rand(),
|
||||
'url' => "https://www.linux.org/",
|
||||
'label' => "plugin example - some text",
|
||||
'icon' => "fab fa-linux", // font awesome icon
|
||||
'url' => 'https://www.linux.org/',
|
||||
'label' => 'plugin example - some text',
|
||||
'icon' => 'fab fa-linux', // font awesome icon
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -38,12 +38,12 @@ class ComputerModelFilter extends AbstractFilter
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return __("Computer model");
|
||||
return __('Computer model');
|
||||
}
|
||||
|
||||
public static function getId(): string
|
||||
{
|
||||
return "plugin_example_computer_model";
|
||||
return 'plugin_example_computer_model';
|
||||
}
|
||||
|
||||
public static function canBeApplied(string $table): bool
|
||||
@@ -57,9 +57,9 @@ class ComputerModelFilter extends AbstractFilter
|
||||
{
|
||||
return self::displayList(
|
||||
self::getName(),
|
||||
is_string($value) ? $value : "",
|
||||
is_string($value) ? $value : '',
|
||||
self::getId(),
|
||||
ComputerModel::class
|
||||
ComputerModel::class,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,10 +67,11 @@ class ComputerModelFilter extends AbstractFilter
|
||||
{
|
||||
if ((int) $value > 0) {
|
||||
$field = ComputerModel::getForeignKeyField();
|
||||
|
||||
return [
|
||||
"WHERE" => [
|
||||
"$table.$field" => (int) $value
|
||||
]
|
||||
'WHERE' => [
|
||||
"$table.$field" => (int) $value,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -88,9 +89,9 @@ class ComputerModelFilter extends AbstractFilter
|
||||
'field' => self::getSearchOptionID(
|
||||
$table,
|
||||
ComputerModel::getForeignKeyField(),
|
||||
ComputerModel::getTable()
|
||||
ComputerModel::getTable(),
|
||||
),
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -39,9 +39,8 @@ use Ticket;
|
||||
* Example of *_item_form implementation
|
||||
* @see http://glpi-developer-documentation.rtfd.io/en/master/plugins/hooks.html#items-display-related
|
||||
* */
|
||||
class ItemForm {
|
||||
|
||||
|
||||
class ItemForm
|
||||
{
|
||||
/**
|
||||
* Display contents at the begining of ITILObject section (right panel).
|
||||
*
|
||||
@@ -49,7 +48,8 @@ class ItemForm {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function preSection($params) {
|
||||
public static function preSection($params)
|
||||
{
|
||||
$item = $params['item'];
|
||||
$options = $params['options'];
|
||||
|
||||
@@ -70,7 +70,6 @@ class ItemForm {
|
||||
</div>
|
||||
</section>
|
||||
TWIG, []);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +79,8 @@ TWIG, []);
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function postSection($params) {
|
||||
public static function postSection($params)
|
||||
{
|
||||
$item = $params['item'];
|
||||
$options = $params['options'];
|
||||
|
||||
@@ -103,10 +103,6 @@ TWIG, []);
|
||||
TWIG, []);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Display contents at the begining of item forms.
|
||||
*
|
||||
@@ -114,7 +110,8 @@ TWIG, []);
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function preItemForm($params) {
|
||||
public static function preItemForm($params)
|
||||
{
|
||||
$item = $params['item'];
|
||||
$options = $params['options'];
|
||||
|
||||
@@ -124,7 +121,7 @@ TWIG, []);
|
||||
$out .= sprintf(
|
||||
__('Start %1$s hook call for %2$s type'),
|
||||
'pre_item_form',
|
||||
$item::getType()
|
||||
$item::getType(),
|
||||
);
|
||||
$out .= '</th></tr>';
|
||||
|
||||
@@ -142,7 +139,7 @@ TWIG, []);
|
||||
$out .= sprintf(
|
||||
__('End %1$s hook call for %2$s type'),
|
||||
'pre_item_form',
|
||||
$item::getType()
|
||||
$item::getType(),
|
||||
);
|
||||
$out .= '</th></tr>';
|
||||
|
||||
@@ -156,7 +153,8 @@ TWIG, []);
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function postItemForm($params) {
|
||||
public static function postItemForm($params)
|
||||
{
|
||||
$item = $params['item'];
|
||||
$options = $params['options'];
|
||||
|
||||
@@ -166,7 +164,7 @@ TWIG, []);
|
||||
$out .= sprintf(
|
||||
__('Start %1$s hook call for %2$s type'),
|
||||
'post_item_form',
|
||||
$item::getType()
|
||||
$item::getType(),
|
||||
);
|
||||
$out .= '</th></tr>';
|
||||
|
||||
@@ -184,22 +182,23 @@ TWIG, []);
|
||||
$out .= sprintf(
|
||||
__('End %1$s hook call for %2$s type'),
|
||||
'post_item_form',
|
||||
$item::getType()
|
||||
$item::getType(),
|
||||
);
|
||||
$out .= '</th></tr>';
|
||||
|
||||
echo $out;
|
||||
}
|
||||
|
||||
static public function timelineActions($params = []) {
|
||||
public static function timelineActions($params = [])
|
||||
{
|
||||
$rand = $params['rand'];
|
||||
$ticket = $params['item'];
|
||||
|
||||
if (get_class($ticket) !== "Ticket") {
|
||||
if (get_class($ticket) !== 'Ticket') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$edit_panel = "viewitem".$ticket->fields['id'].$rand;
|
||||
$edit_panel = 'viewitem' . $ticket->fields['id'] . $rand;
|
||||
$JS = <<<JAVASCRIPT
|
||||
$(function() {
|
||||
$(document).on('click', '#email_transfer_{$rand}', function(event) {
|
||||
@@ -210,8 +209,8 @@ JAVASCRIPT;
|
||||
|
||||
echo "<li class='followup' id='email_transfer_$rand'>
|
||||
<i class='far fa-envelope'></i>" .
|
||||
__("Send a notification").
|
||||
Html::scriptBlock($JS)."
|
||||
</li>";
|
||||
__('Send a notification') .
|
||||
Html::scriptBlock($JS) . '
|
||||
</li>';
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@
|
||||
// Class of the defined type
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use GlpiPlugin\Example\DeviceCamera;
|
||||
use Item_Devices;
|
||||
|
||||
@@ -46,11 +47,10 @@ if (!defined('GLPI_ROOT')) {
|
||||
/**
|
||||
* Relation between item and devices
|
||||
**/
|
||||
class Item_DeviceCamera extends Item_Devices {
|
||||
|
||||
static public $itemtype_2 = DeviceCamera::class;
|
||||
static public $items_id_2 = 'plugin_example_devicecameras_id';
|
||||
|
||||
static protected $notable = false;
|
||||
class Item_DeviceCamera extends Item_Devices
|
||||
{
|
||||
public static $itemtype_2 = DeviceCamera::class;
|
||||
public static $items_id_2 = 'plugin_example_devicecameras_id';
|
||||
|
||||
protected static $notable = false;
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@
|
||||
*/
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use NotificationTarget;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
@@ -36,13 +37,15 @@ if (!defined('GLPI_ROOT')) {
|
||||
}
|
||||
|
||||
// Class NotificationTarget
|
||||
class NotificationTargetExample extends NotificationTarget {
|
||||
|
||||
function getEvents() {
|
||||
class NotificationTargetExample extends NotificationTarget
|
||||
{
|
||||
public function getEvents()
|
||||
{
|
||||
return ['alert' => 'alert example'];
|
||||
}
|
||||
|
||||
function addDataForTemplate($event, $options = []) {
|
||||
public function addDataForTemplate($event, $options = [])
|
||||
{
|
||||
global $DB, $CFG_GLPI;
|
||||
|
||||
$this->data['##example.name##'] = __('Example', 'example');
|
||||
|
@@ -67,8 +67,8 @@ final class Profile extends \Profile
|
||||
[
|
||||
'itemtype' => Example::class,
|
||||
'label' => Example::getTypeName(Session::getPluralNumber()),
|
||||
'field' => Example::$rightname
|
||||
]
|
||||
'field' => Example::$rightname,
|
||||
],
|
||||
];
|
||||
$matrix_options['title'] = self::getTypeName(1);
|
||||
$this->displayRightsChoiceMatrix($rights, $matrix_options);
|
||||
|
@@ -34,6 +34,7 @@
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use Rule;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
@@ -48,25 +49,24 @@ if (!defined('GLPI_ROOT')) {
|
||||
* - actions
|
||||
*
|
||||
**/
|
||||
class RuleTest extends Rule {
|
||||
|
||||
class RuleTest extends Rule
|
||||
{
|
||||
// From Rule
|
||||
public static $rightname = 'rule_import';
|
||||
public $can_sort = true;
|
||||
|
||||
|
||||
function getTitle() {
|
||||
public function getTitle()
|
||||
{
|
||||
return 'test';
|
||||
}
|
||||
|
||||
|
||||
function maxActionsCount() {
|
||||
public function maxActionsCount()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
function getCriterias() {
|
||||
|
||||
public function getCriterias()
|
||||
{
|
||||
$criterias = [];
|
||||
$criterias['name']['field'] = 'name';
|
||||
$criterias['name']['name'] = __('Software');
|
||||
@@ -75,13 +75,13 @@ class RuleTest extends Rule {
|
||||
return $criterias;
|
||||
}
|
||||
|
||||
|
||||
function getActions() {
|
||||
|
||||
public function getActions()
|
||||
{
|
||||
$actions = [];
|
||||
$actions['softwarecategories_id']['name'] = __('Category (class)', 'example');
|
||||
$actions['softwarecategories_id']['type'] = 'dropdown';
|
||||
$actions['softwarecategories_id']['table'] = 'glpi_softwarecategories';
|
||||
|
||||
return $actions;
|
||||
}
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use RuleCollection;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
@@ -41,14 +42,15 @@ if (!defined('GLPI_ROOT')) {
|
||||
}
|
||||
|
||||
|
||||
class RuleTestCollection extends RuleCollection {
|
||||
|
||||
class RuleTestCollection extends RuleCollection
|
||||
{
|
||||
// From RuleCollection
|
||||
public $stop_on_first_match = true;
|
||||
public static $rightname = 'rule_import';
|
||||
public $menu_option = 'test';
|
||||
|
||||
function getTitle() {
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Rulesengine test';
|
||||
}
|
||||
}
|
||||
|
@@ -51,8 +51,8 @@ namespace GlpiPlugin\Example;
|
||||
* post_show_tab will be fired after the tab show
|
||||
*
|
||||
* */
|
||||
class Showtabitem {
|
||||
|
||||
class Showtabitem
|
||||
{
|
||||
/**
|
||||
* Summary of pre_show_tab
|
||||
* @param array $params is an array like following
|
||||
@@ -64,7 +64,8 @@ class Showtabitem {
|
||||
* and 'itemtype' is the type of the tab (ex: 'ITILFollowup' when showing followup tab in a ticket)
|
||||
* Note: you may pass datas to post_show_tab using the $param['options'] array (see example below)
|
||||
*/
|
||||
static function pre_show_tab($params) {
|
||||
public static function pre_show_tab($params)
|
||||
{
|
||||
switch ($params['item']->getType()) {
|
||||
case 'Ticket':
|
||||
if ($params['options']['itemtype'] == 'TicketValidation' && $params['options']['tabnum'] == 2) {
|
||||
@@ -84,11 +85,12 @@ class Showtabitem {
|
||||
* @param array $params is identical to pre_show_tab parameter
|
||||
* Note: you may get datas from pre_show_tab in $param['options'] array (see example below)
|
||||
*/
|
||||
static function post_show_tab($params) {
|
||||
public static function post_show_tab($params)
|
||||
{
|
||||
switch ($params['item']->getType()) {
|
||||
case 'Ticket':
|
||||
if (isset($params['options']['prevent_solution'])) {
|
||||
echo "</div>";
|
||||
echo '</div>';
|
||||
echo "<div style='margin-bottom: 20px;' class='box'>
|
||||
<div class='box-tleft'>
|
||||
<div class='box-tright'>
|
||||
@@ -100,12 +102,12 @@ class Showtabitem {
|
||||
<div class='box-mright'>
|
||||
<div class='box-mcenter'>
|
||||
<h3>
|
||||
<span class='red'>"."Can't solve ticket"."
|
||||
<span class='red'>" . "Can't solve ticket" . '
|
||||
<br>
|
||||
</span>
|
||||
</h3>
|
||||
<h3>
|
||||
<span >"."Tasks are waiting to be done"."
|
||||
<span >' . 'Tasks are waiting to be done' . "
|
||||
</span>
|
||||
</h3>
|
||||
</div>
|
||||
@@ -143,7 +145,8 @@ class Showtabitem {
|
||||
* and 'showprivate' is the right to show private items
|
||||
* Note: you may pass datas to post_show_item using the $param['options'] array
|
||||
*/
|
||||
static function pre_show_item($params) {
|
||||
public static function pre_show_item($params)
|
||||
{
|
||||
if (!is_array($params['item'])) {
|
||||
switch ($params['item']->getType()) {
|
||||
case 'Ticket':
|
||||
@@ -178,7 +181,8 @@ class Showtabitem {
|
||||
* and 'showprivate' is the right to show private items
|
||||
* Note: you may get datas from pre_show_item using the $param['options'] array
|
||||
*/
|
||||
static function post_show_item($params) {
|
||||
public static function post_show_item($params)
|
||||
{
|
||||
if (!is_array($params['item'])) {
|
||||
switch ($params['item']->getType()) {
|
||||
case 'Ticket':
|
||||
@@ -196,5 +200,4 @@ class Showtabitem {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
6
stat.php
6
stat.php
@@ -38,12 +38,12 @@
|
||||
|
||||
// Entry menu case
|
||||
define('GLPI_ROOT', '../..');
|
||||
include (GLPI_ROOT . "/inc/includes.php");
|
||||
include(GLPI_ROOT . '/inc/includes.php');
|
||||
|
||||
Session::checkRight(Config::$rightname, UPDATE);
|
||||
|
||||
Html::header("TITLE", $_SERVER['PHP_SELF'], "plugins");
|
||||
Html::header('TITLE', $_SERVER['PHP_SELF'], 'plugins');
|
||||
|
||||
echo "This is the plugin stat page";
|
||||
echo 'This is the plugin stat page';
|
||||
|
||||
Html::footer();
|
||||
|
Reference in New Issue
Block a user