(.+)#', $value, $results)) {
- $value = str_replace($results[0][0], '', $value);
+ if (!isset($params['subtype'])) {
+ $params['subtype'] = null;
}
- }
- if (!isset($params['subtype'])) {
- $params['subtype'] = null;
+ $out .= Dropdown::showFromArray(
+ 'subtype',
+ $tabs,
+ ['value' => $params['subtype'],
+ 'width' => '100%',
+ 'display' => false,
+ ],
+ );
+ $out .= "";
}
-
- $out .= Dropdown::showFromArray(
- 'subtype',
- $tabs,
- ['value' => $params['subtype'],
- 'width' => '100%',
- 'display' => false,
- ],
- );
- $out .= "";
}
}
}
@@ -1160,7 +1171,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
if (!$item->isEntityAssign() || in_array($item->fields['entities_id'], $entities)) {
$display_condition = new PluginFieldsContainerDisplayCondition();
if ($display_condition->computeDisplayContainer($item, $data['id'])) {
- $tabs_entries[$tab_name] = $data['label'];
+ $tabs_entries[$tab_name] = self::createTabEntry($data['label'], 0, null, PluginFieldsContainer::getIcon());
}
}
}
@@ -1182,7 +1193,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
//retrieve container for current tab
$container = new self();
- $found_c = $container->find(['type' => 'tab', 'name' => Sanitizer::sanitize($tabnum), 'is_active' => 1]);
+ $found_c = $container->find(['type' => 'tab', 'name' => $tabnum, 'is_active' => 1]);
foreach ($found_c as $data) {
$dataitemtypes = json_decode($data['itemtypes']);
if (in_array(get_class($item), $dataitemtypes) != false) {
@@ -1238,7 +1249,8 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false)
$items_id = $data['items_id'];
$classname = self::getClassname($itemtype, $container_obj->fields['name']);
- $obj = new $classname();
+ $dbu = new DbUtils();
+ $obj = $dbu->getItemForItemtype($classname);
if ($obj->getFromDBByCrit(['items_id' => $items_id]) === false) {
// add fields data
$obj->add($data);
@@ -1312,7 +1324,8 @@ public static function constructHistory(
$field_obj
) {
// Don't log few itemtypes
- $obj = new $itemtype();
+ $dbu = new DbUtils();
+ $obj = $dbu->getItemForItemtype($itemtype);
if ($obj->dohistory == false) {
return;
}
@@ -1464,7 +1477,8 @@ public static function validateValues($data, $itemtype, $massiveaction)
if ($container->fields['type'] === 'dom') {
$status_value = $data[$status_field_name] ?? null;
} else {
- $relatedItem = new $itemtype();
+ $dbu = new DbUtils();
+ $relatedItem = $dbu->getItemForItemtype($itemtype);
$status_value = $relatedItem->fields[$status_field_name] ?? null;
}
// Apply status overrides
@@ -1886,7 +1900,7 @@ public static function getAddSearchOptions($itemtype, $containers_id = false)
'glpi_plugin_fields_containers.label AS container_label',
(
Session::isCron()
- ? new QueryExpression(sprintf('%s AS %s', READ + CREATE, $DB->quoteName('right')))
+ ? new \Glpi\DBAL\QueryExpression(sprintf('%s AS %s', READ + CREATE, $DB->quoteName('right')))
: 'glpi_plugin_fields_profiles.right'
),
],
@@ -2132,7 +2146,7 @@ public function prepareInputForClone($input)
if (array_key_exists('itemtypes', $input) && !empty($input['itemtypes'])) {
// $input has been transformed with `Toolbox::addslashes_deep()`, and `self::prepareInputForAdd()`
// is expecting an array, so it have to be unslashed then json decoded.
- $input['itemtypes'] = json_decode(Sanitizer::dbUnescape($input['itemtypes']));
+ $input['itemtypes'] = json_decode($input['itemtypes']);
} else {
unset($input['itemtypes']);
}
diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php
index bd108987..f0435da6 100644
--- a/inc/containerdisplaycondition.class.php
+++ b/inc/containerdisplaycondition.class.php
@@ -77,7 +77,9 @@ public static function installBaseData(Migration $migration, $version)
PRIMARY KEY (`id`),
KEY `plugin_fields_containers_id_itemtype` (`plugin_fields_containers_id`, `itemtype`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
- $DB->doQuery($query) or die($DB->error());
+ if (!$DB->doQuery($query)) {
+ throw new \RuntimeException('Error creating plugin_fields_containers_displayconditions table: ' . $DB->error());
+ }
}
return true;
@@ -163,6 +165,8 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
return self::createTabEntry(
self::getTypeName(Session::getPluralNumber()),
countElementsInTable(self::getTable(), ['plugin_fields_containers_id' => $item->getID()]),
+ null,
+ 'ti ti-eye-off',
);
}
@@ -232,6 +236,9 @@ public static function getFieldName($so_id, $itemtype)
public static function showItemtypeFieldForm($itemtype)
{
+ /** @var array $CFG_GLPI */
+ global $CFG_GLPI;
+
$rand = mt_rand();
$out = '';
$out .= Dropdown::showFromArray('search_option', self::removeBlackListedOption(Search::getOptions($itemtype), $itemtype), ['display_emptychoice' => true, 'display' => false, 'rand' => $rand]);
@@ -239,7 +246,7 @@ public static function showItemtypeFieldForm($itemtype)
$out .= Ajax::updateItemOnSelectEvent(
'dropdown_search_option' . $rand,
'results_condition',
- Plugin::getWebDir('fields') . '/ajax/container_display_condition.php',
+ $CFG_GLPI['root_doc'] . '/plugins/fields/ajax/container_display_condition.php',
[
'search_option_id' => '__VALUE__',
'itemtype' => $itemtype,
@@ -292,7 +299,8 @@ public static function showSearchOptionCondition($searchoption_id, $itemtype, ?s
case 'impact':
case 'urgency':
case 'priority':
- $twig_params['item'] = new $itemtype();
+ $dbu = new DbUtils();
+ $twig_params['item'] = $dbu->getItemForItemtype($itemtype);
$twig_params['itemtype_field'] = $so['field'];
break;
case 'global_validation':
@@ -316,7 +324,8 @@ public static function getRawValue($searchoption_id, $itemtype, $value)
if ($so['datatype'] == 'dropdown' || ($so['datatype'] == 'itemlink' && $so['table'] !== $itemtypetable)) {
$dropdown_itemtype = getItemTypeForTable($so['table']);
- $dropdown = new $dropdown_itemtype();
+ $dbu = new DbUtils();
+ $dropdown = $dbu->getItemForItemtype($dropdown_itemtype);
if ($dropdown->getFromDB($value)) {
$raw_value = $dropdown->fields['name'];
}
@@ -350,7 +359,8 @@ public static function getRawValue($searchoption_id, $itemtype, $value)
public static function removeBlackListedOption($array, $itemtype_class)
{
- $itemtype_object = new $itemtype_class();
+ $dbu = new DbUtils();
+ $itemtype_object = $dbu->getItemForItemtype($itemtype_class);
$allowed_so = [];
//remove "Common"
@@ -457,7 +467,6 @@ public function checkCondition($item)
case self::SHOW_CONDITION_REGEX:
//'regex';
if (self::checkRegex($value)) {
- $value = Sanitizer::unsanitize($value);
if (preg_match_all($value . 'i', $fields[$searchOption['linkfield']]) > 0) {
return false;
}
diff --git a/inc/field.class.php b/inc/field.class.php
index 4f3a4d92..e1646c93 100644
--- a/inc/field.class.php
+++ b/inc/field.class.php
@@ -92,24 +92,26 @@ public static function installBaseData(Migration $migration, $version)
KEY `is_active` (`is_active`),
KEY `is_readonly` (`is_readonly`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
- $DB->doQuery($query) or die($DB->error());
+ if (!$DB->doQuery($query)) {
+ throw new \RuntimeException('Error creating plugin_fields_fields table: ' . $DB->error());
+ }
}
$migration->displayMessage("Updating $table");
if (!$DB->fieldExists($table, 'is_active')) {
- $migration->addField($table, 'is_active', 'bool', ['value' => 1]);
+ $migration->addField($table, 'is_active', 'bool', ['value' => '1']);
$migration->addKey($table, 'is_active', 'is_active');
}
if (!$DB->fieldExists($table, 'is_readonly')) {
- $migration->addField($table, 'is_readonly', 'bool', ['default' => false]);
+ $migration->addField($table, 'is_readonly', 'bool', ['default' => 'false']);
$migration->addKey($table, 'is_readonly', 'is_readonly');
}
if (!$DB->fieldExists($table, 'mandatory')) {
- $migration->addField($table, 'mandatory', 'bool', ['value' => 0]);
+ $migration->addField($table, 'mandatory', 'bool', ['value' => '0']);
}
if (!$DB->fieldExists($table, 'multiple')) {
- $migration->addField($table, 'multiple', 'bool', ['value' => 0]);
+ $migration->addField($table, 'multiple', 'bool', ['value' => '0']);
}
//increase the size of column 'type' (25 to 255)
@@ -313,7 +315,7 @@ public function prepareInputForAdd($input)
}
if (isset($input['allowed_values'])) {
- $input['allowed_values'] = Sanitizer::dbEscape(json_encode($input['allowed_values']));
+ $input['allowed_values'] = json_encode($input['allowed_values']);
}
return $input;
@@ -431,7 +433,7 @@ public function post_purgeItem()
$DB->update(
$table,
[
- 'ranking' => new QueryExpression($DB->quoteName('ranking') . ' - 1'),
+ 'ranking' => new \Glpi\DBAL\QueryExpression($DB->quoteName('ranking') . ' - 1'),
],
[
'plugin_fields_containers_id' => $old_container,
@@ -510,7 +512,7 @@ public function getNextRanking()
global $DB;
$iterator = $DB->request([
- 'SELECT' => new \QueryExpression(
+ 'SELECT' => new \Glpi\DBAL\QueryExpression(
'max(' . $DB->quoteName('ranking') . ') AS ' . $DB->quoteName('rank'),
),
'FROM' => self::getTable(),
@@ -547,6 +549,8 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
self::getTable(),
['plugin_fields_containers_id' => $item->getID()],
),
+ null,
+ 'ti ti-forms',
);
}
@@ -636,7 +640,7 @@ public function showSummary($container)
echo '';
$label = !empty($this->fields['label']) ? $this->fields['label'] : NOT_AVAILABLE;
- echo "getID()}'>{$label}";
+ echo "getID()}'>{$label}";
echo ' | ';
echo '' . $fields_type[$this->fields['type']] . ' | ';
echo '' ;
@@ -815,6 +819,9 @@ public function showForm($ID, $options = [])
public static function showForTabContainer($c_id, $item)
{
+ /** @var array $CFG_GLPI */
+ global $CFG_GLPI;
+
//profile restriction
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id);
if ($right < READ) {
@@ -825,7 +832,7 @@ public static function showForTabContainer($c_id, $item)
//get fields for this container
$field_obj = new self();
$fields = $field_obj->find(['plugin_fields_containers_id' => $c_id, 'is_active' => 1], 'ranking');
- echo " |