mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-06-28 06:58:43 +02:00
Feature GLP11
This commit is contained in:
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);
|
@ -1,15 +1,26 @@
|
|||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.4"
|
"php": ">=8.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"glpi-project/tools": "^0.5"
|
"friendsofphp/php-cs-fixer": "^3.75",
|
||||||
|
"friendsoftwig/twigcs": "^6.1",
|
||||||
|
"glpi-project/tools": "^0.7.5",
|
||||||
|
"php-parallel-lint/php-parallel-lint": "^1.4"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"optimize-autoloader": true,
|
"optimize-autoloader": true,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": "7.4.0"
|
"php": "8.2.99"
|
||||||
},
|
},
|
||||||
"sort-packages": true
|
"sort-packages": true,
|
||||||
|
"allow-plugins": {
|
||||||
|
"phpstan/extension-installer": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Glpi\\Tools\\": "../../tools/src/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2298
composer.lock
generated
2298
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -37,7 +37,7 @@
|
|||||||
//header("Location:../../central.php");
|
//header("Location:../../central.php");
|
||||||
|
|
||||||
// Entry menu case
|
// Entry menu case
|
||||||
include ("../../../inc/includes.php");
|
include("../../../inc/includes.php");
|
||||||
|
|
||||||
Session::checkRight("config", UPDATE);
|
Session::checkRight("config", UPDATE);
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@
|
|||||||
|
|
||||||
use GlpiPlugin\Example\DeviceCamera;
|
use GlpiPlugin\Example\DeviceCamera;
|
||||||
|
|
||||||
include ('../../../inc/includes.php');
|
include('../../../inc/includes.php');
|
||||||
Session::checkLoginUser();
|
Session::checkLoginUser();
|
||||||
|
|
||||||
$dropdown = new DeviceCamera();
|
$dropdown = new DeviceCamera();
|
||||||
include (GLPI_ROOT . "/front/dropdown.common.form.php");
|
include(GLPI_ROOT . "/front/dropdown.common.form.php");
|
||||||
|
@ -33,8 +33,8 @@
|
|||||||
// Purpose of file:
|
// Purpose of file:
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
include ('../../../inc/includes.php');
|
include('../../../inc/includes.php');
|
||||||
Session::checkLoginUser();
|
Session::checkLoginUser();
|
||||||
|
|
||||||
$dropdown = new DeviceCamera();
|
$dropdown = new DeviceCamera();
|
||||||
include (GLPI_ROOT . "/front/dropdown.common.php");
|
include(GLPI_ROOT . "/front/dropdown.common.php");
|
||||||
|
@ -35,10 +35,10 @@
|
|||||||
|
|
||||||
use GlpiPlugin\Example\Dropdown;
|
use GlpiPlugin\Example\Dropdown;
|
||||||
|
|
||||||
include ('../../../inc/includes.php');
|
include('../../../inc/includes.php');
|
||||||
Session::checkLoginUser();
|
Session::checkLoginUser();
|
||||||
|
|
||||||
Plugin::load('example', true);
|
Plugin::load('example', true);
|
||||||
|
|
||||||
$dropdown = new Dropdown();
|
$dropdown = new Dropdown();
|
||||||
include (GLPI_ROOT . "/front/dropdown.common.form.php");
|
include(GLPI_ROOT . "/front/dropdown.common.form.php");
|
||||||
|
@ -35,10 +35,10 @@
|
|||||||
|
|
||||||
use GlpiPlugin\Example\Dropdown;
|
use GlpiPlugin\Example\Dropdown;
|
||||||
|
|
||||||
include ('../../../inc/includes.php');
|
include('../../../inc/includes.php');
|
||||||
Session::checkLoginUser();
|
Session::checkLoginUser();
|
||||||
|
|
||||||
Plugin::load('example', true);
|
Plugin::load('example', true);
|
||||||
|
|
||||||
$dropdown = new Dropdown();
|
$dropdown = new Dropdown();
|
||||||
include (GLPI_ROOT . "/front/dropdown.common.php");
|
include(GLPI_ROOT . "/front/dropdown.common.php");
|
||||||
|
@ -35,13 +35,13 @@
|
|||||||
|
|
||||||
use GlpiPlugin\Example\Example;
|
use GlpiPlugin\Example\Example;
|
||||||
|
|
||||||
include ('../../../inc/includes.php');
|
include('../../../inc/includes.php');
|
||||||
Session::checkLoginUser();
|
Session::checkLoginUser();
|
||||||
|
|
||||||
if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
|
if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
|
||||||
Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", Example::class, "");
|
Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", Example::class, "");
|
||||||
} else {
|
} else {
|
||||||
Html::helpHeader("TITRE", $_SERVER['PHP_SELF']);
|
Html::helpHeader("TITRE", $_SERVER['PHP_SELF']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$example = new Example();
|
$example = new Example();
|
||||||
|
@ -35,13 +35,13 @@
|
|||||||
|
|
||||||
use GlpiPlugin\Example\Example;
|
use GlpiPlugin\Example\Example;
|
||||||
|
|
||||||
include ('../../../inc/includes.php');
|
include('../../../inc/includes.php');
|
||||||
Session::checkRight(Example::$rightname, READ);
|
Session::checkRight(Example::$rightname, READ);
|
||||||
|
|
||||||
if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
|
if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
|
||||||
Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", Example::class, "");
|
Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", Example::class, "");
|
||||||
} else {
|
} else {
|
||||||
Html::helpHeader("TITRE", $_SERVER['PHP_SELF']);
|
Html::helpHeader("TITRE", $_SERVER['PHP_SELF']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,32 +28,32 @@
|
|||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include ('../../../inc/includes.php');
|
include('../../../inc/includes.php');
|
||||||
|
|
||||||
Session::checkLoginUser();
|
Session::checkLoginUser();
|
||||||
|
|
||||||
if (isset($_GET["popup"])) {
|
if (isset($_GET["popup"])) {
|
||||||
$_SESSION["glpipopup"]["name"] = $_GET["popup"];
|
$_SESSION["glpipopup"]["name"] = $_GET["popup"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_SESSION["glpipopup"]["name"])) {
|
if (isset($_SESSION["glpipopup"]["name"])) {
|
||||||
switch ($_SESSION["glpipopup"]["name"]) {
|
switch ($_SESSION["glpipopup"]["name"]) {
|
||||||
case "test_rule" :
|
case "test_rule":
|
||||||
Html::popHeader(__('Test'), $_SERVER['PHP_SELF']);
|
Html::popHeader(__('Test'), $_SERVER['PHP_SELF']);
|
||||||
include "../../../front/rule.test.php";
|
include "../../../front/rule.test.php";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "test_all_rules" :
|
case "test_all_rules":
|
||||||
Html::popHeader(__('Test rules engine'), $_SERVER['PHP_SELF']);
|
Html::popHeader(__('Test rules engine'), $_SERVER['PHP_SELF']);
|
||||||
include "../../../front/rulesengine.test.php";
|
include "../../../front/rulesengine.test.php";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "show_cache" :
|
case "show_cache":
|
||||||
Html::popHeader(__('Cache information'), $_SERVER['PHP_SELF']);
|
Html::popHeader(__('Cache information'), $_SERVER['PHP_SELF']);
|
||||||
include "../../../front/rule.cache.php";
|
include "../../../front/rule.cache.php";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
echo "<div class='center'><br><a href='javascript:window.close()'>".__('Back')."</a>";
|
echo "<div class='center'><br><a href='javascript:window.close()'>" . __('Back') . "</a>";
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
Html::popFooter();
|
Html::popFooter();
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,9 @@
|
|||||||
|
|
||||||
use GlpiPlugin\Example\RuleTestCollection;
|
use GlpiPlugin\Example\RuleTestCollection;
|
||||||
|
|
||||||
include ('../../../inc/includes.php');
|
include('../../../inc/includes.php');
|
||||||
Session::checkLoginUser();
|
Session::checkLoginUser();
|
||||||
|
|
||||||
$rulecollection = new RuleTestCollection();
|
$rulecollection = new RuleTestCollection();
|
||||||
|
|
||||||
include (GLPI_ROOT . "/front/rule.common.form.php");
|
include(GLPI_ROOT . "/front/rule.common.form.php");
|
||||||
|
@ -35,9 +35,9 @@
|
|||||||
|
|
||||||
use GlpiPlugin\Example\RuleTestCollection;
|
use GlpiPlugin\Example\RuleTestCollection;
|
||||||
|
|
||||||
include ('../../../inc/includes.php');
|
include('../../../inc/includes.php');
|
||||||
Session::checkLoginUser();
|
Session::checkLoginUser();
|
||||||
|
|
||||||
$rulecollection = new RuleTestCollection();
|
$rulecollection = new RuleTestCollection();
|
||||||
|
|
||||||
include (GLPI_ROOT . "/front/rule.common.php");
|
include(GLPI_ROOT . "/front/rule.common.php");
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
// Entry menu case
|
// Entry menu case
|
||||||
define('GLPI_ROOT', '../..');
|
define('GLPI_ROOT', '../..');
|
||||||
include (GLPI_ROOT . "/inc/includes.php");
|
include(GLPI_ROOT . "/inc/includes.php");
|
||||||
|
|
||||||
Session::checkRight(Config::$rightname, UPDATE);
|
Session::checkRight(Config::$rightname, UPDATE);
|
||||||
|
|
||||||
|
452
setup.php
452
setup.php
@ -42,9 +42,9 @@ use GlpiPlugin\Example\Showtabitem;
|
|||||||
define('PLUGIN_EXAMPLE_VERSION', '0.0.1');
|
define('PLUGIN_EXAMPLE_VERSION', '0.0.1');
|
||||||
|
|
||||||
// Minimal GLPI version, inclusive
|
// Minimal GLPI version, inclusive
|
||||||
define('PLUGIN_EXAMPLE_MIN_GLPI', '10.0.0');
|
define('PLUGIN_EXAMPLE_MIN_GLPI', '11.0.0');
|
||||||
// Maximum GLPI version, exclusive
|
// Maximum GLPI version, exclusive
|
||||||
define('PLUGIN_EXAMPLE_MAX_GLPI', '10.0.99');
|
define('PLUGIN_EXAMPLE_MAX_GLPI', '11.0.99');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init hooks of the plugin.
|
* Init hooks of the plugin.
|
||||||
@ -52,249 +52,250 @@ define('PLUGIN_EXAMPLE_MAX_GLPI', '10.0.99');
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function plugin_init_example() {
|
function plugin_init_example()
|
||||||
global $PLUGIN_HOOKS,$CFG_GLPI;
|
{
|
||||||
|
|
||||||
// Params : plugin name - string type - ID - Array of attributes
|
/** @var array $CFG_GLPI */
|
||||||
// No specific information passed so not needed
|
/** @var array $PLUGIN_HOOKS */
|
||||||
//Plugin::registerClass(Example::getType(),
|
global $CFG_GLPI, $PLUGIN_HOOKS;
|
||||||
// array('classname' => Example::class,
|
|
||||||
// ));
|
|
||||||
|
|
||||||
Plugin::registerClass(Config::class, ['addtabon' => 'Config']);
|
// Params : plugin name - string type - ID - Array of attributes
|
||||||
|
// No specific information passed so not needed
|
||||||
|
//Plugin::registerClass(Example::getType(),
|
||||||
|
// array('classname' => Example::class,
|
||||||
|
// ));
|
||||||
|
|
||||||
// Params : plugin name - string type - ID - Array of attributes
|
require_once(__DIR__ . '/vendor/autoload.php');
|
||||||
Plugin::registerClass(Dropdown::class);
|
|
||||||
|
|
||||||
$types = ['Central', 'Computer', 'ComputerDisk', 'Notification', 'Phone',
|
Plugin::registerClass(Config::class, ['addtabon' => 'Config']);
|
||||||
'Preference', 'Profile', 'Supplier'];
|
|
||||||
Plugin::registerClass(Example::class,
|
|
||||||
['notificationtemplates_types' => true,
|
|
||||||
'addtabon' => $types,
|
|
||||||
'link_types' => true]);
|
|
||||||
|
|
||||||
Plugin::registerClass(RuleTestCollection::class,
|
// Params : plugin name - string type - ID - Array of attributes
|
||||||
['rulecollections_types' => true]);
|
Plugin::registerClass(Dropdown::class);
|
||||||
|
|
||||||
Plugin::registerClass(DeviceCamera::class,
|
$types = ['Central', 'Computer', 'ComputerDisk', 'Notification', 'Phone',
|
||||||
['device_types' => true]);
|
'Preference', 'Profile', 'Supplier'];
|
||||||
|
Plugin::registerClass(
|
||||||
|
Example::class,
|
||||||
|
['notificationtemplates_types' => true,
|
||||||
|
'addtabon' => $types,
|
||||||
|
'link_types' => true],
|
||||||
|
);
|
||||||
|
|
||||||
if (version_compare(GLPI_VERSION, '9.1', 'ge')) {
|
Plugin::registerClass(
|
||||||
if (class_exists(Example::class)) {
|
RuleTestCollection::class,
|
||||||
Link::registerTag(Example::$tags);
|
['rulecollections_types' => true],
|
||||||
}
|
);
|
||||||
}
|
|
||||||
// Display a menu entry ?
|
|
||||||
Plugin::registerClass(\GlpiPlugin\Example\Profile::class, ['addtabon' => ['Profile']]);
|
|
||||||
if (Example::canView()) { // Right set in change_profile hook
|
|
||||||
$PLUGIN_HOOKS['menu_toadd']['example'] = ['plugins' => Example::class,
|
|
||||||
'tools' => Example::class];
|
|
||||||
|
|
||||||
// Old menu style
|
Plugin::registerClass(
|
||||||
// $PLUGIN_HOOKS['menu_entry']['example'] = 'front/example.php';
|
DeviceCamera::class,
|
||||||
//
|
['device_types' => true],
|
||||||
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['title'] = "Search";
|
);
|
||||||
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['page'] = '/plugins/example/front/example.php';
|
|
||||||
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['search'] = '/plugins/example/front/example.php';
|
|
||||||
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['add'] = '/plugins/example/front/example.form.php';
|
|
||||||
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['config'] = '/plugins/example/index.php';
|
|
||||||
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']["<img src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".__s('Show all')."' alt='".__s('Show all')."'>"] = '/plugins/example/index.php';
|
|
||||||
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links'][__s('Test link', 'example')] = '/plugins/example/index.php';
|
|
||||||
|
|
||||||
$PLUGIN_HOOKS[Hooks::HELPDESK_MENU_ENTRY]['example'] = true;
|
if (class_exists(Example::class)) {
|
||||||
$PLUGIN_HOOKS[Hooks::HELPDESK_MENU_ENTRY_ICON]['example'] = 'fas fa-puzzle-piece';
|
Link::registerTag(Example::$tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config page
|
// Display a menu entry ?
|
||||||
if (Session::haveRight('config', UPDATE)) {
|
Plugin::registerClass(\GlpiPlugin\Example\Profile::class, ['addtabon' => ['Profile']]);
|
||||||
$PLUGIN_HOOKS['config_page']['example'] = 'front/config.php';
|
if (Example::canView()) { // Right set in change_profile hook
|
||||||
}
|
$PLUGIN_HOOKS['menu_toadd']['example'] = ['plugins' => Example::class,
|
||||||
|
'tools' => Example::class];
|
||||||
|
|
||||||
// Init session
|
// Old menu style
|
||||||
//$PLUGIN_HOOKS['init_session']['example'] = 'plugin_init_session_example';
|
// $PLUGIN_HOOKS['menu_entry']['example'] = 'front/example.php';
|
||||||
// Change profile
|
//
|
||||||
$PLUGIN_HOOKS['change_profile']['example'] = 'plugin_change_profile_example';
|
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['title'] = "Search";
|
||||||
// Change entity
|
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['page'] = '/plugins/example/front/example.php';
|
||||||
//$PLUGIN_HOOKS['change_entity']['example'] = 'plugin_change_entity_example';
|
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['search'] = '/plugins/example/front/example.php';
|
||||||
|
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['add'] = '/plugins/example/front/example.form.php';
|
||||||
|
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['config'] = '/plugins/example/index.php';
|
||||||
|
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']["<img src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".__s('Show all')."' alt='".__s('Show all')."'>"] = '/plugins/example/index.php';
|
||||||
|
// $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links'][__s('Test link', 'example')] = '/plugins/example/index.php';
|
||||||
|
|
||||||
// Item action event // See define.php for defined ITEM_TYPE
|
$PLUGIN_HOOKS[Hooks::HELPDESK_MENU_ENTRY]['example'] = true;
|
||||||
$PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['example'] = [Computer::class => 'plugin_pre_item_update_example'];
|
$PLUGIN_HOOKS[Hooks::HELPDESK_MENU_ENTRY_ICON]['example'] = 'fas fa-puzzle-piece';
|
||||||
$PLUGIN_HOOKS[hooks::ITEM_UPDATE]['example'] = [Computer::class => 'plugin_item_update_example'];
|
}
|
||||||
|
|
||||||
$PLUGIN_HOOKS[Hooks::ITEM_EMPTY]['example'] = [Computer::class => 'plugin_item_empty_example'];
|
// Config page
|
||||||
|
if (Session::haveRight('config', UPDATE)) {
|
||||||
|
$PLUGIN_HOOKS['config_page']['example'] = 'front/config.php';
|
||||||
|
}
|
||||||
|
|
||||||
// Restrict right
|
// Init session
|
||||||
$PLUGIN_HOOKS[Hooks::ITEM_CAN]['example'] = [Computer::class => [Example::class, 'item_can']];
|
//$PLUGIN_HOOKS['init_session']['example'] = 'plugin_init_session_example';
|
||||||
$PLUGIN_HOOKS['add_default_where']['example'] = [Computer::class => [Example::class, 'add_default_where']];
|
// Change profile
|
||||||
|
$PLUGIN_HOOKS['change_profile']['example'] = 'plugin_change_profile_example';
|
||||||
|
// Change entity
|
||||||
|
//$PLUGIN_HOOKS['change_entity']['example'] = 'plugin_change_entity_example';
|
||||||
|
|
||||||
// Example using a method in class
|
// Item action event // See define.php for defined ITEM_TYPE
|
||||||
$PLUGIN_HOOKS[Hooks::PRE_ITEM_ADD]['example'] = [Computer::class => [Example::class,
|
$PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['example'] = [Computer::class => 'plugin_pre_item_update_example'];
|
||||||
'pre_item_add_computer']];
|
$PLUGIN_HOOKS[hooks::ITEM_UPDATE]['example'] = [Computer::class => 'plugin_item_update_example'];
|
||||||
$PLUGIN_HOOKS[Hooks::POST_PREPAREADD]['example'] = [Computer::class => [Example::class,
|
|
||||||
'post_prepareadd_computer']];
|
|
||||||
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['example'] = [Computer::class => [Example::class,
|
|
||||||
'item_add_computer']];
|
|
||||||
|
|
||||||
$PLUGIN_HOOKS[Hooks::PRE_ITEM_DELETE]['example'] = [Computer::class => 'plugin_pre_item_delete_example'];
|
$PLUGIN_HOOKS[Hooks::ITEM_EMPTY]['example'] = [Computer::class => 'plugin_item_empty_example'];
|
||||||
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['example'] = [Computer::class => 'plugin_item_delete_example'];
|
|
||||||
|
|
||||||
// Example using the same function
|
// Restrict right
|
||||||
$PLUGIN_HOOKS[Hooks::PRE_ITEM_PURGE]['example'] = [Computer::class => 'plugin_pre_item_purge_example',
|
$PLUGIN_HOOKS[Hooks::ITEM_CAN]['example'] = [Computer::class => [Example::class, 'item_can']];
|
||||||
'Phone' => 'plugin_pre_item_purge_example'];
|
$PLUGIN_HOOKS['add_default_where']['example'] = [Computer::class => [Example::class, 'add_default_where']];
|
||||||
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['example'] = [Computer::class => 'plugin_item_purge_example',
|
|
||||||
'Phone' => 'plugin_item_purge_example'];
|
|
||||||
|
|
||||||
// Example with 2 different functions
|
// Example using a method in class
|
||||||
$PLUGIN_HOOKS[Hooks::PRE_ITEM_RESTORE]['example'] = [Computer::class => 'plugin_pre_item_restore_example',
|
$PLUGIN_HOOKS[Hooks::PRE_ITEM_ADD]['example'] = [Computer::class => [Example::class,
|
||||||
'Phone' => 'plugin_pre_item_restore_example2'];
|
'pre_item_add_computer']];
|
||||||
$PLUGIN_HOOKS[Hooks::ITEM_RESTORE]['example'] = [Computer::class => 'plugin_item_restore_example'];
|
$PLUGIN_HOOKS[Hooks::POST_PREPAREADD]['example'] = [Computer::class => [Example::class,
|
||||||
|
'post_prepareadd_computer']];
|
||||||
|
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['example'] = [Computer::class => [Example::class,
|
||||||
|
'item_add_computer']];
|
||||||
|
|
||||||
// Add event to GLPI core itemtype, event will be raised by the plugin.
|
$PLUGIN_HOOKS[Hooks::PRE_ITEM_DELETE]['example'] = [Computer::class => 'plugin_pre_item_delete_example'];
|
||||||
// See plugin_example_uninstall for cleanup of notification
|
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['example'] = [Computer::class => 'plugin_item_delete_example'];
|
||||||
$PLUGIN_HOOKS[Hooks::ITEM_GET_EVENTS]['example']
|
|
||||||
= ['NotificationTargetTicket' => 'plugin_example_get_events'];
|
|
||||||
|
|
||||||
// Add datas to GLPI core itemtype for notifications template.
|
// Example using the same function
|
||||||
$PLUGIN_HOOKS[Hooks::ITEM_GET_DATA]['example']
|
$PLUGIN_HOOKS[Hooks::PRE_ITEM_PURGE]['example'] = [Computer::class => 'plugin_pre_item_purge_example',
|
||||||
= ['NotificationTargetTicket' => 'plugin_example_get_datas'];
|
'Phone' => 'plugin_pre_item_purge_example'];
|
||||||
|
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['example'] = [Computer::class => 'plugin_item_purge_example',
|
||||||
|
'Phone' => 'plugin_item_purge_example'];
|
||||||
|
|
||||||
$PLUGIN_HOOKS[Hooks::ITEM_TRANSFER]['example'] = 'plugin_item_transfer_example';
|
// Example with 2 different functions
|
||||||
|
$PLUGIN_HOOKS[Hooks::PRE_ITEM_RESTORE]['example'] = [Computer::class => 'plugin_pre_item_restore_example',
|
||||||
|
'Phone' => 'plugin_pre_item_restore_example2'];
|
||||||
|
$PLUGIN_HOOKS[Hooks::ITEM_RESTORE]['example'] = [Computer::class => 'plugin_item_restore_example'];
|
||||||
|
|
||||||
// function to populate planning
|
// Add event to GLPI core itemtype, event will be raised by the plugin.
|
||||||
// No more used since GLPI 0.84
|
// See plugin_example_uninstall for cleanup of notification
|
||||||
// $PLUGIN_HOOKS['planning_populate']['example'] = 'plugin_planning_populate_example';
|
$PLUGIN_HOOKS[Hooks::ITEM_GET_EVENTS]['example']
|
||||||
// Use instead : add class to planning types and define populatePlanning in class
|
= ['NotificationTargetTicket' => 'plugin_example_get_events'];
|
||||||
$CFG_GLPI['planning_types'][] = Example::class;
|
|
||||||
|
|
||||||
//function to display planning items
|
// Add datas to GLPI core itemtype for notifications template.
|
||||||
// No more used sinc GLPi 0.84
|
$PLUGIN_HOOKS[Hooks::ITEM_GET_DATA]['example']
|
||||||
// $PLUGIN_HOOKS['display_planning']['example'] = 'plugin_display_planning_example';
|
= ['NotificationTargetTicket' => 'plugin_example_get_datas'];
|
||||||
// Use instead : displayPlanningItem of the specific itemtype
|
|
||||||
|
|
||||||
// Massive Action definition
|
$PLUGIN_HOOKS[Hooks::ITEM_TRANSFER]['example'] = 'plugin_item_transfer_example';
|
||||||
$PLUGIN_HOOKS['use_massive_action']['example'] = 1;
|
|
||||||
|
|
||||||
$PLUGIN_HOOKS['assign_to_ticket']['example'] = 1;
|
// function to populate planning
|
||||||
|
// No more used since GLPI 0.84
|
||||||
|
// $PLUGIN_HOOKS['planning_populate']['example'] = 'plugin_planning_populate_example';
|
||||||
|
// Use instead : add class to planning types and define populatePlanning in class
|
||||||
|
$CFG_GLPI['planning_types'][] = Example::class;
|
||||||
|
|
||||||
// Add specific files to add to the header : javascript or css
|
//function to display planning items
|
||||||
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['example'] = 'example.js';
|
// No more used sinc GLPi 0.84
|
||||||
$PLUGIN_HOOKS[Hooks::ADD_CSS]['example'] = 'example.css';
|
// $PLUGIN_HOOKS['display_planning']['example'] = 'plugin_display_planning_example';
|
||||||
|
// Use instead : displayPlanningItem of the specific itemtype
|
||||||
|
|
||||||
// Add specific tags to the header
|
// Massive Action definition
|
||||||
$PLUGIN_HOOKS[Hooks::ADD_HEADER_TAG]['example'] = [
|
$PLUGIN_HOOKS['use_massive_action']['example'] = 1;
|
||||||
[
|
|
||||||
'tag' => 'meta',
|
|
||||||
'properties' => [
|
|
||||||
'name' => 'robots',
|
|
||||||
'content' => 'noindex, nofollow',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'tag' => 'link',
|
|
||||||
'properties' => [
|
|
||||||
'rel' => 'alternate',
|
|
||||||
'type' => 'application/rss+xml',
|
|
||||||
'title' => 'The company RSS feed',
|
|
||||||
'href' => 'https://example.org/feed.xml',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
// Add specific files to add to the header into anonymous page : javascript or css
|
$PLUGIN_HOOKS['assign_to_ticket']['example'] = 1;
|
||||||
$PLUGIN_HOOKS[Hooks::ADD_CSS_ANONYMOUS_PAGE]['example'] = 'example_anonymous.css';
|
|
||||||
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT_MODULE_ANONYMOUS_PAGE]['example'] = 'mymodule_anonymous.js';
|
|
||||||
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT_ANONYMOUS_PAGE]['example'] = 'example_anonymous.js';
|
|
||||||
|
|
||||||
// Add specific tags to the header into anonymous page
|
// Add specific files to add to the header : javascript or css
|
||||||
$PLUGIN_HOOKS[Hooks::ADD_HEADER_TAG_ANONYMOUS_PAGE]['example'] = [
|
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['example'] = 'example.js';
|
||||||
[
|
$PLUGIN_HOOKS[Hooks::ADD_CSS]['example'] = 'example.css';
|
||||||
'tag' => 'meta',
|
|
||||||
'properties' => [
|
|
||||||
'name' => 'robots',
|
|
||||||
'content' => 'noindex, nofollow',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'tag' => 'link',
|
|
||||||
'properties' => [
|
|
||||||
'rel' => 'alternate',
|
|
||||||
'type' => 'application/rss+xml',
|
|
||||||
'title' => 'The company RSS feed',
|
|
||||||
'href' => 'https://example.org/feed.xml',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
// request more attributes from ldap
|
// Add specific tags to the header
|
||||||
//$PLUGIN_HOOKS['retrieve_more_field_from_ldap']['example']="plugin_retrieve_more_field_from_ldap_example";
|
$PLUGIN_HOOKS[Hooks::ADD_HEADER_TAG]['example'] = [
|
||||||
|
[
|
||||||
|
'tag' => 'meta',
|
||||||
|
'properties' => [
|
||||||
|
'name' => 'robots',
|
||||||
|
'content' => 'noindex, nofollow',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'tag' => 'link',
|
||||||
|
'properties' => [
|
||||||
|
'rel' => 'alternate',
|
||||||
|
'type' => 'application/rss+xml',
|
||||||
|
'title' => 'The company RSS feed',
|
||||||
|
'href' => 'https://example.org/feed.xml',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
// Retrieve others datas from LDAP
|
// Add specific files to add to the header into anonymous page : javascript or css
|
||||||
//$PLUGIN_HOOKS['retrieve_more_data_from_ldap']['example']="plugin_retrieve_more_data_from_ldap_example";
|
$PLUGIN_HOOKS[Hooks::ADD_CSS_ANONYMOUS_PAGE]['example'] = 'example_anonymous.css';
|
||||||
|
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT_MODULE_ANONYMOUS_PAGE]['example'] = 'mymodule_anonymous.js';
|
||||||
|
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT_ANONYMOUS_PAGE]['example'] = 'example_anonymous.js';
|
||||||
|
|
||||||
// Reports
|
// Add specific tags to the header into anonymous page
|
||||||
$PLUGIN_HOOKS['reports']['example'] = ['report.php' => 'New Report',
|
$PLUGIN_HOOKS[Hooks::ADD_HEADER_TAG_ANONYMOUS_PAGE]['example'] = [
|
||||||
'report.php?other' => 'New Report 2'];
|
[
|
||||||
|
'tag' => 'meta',
|
||||||
|
'properties' => [
|
||||||
|
'name' => 'robots',
|
||||||
|
'content' => 'noindex, nofollow',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'tag' => 'link',
|
||||||
|
'properties' => [
|
||||||
|
'rel' => 'alternate',
|
||||||
|
'type' => 'application/rss+xml',
|
||||||
|
'title' => 'The company RSS feed',
|
||||||
|
'href' => 'https://example.org/feed.xml',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
// Stats
|
// request more attributes from ldap
|
||||||
$PLUGIN_HOOKS['stats']['example'] = ['stat.php' => 'New stat',
|
//$PLUGIN_HOOKS['retrieve_more_field_from_ldap']['example']="plugin_retrieve_more_field_from_ldap_example";
|
||||||
'stat.php?other' => 'New stats 2',];
|
|
||||||
|
|
||||||
$PLUGIN_HOOKS[Hooks::POST_INIT]['example'] = 'plugin_example_postinit';
|
// Retrieve others datas from LDAP
|
||||||
|
//$PLUGIN_HOOKS['retrieve_more_data_from_ldap']['example']="plugin_retrieve_more_data_from_ldap_example";
|
||||||
|
|
||||||
$PLUGIN_HOOKS['status']['example'] = 'plugin_example_Status';
|
// Reports
|
||||||
|
$PLUGIN_HOOKS['reports']['example'] = ['report.php' => 'New Report',
|
||||||
|
'report.php?other' => 'New Report 2'];
|
||||||
|
|
||||||
// CSRF compliance : All actions must be done via POST and forms closed by Html::closeForm();
|
// Stats
|
||||||
$PLUGIN_HOOKS[Hooks::CSRF_COMPLIANT]['example'] = true;
|
$PLUGIN_HOOKS['stats']['example'] = ['stat.php' => 'New stat',
|
||||||
|
'stat.php?other' => 'New stats 2',];
|
||||||
|
|
||||||
$PLUGIN_HOOKS[Hooks::DISPLAY_CENTRAL]['example'] = "plugin_example_display_central";
|
$PLUGIN_HOOKS[Hooks::POST_INIT]['example'] = 'plugin_example_postinit';
|
||||||
$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,
|
$PLUGIN_HOOKS['status']['example'] = 'plugin_example_Status';
|
||||||
// see GlpiPlugin\Example\Showtabitem class for implementation explanations
|
|
||||||
$PLUGIN_HOOKS[Hooks::PRE_SHOW_TAB]['example'] = [Showtabitem::class, 'pre_show_tab'];
|
|
||||||
$PLUGIN_HOOKS[Hooks::POST_SHOW_TAB]['example'] = [Showtabitem::class, 'post_show_tab'];
|
|
||||||
$PLUGIN_HOOKS[Hooks::PRE_SHOW_ITEM]['example'] = [Showtabitem::class, 'pre_show_item'];
|
|
||||||
$PLUGIN_HOOKS[Hooks::POST_SHOW_ITEM]['example'] = [Showtabitem::class, 'post_show_item'];
|
|
||||||
|
|
||||||
$PLUGIN_HOOKS[Hooks::PRE_ITEM_FORM]['example'] = [ItemForm::class, 'preItemForm'];
|
$PLUGIN_HOOKS[Hooks::DISPLAY_CENTRAL]['example'] = "plugin_example_display_central";
|
||||||
$PLUGIN_HOOKS[Hooks::POST_ITEM_FORM]['example'] = [ItemForm::class, 'postItemForm'];
|
$PLUGIN_HOOKS[Hooks::DISPLAY_LOGIN]['example'] = "plugin_example_display_login";
|
||||||
|
$PLUGIN_HOOKS[Hooks::INFOCOM]['example'] = "plugin_example_infocom_hook";
|
||||||
|
|
||||||
//TODO: remove check when GLPI 11.0.0 is released
|
// pre_show and post_show for tabs and items,
|
||||||
if (version_compare(GLPI_VERSION, '11.0.0', 'ge')) {
|
// see GlpiPlugin\Example\Showtabitem class for implementation explanations
|
||||||
$PLUGIN_HOOKS[Hooks::PRE_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'preSection'];
|
$PLUGIN_HOOKS[Hooks::PRE_SHOW_TAB]['example'] = [Showtabitem::class, 'pre_show_tab'];
|
||||||
$PLUGIN_HOOKS[Hooks::POST_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'postSection'];
|
$PLUGIN_HOOKS[Hooks::POST_SHOW_TAB]['example'] = [Showtabitem::class, 'post_show_tab'];
|
||||||
}
|
$PLUGIN_HOOKS[Hooks::PRE_SHOW_ITEM]['example'] = [Showtabitem::class, 'pre_show_item'];
|
||||||
|
$PLUGIN_HOOKS[Hooks::POST_SHOW_ITEM]['example'] = [Showtabitem::class, 'post_show_item'];
|
||||||
|
|
||||||
// Add new actions to timeline
|
$PLUGIN_HOOKS[Hooks::PRE_ITEM_FORM]['example'] = [ItemForm::class, 'preItemForm'];
|
||||||
$PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['example'] = [
|
$PLUGIN_HOOKS[Hooks::POST_ITEM_FORM]['example'] = [ItemForm::class, 'postItemForm'];
|
||||||
ItemForm::class, 'timelineActions'
|
|
||||||
];
|
|
||||||
|
|
||||||
// declare this plugin as an import plugin for Computer itemtype
|
$PLUGIN_HOOKS[Hooks::PRE_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'preSection'];
|
||||||
$PLUGIN_HOOKS['import_item']['example'] = [Computer::class => ['Plugin']];
|
$PLUGIN_HOOKS[Hooks::POST_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'postSection'];
|
||||||
|
|
||||||
// add additional informations on Computer::showForm
|
// Add new actions to timeline
|
||||||
$PLUGIN_HOOKS[Hooks::AUTOINVENTORY_INFORMATION]['example'] = [
|
$PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['example'] = [
|
||||||
Computer::class => [Computer::class, 'showInfo']
|
ItemForm::class, 'timelineActions',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// declare this plugin as an import plugin for Computer itemtype
|
||||||
|
$PLUGIN_HOOKS['import_item']['example'] = [Computer::class => ['Plugin']];
|
||||||
|
|
||||||
|
// add additional informations on Computer::showForm
|
||||||
|
$PLUGIN_HOOKS[Hooks::AUTOINVENTORY_INFORMATION]['example'] = [
|
||||||
|
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
|
// add new cards to dashboard grid
|
||||||
$PLUGIN_HOOKS['dashboard_types']['example'] = [Example::class, 'dashboardTypes'];
|
$PLUGIN_HOOKS['dashboard_types']['example'] = [Example::class, 'dashboardTypes'];
|
||||||
$PLUGIN_HOOKS['dashboard_cards']['example'] = [Example::class, 'dashboardCards'];
|
$PLUGIN_HOOKS['dashboard_cards']['example'] = [Example::class, 'dashboardCards'];
|
||||||
|
|
||||||
// Dashboard filter
|
// Dashboard filter
|
||||||
$PLUGIN_HOOKS[Hooks::DASHBOARD_FILTERS]['example'] = [
|
$PLUGIN_HOOKS[Hooks::DASHBOARD_FILTERS]['example'] = [
|
||||||
ComputerModelFilter::class
|
ComputerModelFilter::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
//TODO: remove check when GLPI 11.0.0 is released
|
$PLUGIN_HOOKS[Hooks::SET_ITEM_IMPACT_ICON]['example'] = 'plugin_example_set_impact_icon';
|
||||||
if (version_compare(GLPI_VERSION, '11.0.0', 'ge')) {
|
|
||||||
// Icon in the impact analysis
|
|
||||||
$PLUGIN_HOOKS[Hooks::SET_ITEM_IMPACT_ICON]['example'] = 'plugin_example_set_impact_icon';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -304,20 +305,21 @@ function plugin_init_example() {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function plugin_version_example() {
|
function plugin_version_example()
|
||||||
return [
|
{
|
||||||
'name' => 'Plugin Example',
|
return [
|
||||||
'version' => PLUGIN_EXAMPLE_VERSION,
|
'name' => 'Plugin Example',
|
||||||
'author' => 'Example plugin team',
|
'version' => PLUGIN_EXAMPLE_VERSION,
|
||||||
'license' => 'GPLv2+',
|
'author' => 'Example plugin team',
|
||||||
'homepage' => 'https://github.com/pluginsGLPI/example',
|
'license' => 'GPLv2+',
|
||||||
'requirements' => [
|
'homepage' => 'https://github.com/pluginsGLPI/example',
|
||||||
'glpi' => [
|
'requirements' => [
|
||||||
'min' => PLUGIN_EXAMPLE_MIN_GLPI,
|
'glpi' => [
|
||||||
'max' => PLUGIN_EXAMPLE_MAX_GLPI,
|
'min' => PLUGIN_EXAMPLE_MIN_GLPI,
|
||||||
]
|
'max' => PLUGIN_EXAMPLE_MAX_GLPI,
|
||||||
]
|
],
|
||||||
];
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -327,11 +329,12 @@ function plugin_version_example() {
|
|||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function plugin_example_check_prerequisites() {
|
function plugin_example_check_prerequisites()
|
||||||
if (false) {
|
{
|
||||||
return false;
|
if (false) {
|
||||||
}
|
return false;
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -341,13 +344,14 @@ function plugin_example_check_prerequisites() {
|
|||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function plugin_example_check_config($verbose = false) {
|
function plugin_example_check_config($verbose = false)
|
||||||
if (true) { // Your configuration check
|
{
|
||||||
return true;
|
if (true) { // Your configuration check
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
echo __('Installed / not configured', 'example');
|
echo __('Installed / not configured', 'example');
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use CommonDBChild;
|
use CommonDBChild;
|
||||||
use Session;
|
use Session;
|
||||||
|
|
||||||
@ -43,64 +44,68 @@ use Session;
|
|||||||
// enhancements.
|
// enhancements.
|
||||||
// For CommonDBRelation, the variable are quiet equivalent, but they use _1 and _2 for each side
|
// For CommonDBRelation, the variable are quiet equivalent, but they use _1 and _2 for each side
|
||||||
// parent
|
// parent
|
||||||
class Child extends CommonDBChild {
|
class Child extends CommonDBChild
|
||||||
|
{
|
||||||
// A child rely on an item. If $itemtype=='itemtype', then that is a variable item.
|
// A child rely on an item. If $itemtype=='itemtype', then that is a variable item.
|
||||||
static public $itemtype = 'itemtype';
|
public static $itemtype = 'itemtype';
|
||||||
static public $items_id = 'items_id';
|
public static $items_id = 'items_id';
|
||||||
|
|
||||||
|
|
||||||
// With 0.84, you have to specify each right (create, view, update and delete), because
|
// 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
|
// CommonDBChild(s) and CommonDBRelation(s) mainly depend on the rights on the parent item
|
||||||
// All these methods rely on parent:can*. Two attributs are usefull :
|
// All these methods rely on parent:can*. Two attributs are usefull :
|
||||||
// * $checkParentRights: define what to check regarding the parent :
|
// * $checkParentRights: define what to check regarding the parent :
|
||||||
// - CommonDBConnexity::DONT_CHECK_ITEM_RIGHTS don't eaven relly on parents rights
|
// - CommonDBConnexity::DONT_CHECK_ITEM_RIGHTS don't eaven relly on parents rights
|
||||||
// - CommonDBConnexity::HAVE_VIEW_RIGHT_ON_ITEM view right on the item is enough
|
// - CommonDBConnexity::HAVE_VIEW_RIGHT_ON_ITEM view right on the item is enough
|
||||||
// - CommonDBConnexity::HAVE_SAME_RIGHT_ON_ITEM we must have at least update right
|
// - CommonDBConnexity::HAVE_SAME_RIGHT_ON_ITEM we must have at least update right
|
||||||
// on the item
|
// on the item
|
||||||
// * $mustBeAttached: some CommonDBChild can be free, without any parent.
|
// * $mustBeAttached: some CommonDBChild can be free, without any parent.
|
||||||
static function canCreate() {
|
public static function canCreate(): bool
|
||||||
|
{
|
||||||
|
|
||||||
return (Session::haveRight('internet', UPDATE)
|
return (Session::haveRight('internet', UPDATE)
|
||||||
&& parent::canCreate());
|
&& parent::canCreate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static function canView() {
|
public static function canView(): bool
|
||||||
|
{
|
||||||
|
|
||||||
return (Session::haveRight('internet', READ)
|
return (Session::haveRight('internet', READ)
|
||||||
&& parent::canView());
|
&& parent::canView());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static function canUpdate() {
|
public static function canUpdate(): bool
|
||||||
|
{
|
||||||
|
|
||||||
return (Session::haveRight('internet', UPDATE)
|
return (Session::haveRight('internet', UPDATE)
|
||||||
&& parent::canUpdate());
|
&& parent::canUpdate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static function canDelete() {
|
public static function canDelete(): bool
|
||||||
|
{
|
||||||
|
|
||||||
return (Session::haveRight('internet', DELETE)
|
return (Session::haveRight('internet', DELETE)
|
||||||
&& parent::canDelete());
|
&& parent::canDelete());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// By default, post_addItem, post_updateItem and post_deleteFromDB are defined.
|
// By default, post_addItem, post_updateItem and post_deleteFromDB are defined.
|
||||||
// They define the history to add to the parents
|
// They define the history to add to the parents
|
||||||
// This method define the name to set inside the history of the parent.
|
// 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
|
// 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 ...)
|
// 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
|
// CommonDBChild also check if we can add or updatethe item regarding the new item
|
||||||
// ($input[static::$itemtype] and $input[static::$items_id]).
|
// ($input[static::$itemtype] and $input[static::$items_id]).
|
||||||
// But don't forget to call parent::prepareInputForAdd()
|
// But don't forget to call parent::prepareInputForAdd()
|
||||||
function prepareInputForAdd($input) {
|
public function prepareInputForAdd($input)
|
||||||
// My preparation on $input
|
{
|
||||||
return parent::prepareInputForAdd($input);
|
// My preparation on $input
|
||||||
}
|
return parent::prepareInputForAdd($input);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,50 +34,48 @@
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use CommonDBTM;
|
use CommonDBTM;
|
||||||
|
|
||||||
// Class of the defined type
|
class Computer extends CommonDBTM
|
||||||
|
{
|
||||||
|
public static function showInfo()
|
||||||
|
{
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
echo '<table class="tab_glpi" width="100%">';
|
||||||
die("Sorry. You can't access directly to this file");
|
echo '<tr>';
|
||||||
}
|
echo '<th>' . __('More information') . '</th>';
|
||||||
|
echo '</tr>';
|
||||||
class Computer extends CommonDBTM {
|
echo '<tr class="tab_bg_1">';
|
||||||
|
echo '<td>';
|
||||||
static function showInfo() {
|
echo __('Test successful');
|
||||||
|
echo '</td>';
|
||||||
echo '<table class="tab_glpi" width="100%">';
|
echo '</tr>';
|
||||||
echo '<tr>';
|
echo '</table>';
|
||||||
echo '<th>'.__('More information').'</th>';
|
}
|
||||||
echo '</tr>';
|
|
||||||
echo '<tr class="tab_bg_1">';
|
|
||||||
echo '<td>';
|
|
||||||
echo __('Test successful');
|
|
||||||
echo '</td>';
|
|
||||||
echo '</tr>';
|
|
||||||
echo '</table>';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static function item_can($item) {
|
public static function item_can($item)
|
||||||
|
{
|
||||||
|
|
||||||
if (($item->getType() == 'Computer')
|
if (($item->getType() == 'Computer')
|
||||||
&& ($item->right == READ)
|
&& ($item->right == READ)
|
||||||
&& ($item->fields['groups_id'] > 0)
|
&& ($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.
|
$item->right = 0; // unknown, so denied.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static function add_default_where($in) {
|
public static function add_default_where($in)
|
||||||
|
{
|
||||||
|
|
||||||
list($itemtype, $condition) = $in;
|
list($itemtype, $condition) = $in;
|
||||||
if ($itemtype == 'Computer') {
|
if ($itemtype == 'Computer') {
|
||||||
$table = getTableForItemType($itemtype);
|
$table = getTableForItemType($itemtype);
|
||||||
$condition .= " (".$table.".groups_id NOT IN (".implode(',', $_SESSION["glpigroups"])."))";
|
$condition .= " (" . $table . ".groups_id NOT IN (" . implode(',', $_SESSION["glpigroups"]) . "))";
|
||||||
}
|
}
|
||||||
return [$itemtype, $condition];
|
return [$itemtype, $condition];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use CommonDBTM;
|
use CommonDBTM;
|
||||||
use CommonGLPI;
|
use CommonGLPI;
|
||||||
use Config as GlpiConfig;
|
use Config as GlpiConfig;
|
||||||
@ -37,60 +38,65 @@ use Html;
|
|||||||
use Session;
|
use Session;
|
||||||
use Toolbox;
|
use Toolbox;
|
||||||
|
|
||||||
class Config extends CommonDBTM {
|
class Config extends CommonDBTM
|
||||||
|
{
|
||||||
|
protected static $notable = true;
|
||||||
|
|
||||||
static protected $notable = true;
|
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
||||||
|
{
|
||||||
|
|
||||||
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
|
if (!$withtemplate) {
|
||||||
|
if ($item->getType() == 'Config') {
|
||||||
|
return __('Example plugin');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if (!$withtemplate) {
|
public static function configUpdate($input)
|
||||||
if ($item->getType() == 'Config') {
|
{
|
||||||
return __('Example plugin');
|
$input['configuration'] = 1 - $input['configuration'];
|
||||||
}
|
return $input;
|
||||||
}
|
}
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
static function configUpdate($input) {
|
public function showFormExample()
|
||||||
$input['configuration'] = 1 - $input['configuration'];
|
{
|
||||||
return $input;
|
/** @var array $CFG_GLPI */
|
||||||
}
|
global $CFG_GLPI;
|
||||||
|
|
||||||
function showFormExample() {
|
if (!Session::haveRight("config", UPDATE)) {
|
||||||
global $CFG_GLPI;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Session::haveRight("config", UPDATE)) {
|
$my_config = GlpiConfig::getConfigurationValues('plugin:Example');
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$my_config = GlpiConfig::getConfigurationValues('plugin:Example');
|
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 "<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>";
|
||||||
|
|
||||||
echo "<form name='form' action=\"".Toolbox::getItemTypeFormURL('Config')."\" method='post'>";
|
echo "<tr class='tab_bg_2'>";
|
||||||
echo "<div class='center' id='tabsbody'>";
|
echo "<td colspan='4' class='center'>";
|
||||||
echo "<table class='tab_cadre_fixe'>";
|
echo "<input type='submit' name='update' class='submit' value=\"" . _sx('button', 'Save') . "\">";
|
||||||
echo "<tr><th colspan='4'>" . __('Example setup') . "</th></tr>";
|
echo "</td></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>";
|
|
||||||
|
|
||||||
echo "<tr class='tab_bg_2'>";
|
echo "</table></div>";
|
||||||
echo "<td colspan='4' class='center'>";
|
Html::closeForm();
|
||||||
echo "<input type='submit' name='update' class='submit' value=\""._sx('button', 'Save')."\">";
|
}
|
||||||
echo "</td></tr>";
|
|
||||||
|
|
||||||
echo "</table></div>";
|
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
|
||||||
Html::closeForm();
|
{
|
||||||
}
|
if ($item->getType() == Config::class) {
|
||||||
|
$config = new self();
|
||||||
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
|
$config->showFormExample();
|
||||||
|
}
|
||||||
if ($item->getType() == 'Config') {
|
return true;
|
||||||
$config = new self();
|
}
|
||||||
$config->showFormExample();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,19 +34,15 @@
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use CommonDevice;
|
use CommonDevice;
|
||||||
|
|
||||||
// Class of the defined type
|
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
|
||||||
die("Sorry. You can't access directly to this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Class DeviceCamera
|
/// Class DeviceCamera
|
||||||
class DeviceCamera extends CommonDevice {
|
class DeviceCamera extends CommonDevice
|
||||||
|
{
|
||||||
static function getTypeName($nb = 0) {
|
public static function getTypeName($nb = 0)
|
||||||
return _n('Camera', 'Cameras', $nb);
|
{
|
||||||
}
|
return _n('Camera', 'Cameras', $nb);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
342
src/Document.php
342
src/Document.php
@ -1,30 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/**
|
||||||
-------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
GLPI - Gestionnaire Libre de Parc Informatique
|
* Example plugin for GLPI
|
||||||
Copyright (C) 2003-2011 by the INDEPNET Development Team.
|
* -------------------------------------------------------------------------
|
||||||
|
*
|
||||||
http://indepnet.net/ http://glpi-project.org
|
* LICENSE
|
||||||
-------------------------------------------------------------------------
|
*
|
||||||
|
* This file is part of Example.
|
||||||
LICENSE
|
*
|
||||||
|
* Example is free software; you can redistribute it and/or modify
|
||||||
This file is part of GLPI.
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
GLPI is free software; you can redistribute it and/or modify
|
* (at your option) any later version.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Example is distributed in the hope that it will be useful,
|
||||||
(at your option) any later version.
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GLPI is distributed in the hope that it will be useful,
|
* GNU General Public License for more details.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
*
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* You should have received a copy of the GNU General Public License
|
||||||
GNU General Public License for more details.
|
* along with Example. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
You should have received a copy of the GNU General Public License
|
* @copyright Copyright (C) 2006-2022 by Example plugin team.
|
||||||
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
|
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
--------------------------------------------------------------------------
|
* @link https://github.com/pluginsGLPI/example
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,14 +56,14 @@ along with GLPI. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use Document as GlpiDocument;
|
use Document as GlpiDocument;
|
||||||
|
use Exception;
|
||||||
|
use Glpi\Exception\Http\NotFoundHttpException;
|
||||||
|
use Sabre\DAV\Exception\BadRequest;
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
class Document extends GlpiDocument
|
||||||
die("Sorry. You can't access this file directly");
|
{
|
||||||
}
|
|
||||||
|
|
||||||
class Document extends GlpiDocument {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the table used to store this object. Overloads the implementation in CommonDBTM
|
* Return the table used to store this object. Overloads the implementation in CommonDBTM
|
||||||
*
|
*
|
||||||
@ -70,155 +71,160 @@ class Document extends GlpiDocument {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
**/
|
**/
|
||||||
public static function getTable($classname = null) {
|
public static function getTable($classname = null)
|
||||||
if ($classname === null) {
|
{
|
||||||
$classname = get_called_class();
|
if ($classname === null) {
|
||||||
}
|
$classname = get_called_class();
|
||||||
if ($classname == get_called_class()) {
|
}
|
||||||
return parent::getTable(Document::class);
|
if ($classname == get_called_class()) {
|
||||||
}
|
return parent::getTable(Document::class);
|
||||||
|
}
|
||||||
|
|
||||||
return parent::getTable($classname);
|
return parent::getTable($classname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare creation of an item
|
* Prepare creation of an item
|
||||||
*
|
*
|
||||||
* @param array $input
|
* @param array $input
|
||||||
* @return array|false
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
public function prepareInputForAdd($input) {
|
public function prepareInputForAdd($input)
|
||||||
$input['_only_if_upload_succeed'] = true;
|
{
|
||||||
if (!isset($_FILES['file'])) {
|
$input['_only_if_upload_succeed'] = true;
|
||||||
return false;
|
if (!isset($_FILES['file'])) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Move the uploaded file to GLPi's tmp dir
|
// Move the uploaded file to GLPi's tmp dir
|
||||||
while (count($_FILES['file']['name']) > 0) {
|
while (count($_FILES['file']['name']) > 0) {
|
||||||
$source = array_pop($_FILES['file']['name']);
|
$source = array_pop($_FILES['file']['name']);
|
||||||
$destination = GLPI_TMP_DIR . '/' . $source;
|
$destination = GLPI_TMP_DIR . '/' . $source;
|
||||||
move_uploaded_file($source, $destination);
|
move_uploaded_file($source, $destination);
|
||||||
$input['_filename'][] = $source;
|
$input['_filename'][] = $source;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::prepareInputForAdd($input);
|
return parent::prepareInputForAdd($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare update of an item
|
* Prepare update of an item
|
||||||
*
|
*
|
||||||
* @param array $input
|
* @param array $input
|
||||||
* @return array|false
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
public function prepareInputForUpdate($input) {
|
public function prepareInputForUpdate($input)
|
||||||
// Do not allow update of document
|
{
|
||||||
return false;
|
// Do not allow update of document
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process required after loading an object from DB
|
* Process required after loading an object from DB
|
||||||
* In this example, a file is sent as a byte strem then stops execution.
|
* In this example, a file is sent as a byte strem then stops execution.
|
||||||
*
|
*
|
||||||
* @return void
|
* @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()) {
|
// Check the user can view this itemtype and can view this item
|
||||||
if (isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/octet-stream'
|
if ($this->canView() && $this->canViewItem()) {
|
||||||
|| isset($_GET['alt']) && $_GET['alt'] == 'media') {
|
if (isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/octet-stream'
|
||||||
$this->sendFile(); // and terminate script
|
|| isset($_GET['alt']) && $_GET['alt'] == 'media') {
|
||||||
}
|
$this->sendFile(); // and terminate script
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a byte stream to the HTTP client and stops execution
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
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");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Download range defaults to the full file
|
|
||||||
// get file metadata
|
|
||||||
$size = filesize($streamSource);
|
|
||||||
$begin = 0;
|
|
||||||
$end = $size - 1;
|
|
||||||
$mimeType = 'application/octet-stream';
|
|
||||||
$time = date('r', filemtime($streamSource));
|
|
||||||
|
|
||||||
// Open the file
|
|
||||||
$fileHandle = @fopen($streamSource, 'rb');
|
|
||||||
if (!$fileHandle) {
|
|
||||||
header ("HTTP/1.0 500 Internal Server Error");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set range if specified by the client
|
|
||||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
|
||||||
if (preg_match('/bytes=\h*(\d+)?-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) {
|
|
||||||
if (!empty($matches[1])) {
|
|
||||||
$begin = intval($matches[1]);
|
|
||||||
}
|
}
|
||||||
if (!empty($matches[2])) {
|
}
|
||||||
$end = min(intval($matches[2]), $end);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a byte stream to the HTTP client and stops execution
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
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");
|
||||||
|
throw new NotFoundHttpException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download range defaults to the full file
|
||||||
|
// get file metadata
|
||||||
|
$size = filesize($streamSource);
|
||||||
|
$begin = 0;
|
||||||
|
$end = $size - 1;
|
||||||
|
$mimeType = 'application/octet-stream';
|
||||||
|
$time = date('r', filemtime($streamSource));
|
||||||
|
|
||||||
|
// Open the file
|
||||||
|
$fileHandle = @fopen($streamSource, 'rb');
|
||||||
|
if (!$fileHandle) {
|
||||||
|
header("HTTP/1.0 500 Internal Server Error");
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
// set range if specified by the client
|
||||||
|
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||||
|
if (preg_match('/bytes=\h*(\d+)?-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) {
|
||||||
|
if (!empty($matches[1])) {
|
||||||
|
$begin = intval($matches[1]);
|
||||||
|
}
|
||||||
|
if (!empty($matches[2])) {
|
||||||
|
$end = min(intval($matches[2]), $end);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// seek to the begining of the range
|
// seek to the begining of the range
|
||||||
$currentPosition = $begin;
|
$currentPosition = $begin;
|
||||||
if (fseek($fileHandle, $begin, SEEK_SET) < 0) {
|
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);
|
throw new Exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
// send headers to ensure the client is able to detect a corrupted download
|
// send headers to ensure the client is able to detect a corrupted download
|
||||||
// example : less bytes than the expected range
|
// example : less bytes than the expected range
|
||||||
// send meta data
|
// send meta data
|
||||||
// setup client's cache behavior
|
// 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('Pragma: private'); /// IE BUG + SSL
|
||||||
header('Cache-control: private, must-revalidate'); /// 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("Content-type: $mimeType");
|
||||||
header("Last-Modified: $time");
|
header("Last-Modified: $time");
|
||||||
header('Accept-Ranges: bytes');
|
header('Accept-Ranges: bytes');
|
||||||
header('Content-Length:' . ($end - $begin + 1));
|
header('Content-Length:' . ($end - $begin + 1));
|
||||||
header("Content-Range: bytes $begin-$end/$size");
|
header("Content-Range: bytes $begin-$end/$size");
|
||||||
header("Content-Transfer-Encoding: binary\n");
|
header("Content-Transfer-Encoding: binary\n");
|
||||||
header('Connection: close');
|
header('Connection: close');
|
||||||
|
|
||||||
// Prepare HTTP response
|
// Prepare HTTP response
|
||||||
if ($begin > 0 || $end < $size - 1) {
|
if ($begin > 0 || $end < $size - 1) {
|
||||||
header('HTTP/1.0 206 Partial Content');
|
header('HTTP/1.0 206 Partial Content');
|
||||||
} else {
|
} else {
|
||||||
header('HTTP/1.0 200 OK');
|
header('HTTP/1.0 200 OK');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends bytes until the end of the range or connection closed
|
// Sends bytes until the end of the range or connection closed
|
||||||
while (!feof($fileHandle) && $currentPosition < $end && (connection_status() == 0)) {
|
while (!feof($fileHandle) && $currentPosition < $end && (connection_status() == 0)) {
|
||||||
// allow a few seconds to send a few KB.
|
// allow a few seconds to send a few KB.
|
||||||
set_time_limit(10);
|
set_time_limit(10);
|
||||||
$content = fread($fileHandle, min(1024 * 16, $end - $currentPosition + 1));
|
$content = fread($fileHandle, min(1024 * 16, $end - $currentPosition + 1));
|
||||||
if ($content === false) {
|
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);
|
throw new Exception();
|
||||||
} else {
|
} else {
|
||||||
print $content;
|
print $content;
|
||||||
}
|
}
|
||||||
flush();
|
flush();
|
||||||
$currentPosition += 1024 * 16;
|
$currentPosition += 1024 * 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
// End now to prevent any unwanted bytes
|
// End now to prevent any unwanted bytes
|
||||||
exit(0);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,18 +32,20 @@
|
|||||||
// Original Author of file:
|
// Original Author of file:
|
||||||
// Purpose of file:
|
// Purpose of file:
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use CommonDropdown;
|
use CommonDropdown;
|
||||||
|
|
||||||
// Class for a Dropdown
|
// Class for a Dropdown
|
||||||
class Dropdown extends CommonDropdown {
|
class Dropdown extends CommonDropdown
|
||||||
|
{
|
||||||
|
public static function getTypeName($nb = 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($nb > 0) {
|
||||||
static function getTypeName($nb = 0) {
|
return __('Plugin Example Dropdowns', 'example');
|
||||||
|
}
|
||||||
if ($nb > 0) {
|
return __('Plugin Example Dropdowns', 'example');
|
||||||
return __('Plugin Example Dropdowns', 'example');
|
}
|
||||||
}
|
|
||||||
return __('Plugin Example Dropdowns', 'example');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
914
src/Example.php
914
src/Example.php
File diff suppressed because it is too large
Load Diff
@ -48,6 +48,7 @@ class ComputerModelFilter extends AbstractFilter
|
|||||||
|
|
||||||
public static function canBeApplied(string $table): bool
|
public static function canBeApplied(string $table): bool
|
||||||
{
|
{
|
||||||
|
/** @var DBmysql $DB */
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
return $DB->fieldExists($table, ComputerModel::getForeignKeyField());
|
return $DB->fieldExists($table, ComputerModel::getForeignKeyField());
|
||||||
@ -59,7 +60,7 @@ class ComputerModelFilter extends AbstractFilter
|
|||||||
self::getName(),
|
self::getName(),
|
||||||
is_string($value) ? $value : "",
|
is_string($value) ? $value : "",
|
||||||
self::getId(),
|
self::getId(),
|
||||||
ComputerModel::class
|
ComputerModel::class,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,8 +70,8 @@ class ComputerModelFilter extends AbstractFilter
|
|||||||
$field = ComputerModel::getForeignKeyField();
|
$field = ComputerModel::getForeignKeyField();
|
||||||
return [
|
return [
|
||||||
"WHERE" => [
|
"WHERE" => [
|
||||||
"$table.$field" => (int) $value
|
"$table.$field" => (int) $value,
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,9 +89,9 @@ class ComputerModelFilter extends AbstractFilter
|
|||||||
'field' => self::getSearchOptionID(
|
'field' => self::getSearchOptionID(
|
||||||
$table,
|
$table,
|
||||||
ComputerModel::getForeignKeyField(),
|
ComputerModel::getForeignKeyField(),
|
||||||
ComputerModel::getTable()
|
ComputerModel::getTable(),
|
||||||
),
|
),
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
228
src/ItemForm.php
228
src/ItemForm.php
@ -39,21 +39,21 @@ use Ticket;
|
|||||||
* Example of *_item_form implementation
|
* Example of *_item_form implementation
|
||||||
* @see http://glpi-developer-documentation.rtfd.io/en/master/plugins/hooks.html#items-display-related
|
* @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).
|
||||||
|
*
|
||||||
|
* @param array $params Array with "item" and "options" keys
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function preSection($params)
|
||||||
|
{
|
||||||
|
$item = $params['item'];
|
||||||
|
$options = $params['options'];
|
||||||
|
|
||||||
|
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
|
||||||
/**
|
|
||||||
* Display contents at the begining of ITILObject section (right panel).
|
|
||||||
*
|
|
||||||
* @param array $params Array with "item" and "options" keys
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
static public function preSection($params) {
|
|
||||||
$item = $params['item'];
|
|
||||||
$options = $params['options'];
|
|
||||||
|
|
||||||
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
|
|
||||||
<section class="accordion-item" aria-label="a label">
|
<section class="accordion-item" aria-label="a label">
|
||||||
<h2 class="accordion-header" id="example-heading" title="example-heading-id" data-bs-toggle="tooltip">
|
<h2 class="accordion-header" id="example-heading" title="example-heading-id" data-bs-toggle="tooltip">
|
||||||
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#example-pre-content" aria-expanded="true" aria-controls="example-pre-content">
|
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#example-pre-content" aria-expanded="true" aria-controls="example-pre-content">
|
||||||
@ -71,20 +71,21 @@ class ItemForm {
|
|||||||
</section>
|
</section>
|
||||||
TWIG, []);
|
TWIG, []);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display contents at the end of ITILObject section (right panel).
|
* Display contents at the end of ITILObject section (right panel).
|
||||||
*
|
*
|
||||||
* @param array $params Array with "item" and "options" keys
|
* @param array $params Array with "item" and "options" keys
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static public function postSection($params) {
|
public static function postSection($params)
|
||||||
$item = $params['item'];
|
{
|
||||||
$options = $params['options'];
|
$item = $params['item'];
|
||||||
|
$options = $params['options'];
|
||||||
|
|
||||||
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
|
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
|
||||||
<section class="accordion-item" aria-label="a label">
|
<section class="accordion-item" aria-label="a label">
|
||||||
<h2 class="accordion-header" id="example-heading" title="example-heading-id" data-bs-toggle="tooltip">
|
<h2 class="accordion-header" id="example-heading" title="example-heading-id" data-bs-toggle="tooltip">
|
||||||
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#example-post-content" aria-expanded="true" aria-controls="example-post-content">
|
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#example-post-content" aria-expanded="true" aria-controls="example-post-content">
|
||||||
@ -101,106 +102,109 @@ TWIG, []);
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
TWIG, []);
|
TWIG, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display contents at the begining of item forms.
|
* Display contents at the begining of item forms.
|
||||||
*
|
*
|
||||||
* @param array $params Array with "item" and "options" keys
|
* @param array $params Array with "item" and "options" keys
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static public function preItemForm($params) {
|
public static function preItemForm($params)
|
||||||
$item = $params['item'];
|
{
|
||||||
$options = $params['options'];
|
$item = $params['item'];
|
||||||
|
$options = $params['options'];
|
||||||
|
|
||||||
$firstelt = ($item::getType() == Ticket::class ? 'th' : 'td');
|
$firstelt = ($item::getType() == Ticket::class ? 'th' : 'td');
|
||||||
|
|
||||||
$out = '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
$out = '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
||||||
$out .= sprintf(
|
$out .= sprintf(
|
||||||
__('Start %1$s hook call for %2$s type'),
|
__('Start %1$s hook call for %2$s type'),
|
||||||
'pre_item_form',
|
'pre_item_form',
|
||||||
$item::getType()
|
$item::getType(),
|
||||||
);
|
);
|
||||||
$out .= '</th></tr>';
|
$out .= '</th></tr>';
|
||||||
|
|
||||||
$out .= "<tr><$firstelt>";
|
$out .= "<tr><$firstelt>";
|
||||||
$out .= '<label for="example_pre_form_hook">' . __('First pre form hook') . '</label>';
|
$out .= '<label for="example_pre_form_hook">' . __('First pre form hook') . '</label>';
|
||||||
$out .= "</$firstelt><td>";
|
$out .= "</$firstelt><td>";
|
||||||
$out .= '<input type="text" name="example_pre_form_hook" id="example_pre_form_hook"/>';
|
$out .= '<input type="text" name="example_pre_form_hook" id="example_pre_form_hook"/>';
|
||||||
$out .= "</td><$firstelt>";
|
$out .= "</td><$firstelt>";
|
||||||
$out .= '<label for="example_pre_form_hook2">' . __('Second pre form hook') . '</label>';
|
$out .= '<label for="example_pre_form_hook2">' . __('Second pre form hook') . '</label>';
|
||||||
$out .= "</$firstelt><td>";
|
$out .= "</$firstelt><td>";
|
||||||
$out .= '<input type="text" name="example_pre_form_hook2" id="example_pre_form_hook2"/>';
|
$out .= '<input type="text" name="example_pre_form_hook2" id="example_pre_form_hook2"/>';
|
||||||
$out .= '</td></tr>';
|
$out .= '</td></tr>';
|
||||||
|
|
||||||
$out .= '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
$out .= '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
||||||
$out .= sprintf(
|
$out .= sprintf(
|
||||||
__('End %1$s hook call for %2$s type'),
|
__('End %1$s hook call for %2$s type'),
|
||||||
'pre_item_form',
|
'pre_item_form',
|
||||||
$item::getType()
|
$item::getType(),
|
||||||
);
|
);
|
||||||
$out .= '</th></tr>';
|
$out .= '</th></tr>';
|
||||||
|
|
||||||
echo $out;
|
echo $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display contents at the begining of item forms.
|
* Display contents at the begining of item forms.
|
||||||
*
|
*
|
||||||
* @param array $params Array with "item" and "options" keys
|
* @param array $params Array with "item" and "options" keys
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static public function postItemForm($params) {
|
public static function postItemForm($params)
|
||||||
$item = $params['item'];
|
{
|
||||||
$options = $params['options'];
|
$item = $params['item'];
|
||||||
|
$options = $params['options'];
|
||||||
|
|
||||||
$firstelt = ($item::getType() == Ticket::class ? 'th' : 'td');
|
$firstelt = ($item::getType() == Ticket::class ? 'th' : 'td');
|
||||||
|
|
||||||
$out = '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
$out = '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
||||||
$out .= sprintf(
|
$out .= sprintf(
|
||||||
__('Start %1$s hook call for %2$s type'),
|
__('Start %1$s hook call for %2$s type'),
|
||||||
'post_item_form',
|
'post_item_form',
|
||||||
$item::getType()
|
$item::getType(),
|
||||||
);
|
);
|
||||||
$out .= '</th></tr>';
|
$out .= '</th></tr>';
|
||||||
|
|
||||||
$out .= "<tr><$firstelt>";
|
$out .= "<tr><$firstelt>";
|
||||||
$out .= '<label for="example_post_form_hook">' . __('First post form hook') . '</label>';
|
$out .= '<label for="example_post_form_hook">' . __('First post form hook') . '</label>';
|
||||||
$out .= "</$firstelt><td>";
|
$out .= "</$firstelt><td>";
|
||||||
$out .= '<input type="text" name="example_post_form_hook" id="example_post_form_hook"/>';
|
$out .= '<input type="text" name="example_post_form_hook" id="example_post_form_hook"/>';
|
||||||
$out .= "</td><$firstelt>";
|
$out .= "</td><$firstelt>";
|
||||||
$out .= '<label for="example_post_form_hook2">' . __('Second post form hook') . '</label>';
|
$out .= '<label for="example_post_form_hook2">' . __('Second post form hook') . '</label>';
|
||||||
$out .= "</$firstelt><td>";
|
$out .= "</$firstelt><td>";
|
||||||
$out .= '<input type="text" name="example_post_form_hook2" id="example_post_form_hook2"/>';
|
$out .= '<input type="text" name="example_post_form_hook2" id="example_post_form_hook2"/>';
|
||||||
$out .= '</td></tr>';
|
$out .= '</td></tr>';
|
||||||
|
|
||||||
$out .= '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
$out .= '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
||||||
$out .= sprintf(
|
$out .= sprintf(
|
||||||
__('End %1$s hook call for %2$s type'),
|
__('End %1$s hook call for %2$s type'),
|
||||||
'post_item_form',
|
'post_item_form',
|
||||||
$item::getType()
|
$item::getType(),
|
||||||
);
|
);
|
||||||
$out .= '</th></tr>';
|
$out .= '</th></tr>';
|
||||||
|
|
||||||
echo $out;
|
echo $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function timelineActions($params = []) {
|
public static function timelineActions($params = [])
|
||||||
$rand = $params['rand'];
|
{
|
||||||
$ticket = $params['item'];
|
$rand = $params['rand'];
|
||||||
|
$ticket = $params['item'];
|
||||||
|
|
||||||
if (get_class($ticket) !== "Ticket") {
|
if (get_class($ticket) !== "Ticket") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$edit_panel = "viewitem".$ticket->fields['id'].$rand;
|
$edit_panel = "viewitem" . $ticket->fields['id'] . $rand;
|
||||||
$JS = <<<JAVASCRIPT
|
$JS = <<<JAVASCRIPT
|
||||||
$(function() {
|
$(function() {
|
||||||
$(document).on('click', '#email_transfer_{$rand}', function(event) {
|
$(document).on('click', '#email_transfer_{$rand}', function(event) {
|
||||||
$('#{$edit_panel}').html('email send');
|
$('#{$edit_panel}').html('email send');
|
||||||
@ -208,10 +212,10 @@ TWIG, []);
|
|||||||
});
|
});
|
||||||
JAVASCRIPT;
|
JAVASCRIPT;
|
||||||
|
|
||||||
echo "<li class='followup' id='email_transfer_$rand'>
|
echo "<li class='followup' id='email_transfer_$rand'>
|
||||||
<i class='far fa-envelope'></i>".
|
<i class='far fa-envelope'></i>" .
|
||||||
__("Send a notification").
|
__("Send a notification") .
|
||||||
Html::scriptBlock($JS)."
|
Html::scriptBlock($JS) . "
|
||||||
</li>";
|
</li>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,21 +36,18 @@
|
|||||||
// Class of the defined type
|
// Class of the defined type
|
||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use GlpiPlugin\Example\DeviceCamera;
|
use GlpiPlugin\Example\DeviceCamera;
|
||||||
use Item_Devices;
|
use Item_Devices;
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
|
||||||
die("Sorry. You can't access directly to this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relation between item and devices
|
* Relation between item and devices
|
||||||
**/
|
**/
|
||||||
class Item_DeviceCamera extends Item_Devices {
|
class Item_DeviceCamera extends Item_Devices
|
||||||
|
{
|
||||||
|
public static $itemtype_2 = DeviceCamera::class;
|
||||||
|
public static $items_id_2 = 'plugin_example_devicecameras_id';
|
||||||
|
|
||||||
static public $itemtype_2 = DeviceCamera::class;
|
protected static $notable = false;
|
||||||
static public $items_id_2 = 'plugin_example_devicecameras_id';
|
|
||||||
|
|
||||||
static protected $notable = false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,22 +29,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use NotificationTarget;
|
use NotificationTarget;
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
|
||||||
die("Sorry. You can't access directly to this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Class NotificationTarget
|
// Class NotificationTarget
|
||||||
class NotificationTargetExample extends NotificationTarget {
|
class NotificationTargetExample extends NotificationTarget
|
||||||
|
{
|
||||||
|
public function getEvents()
|
||||||
|
{
|
||||||
|
return ['alert' => 'alert example'];
|
||||||
|
}
|
||||||
|
|
||||||
function getEvents() {
|
public function addDataForTemplate($event, $options = [])
|
||||||
return ['alert' => 'alert example'];
|
{
|
||||||
}
|
$this->data['##example.name##'] = __('Example', 'example');
|
||||||
|
}
|
||||||
function addDataForTemplate($event, $options = []) {
|
|
||||||
global $DB, $CFG_GLPI;
|
|
||||||
|
|
||||||
$this->data['##example.name##'] = __('Example', 'example');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -34,17 +34,27 @@ use CommonGLPI;
|
|||||||
use Html;
|
use Html;
|
||||||
use Session;
|
use Session;
|
||||||
|
|
||||||
final class Profile extends \Profile
|
class Profile extends \Profile
|
||||||
{
|
{
|
||||||
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
||||||
{
|
{
|
||||||
return __('Example plugin');
|
if (
|
||||||
|
$item instanceof \Profile
|
||||||
|
&& $item->getField('id')
|
||||||
|
) {
|
||||||
|
return self::createTabEntry(__('Example plugin'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
|
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
|
||||||
{
|
{
|
||||||
$profile = new self();
|
if ($item instanceof self) {
|
||||||
$profile->showFormExample($item->getID());
|
$profile = new self();
|
||||||
|
$profile->showFormExample($item->getID());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showFormExample(int $profiles_id): void
|
public function showFormExample(int $profiles_id): void
|
||||||
@ -67,8 +77,8 @@ final class Profile extends \Profile
|
|||||||
[
|
[
|
||||||
'itemtype' => Example::class,
|
'itemtype' => Example::class,
|
||||||
'label' => Example::getTypeName(Session::getPluralNumber()),
|
'label' => Example::getTypeName(Session::getPluralNumber()),
|
||||||
'field' => Example::$rightname
|
'field' => Example::$rightname,
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
$matrix_options['title'] = self::getTypeName(1);
|
$matrix_options['title'] = self::getTypeName(1);
|
||||||
$this->displayRightsChoiceMatrix($rights, $matrix_options);
|
$this->displayRightsChoiceMatrix($rights, $matrix_options);
|
||||||
|
@ -34,13 +34,9 @@
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use Rule;
|
use Rule;
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
|
||||||
die("Sorry. You can't access directly to this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rule class store all informations about a GLPI rule :
|
* Rule class store all informations about a GLPI rule :
|
||||||
* - description
|
* - description
|
||||||
@ -48,40 +44,44 @@ if (!defined('GLPI_ROOT')) {
|
|||||||
* - actions
|
* - actions
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
class RuleTest extends Rule {
|
class RuleTest extends Rule
|
||||||
|
{
|
||||||
// From Rule
|
// From Rule
|
||||||
public static $rightname = 'rule_import';
|
public static $rightname = 'rule_import';
|
||||||
public $can_sort = true;
|
public $can_sort = true;
|
||||||
|
|
||||||
|
|
||||||
function getTitle() {
|
public function getTitle()
|
||||||
return 'test';
|
{
|
||||||
}
|
return 'test';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function maxActionsCount() {
|
public function maxActionsCount()
|
||||||
return 1;
|
{
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function getCriterias() {
|
public function getCriterias()
|
||||||
|
{
|
||||||
|
|
||||||
$criterias = [];
|
$criterias = [];
|
||||||
$criterias['name']['field'] = 'name';
|
$criterias['name']['field'] = 'name';
|
||||||
$criterias['name']['name'] = __('Software');
|
$criterias['name']['name'] = __('Software');
|
||||||
$criterias['name']['table'] = 'glpi_softwares';
|
$criterias['name']['table'] = 'glpi_softwares';
|
||||||
|
|
||||||
return $criterias;
|
return $criterias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getActions() {
|
public function getActions()
|
||||||
|
{
|
||||||
|
|
||||||
$actions = [];
|
$actions = [];
|
||||||
$actions['softwarecategories_id']['name'] = __('Category (class)', 'example');
|
$actions['softwarecategories_id']['name'] = __('Category (class)', 'example');
|
||||||
$actions['softwarecategories_id']['type'] = 'dropdown';
|
$actions['softwarecategories_id']['type'] = 'dropdown';
|
||||||
$actions['softwarecategories_id']['table'] = 'glpi_softwarecategories';
|
$actions['softwarecategories_id']['table'] = 'glpi_softwarecategories';
|
||||||
return $actions;
|
return $actions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,21 +34,18 @@
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use RuleCollection;
|
use RuleCollection;
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
class RuleTestCollection extends RuleCollection
|
||||||
die("Sorry. You can't access directly to this file");
|
{
|
||||||
}
|
// From RuleCollection
|
||||||
|
public $stop_on_first_match = true;
|
||||||
|
public static $rightname = 'rule_import';
|
||||||
class RuleTestCollection extends RuleCollection {
|
public $menu_option = 'test';
|
||||||
|
|
||||||
// From RuleCollection
|
public function getTitle()
|
||||||
public $stop_on_first_match = true;
|
{
|
||||||
public static $rightname = 'rule_import';
|
return 'Rulesengine test';
|
||||||
public $menu_option = 'test';
|
}
|
||||||
|
|
||||||
function getTitle() {
|
|
||||||
return 'Rulesengine test';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -51,45 +51,47 @@ namespace GlpiPlugin\Example;
|
|||||||
* post_show_tab will be fired after the tab show
|
* 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
|
||||||
|
* array( 'item', 'options')
|
||||||
|
* where 'item' is the parent object (like 'Ticket'),
|
||||||
|
* and 'options' are options like following
|
||||||
|
* array( 'tabnum', 'itemtype')
|
||||||
|
* where 'tabnum' is the internal name of the tab that will be shown
|
||||||
|
* 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)
|
||||||
|
*/
|
||||||
|
public static function pre_show_tab($params)
|
||||||
|
{
|
||||||
|
switch ($params['item']->getType()) {
|
||||||
|
case 'Ticket':
|
||||||
|
if ($params['options']['itemtype'] == 'TicketValidation' && $params['options']['tabnum'] == 2) {
|
||||||
|
// if tasks are not all done
|
||||||
|
// then prevent solution div to show
|
||||||
|
// this is an example to prevent solving of ticket
|
||||||
|
if (true) { // here you should test if some tasks are in todo status.
|
||||||
|
$params['options']['prevent_solution'] = true; // this will be passed to the post_show hook
|
||||||
|
echo "<div id='toHideSolution' style='display: none;'>"; // in order to hide the default solution div
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Summary of pre_show_tab
|
* Summary of post_show_tab
|
||||||
* @param array $params is an array like following
|
* @param array $params is identical to pre_show_tab parameter
|
||||||
* array( 'item', 'options')
|
* Note: you may get datas from pre_show_tab in $param['options'] array (see example below)
|
||||||
* where 'item' is the parent object (like 'Ticket'),
|
*/
|
||||||
* and 'options' are options like following
|
public static function post_show_tab($params)
|
||||||
* array( 'tabnum', 'itemtype')
|
{
|
||||||
* where 'tabnum' is the internal name of the tab that will be shown
|
switch ($params['item']->getType()) {
|
||||||
* and 'itemtype' is the type of the tab (ex: 'ITILFollowup' when showing followup tab in a ticket)
|
case 'Ticket':
|
||||||
* Note: you may pass datas to post_show_tab using the $param['options'] array (see example below)
|
if (isset($params['options']['prevent_solution'])) {
|
||||||
*/
|
echo "</div>";
|
||||||
static function pre_show_tab($params) {
|
echo "<div style='margin-bottom: 20px;' class='box'>
|
||||||
switch ($params['item']->getType()) {
|
|
||||||
case 'Ticket':
|
|
||||||
if ($params['options']['itemtype']=='TicketValidation' && $params['options']['tabnum']==2) {
|
|
||||||
// if tasks are not all done
|
|
||||||
// then prevent solution div to show
|
|
||||||
// this is an example to prevent solving of ticket
|
|
||||||
if (true) { // here you should test if some tasks are in todo status.
|
|
||||||
$params['options']['prevent_solution'] = true; // this will be passed to the post_show hook
|
|
||||||
echo "<div id='toHideSolution' style='display: none;'>"; // in order to hide the default solution div
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Summary of post_show_tab
|
|
||||||
* @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) {
|
|
||||||
switch ($params['item']->getType()) {
|
|
||||||
case 'Ticket':
|
|
||||||
if (isset($params['options']['prevent_solution'])) {
|
|
||||||
echo "</div>";
|
|
||||||
echo "<div style='margin-bottom: 20px;' class='box'>
|
|
||||||
<div class='box-tleft'>
|
<div class='box-tleft'>
|
||||||
<div class='box-tright'>
|
<div class='box-tright'>
|
||||||
<div class='box-tcenter'>
|
<div class='box-tcenter'>
|
||||||
@ -100,12 +102,12 @@ class Showtabitem {
|
|||||||
<div class='box-mright'>
|
<div class='box-mright'>
|
||||||
<div class='box-mcenter'>
|
<div class='box-mcenter'>
|
||||||
<h3>
|
<h3>
|
||||||
<span class='red'>"."Can't solve ticket"."
|
<span class='red'>" . "Can't solve ticket" . "
|
||||||
<br>
|
<br>
|
||||||
</span>
|
</span>
|
||||||
</h3>
|
</h3>
|
||||||
<h3>
|
<h3>
|
||||||
<span >"."Tasks are waiting to be done"."
|
<span >" . "Tasks are waiting to be done" . "
|
||||||
</span>
|
</span>
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
@ -118,83 +120,85 @@ class Showtabitem {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div> ";
|
</div> ";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'Computer':
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Summary of pre_show_item
|
||||||
|
* @param array $params is an array like following
|
||||||
|
* array( 'item', 'options')
|
||||||
|
* where 'item' is the object to show (like 'Ticket', 'TicketTask', ...),
|
||||||
|
* BEWARE that sometimes it can be an array of data and not an object (ex: for solution item)
|
||||||
|
* and 'options' are options like following
|
||||||
|
* if item is a main object like a ticket, change, problem, ... then it contains
|
||||||
|
* array( 'id' )
|
||||||
|
* where 'id' is the id of object that will be shown (same than $param['item']->fields['id'])
|
||||||
|
* or if item contains a sub-object like followup, task, ... then it contains
|
||||||
|
* array( 'parent', 'rand', 'showprivate')
|
||||||
|
* where 'parent' is the main object related to the current item (ex: if 'item' is ITILFollowup then it will be the related Ticket)
|
||||||
|
* and 'rand' contains the random number that will be used to render the item
|
||||||
|
* and 'showprivate' is the right to show private items
|
||||||
|
* Note: you may pass datas to post_show_item using the $param['options'] array
|
||||||
|
*/
|
||||||
|
public static function pre_show_item($params)
|
||||||
|
{
|
||||||
|
if (!is_array($params['item'])) {
|
||||||
|
switch ($params['item']->getType()) {
|
||||||
|
case 'Ticket':
|
||||||
|
//echo 'test' ;
|
||||||
|
break;
|
||||||
|
case 'TicketTask':
|
||||||
|
//echo 'test' ;
|
||||||
|
break;
|
||||||
|
case 'ITILFollowup':
|
||||||
|
//echo 'test' ;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
|
// here we are going to view a Solution
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case 'Computer':
|
/**
|
||||||
break;
|
* Summary of post_show_item
|
||||||
}
|
* @param array $params is an array like following
|
||||||
}
|
* array( 'item', 'options')
|
||||||
|
* where 'item' is the object to show (like 'Ticket', 'TicketTask', ...),
|
||||||
/**
|
* and 'options' are options like following
|
||||||
* Summary of pre_show_item
|
* if item is a main object like a ticket, change, problem, ... then it contains
|
||||||
* @param array $params is an array like following
|
* array( 'id' )
|
||||||
* array( 'item', 'options')
|
* where 'id' is the id of object that will be shown (same than $param['item']->fields['id'])
|
||||||
* where 'item' is the object to show (like 'Ticket', 'TicketTask', ...),
|
* or if item contains a sub-object like followup, task, ... then it contains
|
||||||
* BEWARE that sometimes it can be an array of data and not an object (ex: for solution item)
|
* array( 'parent', 'rand', 'showprivate')
|
||||||
* and 'options' are options like following
|
* where 'parent' is the main object related to the current item (ex: if 'item' is ITILFollowup then it will be the related Ticket)
|
||||||
* if item is a main object like a ticket, change, problem, ... then it contains
|
* and 'rand' contains the random number that will be used to render the item
|
||||||
* array( 'id' )
|
* and 'showprivate' is the right to show private items
|
||||||
* where 'id' is the id of object that will be shown (same than $param['item']->fields['id'])
|
* Note: you may get datas from pre_show_item using the $param['options'] array
|
||||||
* or if item contains a sub-object like followup, task, ... then it contains
|
*/
|
||||||
* array( 'parent', 'rand', 'showprivate')
|
public static function post_show_item($params)
|
||||||
* where 'parent' is the main object related to the current item (ex: if 'item' is ITILFollowup then it will be the related Ticket)
|
{
|
||||||
* and 'rand' contains the random number that will be used to render the item
|
if (!is_array($params['item'])) {
|
||||||
* and 'showprivate' is the right to show private items
|
switch ($params['item']->getType()) {
|
||||||
* Note: you may pass datas to post_show_item using the $param['options'] array
|
case 'Ticket':
|
||||||
*/
|
//echo 'test' ;
|
||||||
static function pre_show_item($params) {
|
break;
|
||||||
if (!is_array($params['item'])) {
|
case 'TicketTask':
|
||||||
switch ($params['item']->getType()) {
|
//echo 'test' ;
|
||||||
case 'Ticket':
|
break;
|
||||||
//echo 'test' ;
|
case 'ITILFollowup':
|
||||||
break;
|
//echo 'test' ;
|
||||||
case 'TicketTask' :
|
break;
|
||||||
//echo 'test' ;
|
}
|
||||||
break;
|
} else {
|
||||||
case 'ITILFollowup' :
|
// here we are going to view a Solution
|
||||||
//echo 'test' ;
|
return;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// here we are going to view a Solution
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Summary of post_show_item
|
|
||||||
* @param array $params is an array like following
|
|
||||||
* array( 'item', 'options')
|
|
||||||
* where 'item' is the object to show (like 'Ticket', 'TicketTask', ...),
|
|
||||||
* and 'options' are options like following
|
|
||||||
* if item is a main object like a ticket, change, problem, ... then it contains
|
|
||||||
* array( 'id' )
|
|
||||||
* where 'id' is the id of object that will be shown (same than $param['item']->fields['id'])
|
|
||||||
* or if item contains a sub-object like followup, task, ... then it contains
|
|
||||||
* array( 'parent', 'rand', 'showprivate')
|
|
||||||
* where 'parent' is the main object related to the current item (ex: if 'item' is ITILFollowup then it will be the related Ticket)
|
|
||||||
* and 'rand' contains the random number that will be used to render the item
|
|
||||||
* 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) {
|
|
||||||
if (!is_array($params['item'])) {
|
|
||||||
switch ($params['item']->getType()) {
|
|
||||||
case 'Ticket':
|
|
||||||
//echo 'test' ;
|
|
||||||
break;
|
|
||||||
case 'TicketTask' :
|
|
||||||
//echo 'test' ;
|
|
||||||
break;
|
|
||||||
case 'ITILFollowup' :
|
|
||||||
//echo 'test' ;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// here we are going to view a Solution
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
2
stat.php
2
stat.php
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
// Entry menu case
|
// Entry menu case
|
||||||
define('GLPI_ROOT', '../..');
|
define('GLPI_ROOT', '../..');
|
||||||
include (GLPI_ROOT . "/inc/includes.php");
|
include(GLPI_ROOT . "/inc/includes.php");
|
||||||
|
|
||||||
Session::checkRight(Config::$rightname, UPDATE);
|
Session::checkRight(Config::$rightname, UPDATE);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user