Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .twig_cs.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

declare(strict_types=1);

use FriendsOfTwig\Twigcs;
use FriendsOfTwig\Twigcs\Finder\TemplateFinder;
use FriendsOfTwig\Twigcs\Config\Config;
use Glpi\Tools\GlpiTwigRuleset;

$finder = Twigcs\Finder\TemplateFinder::create()
$finder = TemplateFinder::create()
->in(__DIR__ . '/templates')
->name('*.html.twig')
->ignoreVCSIgnored(true);

return Twigcs\Config\Config::create()
return Config::create()
->setFinder($finder)
->setRuleSet(\Glpi\Tools\GlpiTwigRuleset::class)
->setRuleSet(GlpiTwigRuleset::class)
;
11 changes: 6 additions & 5 deletions ajax/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
Session::checkLoginUser();
use Glpi\Exception\Http\AccessDeniedHttpException;
use Glpi\Exception\Http\NotFoundHttpException;

Session::checkLoginUser();

if (isset($_GET['action']) && $_GET['action'] === 'get_fields_html') {

$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $_GET['id']);
if ($right < READ) {
throw new \Glpi\Exception\Http\AccessDeniedHttpException();
throw new AccessDeniedHttpException();
}

$containers_id = $_GET['id'];
Expand All @@ -49,7 +50,7 @@
$dbu = new DbUtils();
$item = $dbu->getItemForItemtype($itemtype);
if ($items_id > 0 && !$item->getFromDB($items_id)) {
throw new \Glpi\Exception\Http\NotFoundHttpException();
throw new NotFoundHttpException();
}
$item->input = $input;

Expand All @@ -65,5 +66,5 @@
echo '';
}
} else {
throw new \Glpi\Exception\Http\NotFoundHttpException();
throw new NotFoundHttpException();
}
4 changes: 1 addition & 3 deletions ajax/container_display_condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
* @link https://github.com/pluginsGLPI/fields
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
Session::checkLoginUser();

if (isset($_GET['action'])) {
Expand All @@ -55,5 +53,5 @@
}
}
} else {
throw new \RuntimeException('Invalid request', 400);
throw new RuntimeException('Invalid request', 400);
}
1 change: 0 additions & 1 deletion ajax/container_itemtypes_dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
Session::checkLoginUser();

PluginFieldsContainer::showFormItemtype($_REQUEST);
1 change: 0 additions & 1 deletion ajax/container_subtype_dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
Session::checkLoginUser();

PluginFieldsContainer::showFormSubtype($_REQUEST, true);
9 changes: 3 additions & 6 deletions ajax/field_specific_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
header('Content-Type: text/html; charset=UTF-8');
Html::header_nocache();
Session::checkLoginUser();
Expand Down Expand Up @@ -66,11 +65,9 @@
echo implode(
', ',
array_map(
function ($itemtype) {
return is_a($itemtype, CommonDBTM::class, true)
? $itemtype::getTypeName(Session::getPluralNumber())
: $itemtype;
},
fn($itemtype) => is_a($itemtype, CommonDBTM::class, true)
? $itemtype::getTypeName(Session::getPluralNumber())
: $itemtype,
$allowed_itemtypes,
),
);
Expand Down
11 changes: 6 additions & 5 deletions ajax/reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
use Glpi\DBAL\QueryExpression;

Session::checkLoginUser();

if (
Expand All @@ -37,7 +38,7 @@
|| !array_key_exists('new_order', $_POST)
) {
// Missing input
throw new \RuntimeException('Missing input', 400);
throw new RuntimeException('Missing input', 400);
}

$table = PluginFieldsField::getTable();
Expand All @@ -62,7 +63,7 @@

if (0 === $field_iterator->count()) {
// Unknown field
throw new \RuntimeException('Unknown field', 404);
throw new RuntimeException('Unknown field', 404);
}

$field_id = $field_iterator->current()['id'];
Expand All @@ -72,7 +73,7 @@
$DB->update(
$table,
[
'ranking' => new \Glpi\DBAL\QueryExpression($DB->quoteName('ranking') . ' - 1'),
'ranking' => new QueryExpression($DB->quoteName('ranking') . ' - 1'),
],
[
'plugin_fields_containers_id' => $container_id,
Expand All @@ -84,7 +85,7 @@
$DB->update(
$table,
[
'ranking' => new \Glpi\DBAL\QueryExpression($DB->quoteName('ranking') . ' + 1'),
'ranking' => new QueryExpression($DB->quoteName('ranking') . ' + 1'),
],
[
'plugin_fields_containers_id' => $container_id,
Expand Down
3 changes: 1 addition & 2 deletions ajax/status_override.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
Session::checkLoginUser();

if (isset($_GET['action'])) {
Expand All @@ -43,5 +42,5 @@
$status_override->showForm($_GET['id'], $_GET);
}
} else {
throw new \RuntimeException('Invalid request', 400);
throw new RuntimeException('Invalid request', 400);
}
9 changes: 2 additions & 7 deletions ajax/viewtranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,17 @@
* @brief
*/

include('../../../inc/includes.php');
header('Content-Type: text/html; charset=UTF-8');
Html::header_nocache();

Session::checkLoginUser();

if (!isset($_POST['itemtype']) || !isset($_POST['items_id']) || !isset($_POST['id'])) {
throw new \RuntimeException('Missing required parameters', 400);
throw new RuntimeException('Missing required parameters', 400);
}

$translation = new PluginFieldsLabelTranslation();
if ($_POST['id'] == -1) {
$canedit = $translation->can(-1, CREATE, $_POST);
} else {
$canedit = $translation->can($_POST['id'], UPDATE);
}
$canedit = $_POST['id'] == -1 ? $translation->can(-1, CREATE, $_POST) : $translation->can($_POST['id'], UPDATE);
if ($canedit) {
$translation->showFormForItem($_POST['itemtype'], $_POST['items_id'], $_POST['id']);
} else {
Expand Down
1 change: 0 additions & 1 deletion front/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
Session::checkLoginUser();

Html::header(
Expand Down
1 change: 0 additions & 1 deletion front/containerdisplaycondition.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
Session::checkRight('config', READ);

$status_override = new PluginFieldsContainerDisplayCondition();
Expand Down
3 changes: 1 addition & 2 deletions front/export_to_yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
include('../hook.php');
include(__DIR__ . '/../hook.php');

Session::checkRight('config', READ);

Expand Down
1 change: 0 additions & 1 deletion front/field.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');

if (empty($_GET['id'])) {
$_GET['id'] = '';
Expand Down
1 change: 0 additions & 1 deletion front/labeltranslation.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
Session::checkRight('config', UPDATE);

$translation = new PluginFieldsLabelTranslation();
Expand Down
1 change: 0 additions & 1 deletion front/profile.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
Session::checkRight('config', UPDATE);

if (isset($_POST['update'])) {
Expand Down
3 changes: 1 addition & 2 deletions front/regenerate_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
include('../hook.php');
include(__DIR__ . '/../hook.php');

Session::checkRight('config', READ);

Expand Down
1 change: 0 additions & 1 deletion front/statusoverride.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
Session::checkRight('config', READ);

$status_override = new PluginFieldsStatusOverride();
Expand Down
8 changes: 4 additions & 4 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ function plugin_fields_giveItem($itemtype, $ID, $data, $num)

//fix glpi default Search::giveItem who for empty date display "--"
if (
strpos($table, 'glpi_plugin_fields') !== false
str_contains($table, 'glpi_plugin_fields')
&& isset($searchopt[$ID]['datatype'])
&& strpos($searchopt[$ID]['datatype'], 'date') !== false
&& str_contains($searchopt[$ID]['datatype'], 'date')
&& empty($data['raw']["ITEM_$num"])
) {
return ' ';
Expand Down Expand Up @@ -349,7 +349,7 @@ function plugin_datainjection_populate_fields()

function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype)
{
/** @var \DBmysql $DB */
/** @var DBmysql $DB */
global $DB;

$searchopt = &Search::getOptions($itemtype);
Expand All @@ -373,7 +373,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype)
if ($searchtype == 'equals' || $searchtype == 'notequals') {
$operator = ($searchtype == 'equals') ? '=' : '!=';
if ($nott) {
$link = $link . ' NOT ';
$link .= ' NOT ';
}
return $link . 'CAST(' . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' AS DECIMAL(10,7))' . $operator . ' ' . $DB->quoteValue($val) ;
} else {
Expand Down
4 changes: 2 additions & 2 deletions inc/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function __construct($options = null)

public function setOptions($options)
{
if (!is_array($options) && !($options instanceof \Traversable)) {
throw new \InvalidArgumentException();
if (!is_array($options) && !($options instanceof Traversable)) {
throw new InvalidArgumentException();
}

foreach ($options as $path) {
Expand Down
Loading