Skip to content

Commit

Permalink
Added a filter to be sure that $type is an array
Browse files Browse the repository at this point in the history
Deleted extra code that was not relevant in impact plugin context
Added a filter to prevent instanciation of an unknown class
Added new pics: Group, Supplier, KnowbaseItem, PluginDatabasesDatabase
Set version to 1.3.2
fixes #7 #7
  • Loading branch information
tomolimo committed Aug 9, 2019
1 parent 89c451e commit 6fa605d
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 68 deletions.
21 changes: 9 additions & 12 deletions front/impact.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,20 @@
Session::checkLoginUser();

if (isset($_POST['add'])
&& isset($_POST['itemtype_1']) && isset($_POST['items_id_1'])
&& isset($_POST['itemtype_2']) && isset($_POST['items_id_2'])) {

&& isset($_POST['itemtype_1']) && isset($_POST['items_id_1']) && $_POST['items_id_1'] > 0
&& isset($_POST['itemtype_2']) && isset($_POST['items_id_2']) && $_POST['items_id_2'] > 0
&& class_exists($_POST['itemtype_1'])) {

$item = new $_POST['itemtype_1'];
$item->check(-1, UPDATE, $_POST);

$item = new PluginImpactsImpact;
if (isset($_POST['add'])) {

if ($item->add($_POST)) {
Glpi\Event::log($_POST["items_id_1"], $_POST["itemtype_1"], 4, "inventory",
//TRANS: %s is the user login
sprintf(__('%s adds an impact with %s (%s)'), $_SESSION["glpiname"], $_POST["itemtype_2"]::getTypeName(1), $_POST["items_id_2"]));
}
Html::back();
if ($item->add($_POST)) {
Glpi\Event::log($_POST["items_id_1"], $_POST["itemtype_1"], 4, "inventory",
//TRANS: %s is the user login
sprintf(__('%s adds an impact with %s (%s)'), $_SESSION["glpiname"], $_POST["itemtype_2"]::getTypeName(1), $_POST["items_id_2"]));
}

Html::back();
}

Html::displayErrorAndDie("lost");
2 changes: 1 addition & 1 deletion impacts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<compatibility>9.3</compatibility>
</version>
<version>
<num>1.3.1</num>
<num>1.3.2</num>
<compatibility>9.4</compatibility>
<compatibility>9.3</compatibility>
</version>
Expand Down
6 changes: 3 additions & 3 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
static function getAssetList($completelist = false) {
global $CFG_GLPI;

$regex = '/types/m';
$regex = '/types$/m';
$listTemp = [];
foreach ($CFG_GLPI as $k => $type) {
if (preg_match_all($regex, $k, $matches, PREG_SET_ORDER, 0)) {
if (is_array($type) && preg_match_all($regex, $k, $matches, PREG_SET_ORDER, 0)) {
foreach ($type as $val) {
if (strcmp($val, '*')) {
array_push($listTemp, $val);
Expand All @@ -151,7 +151,7 @@ static function getAssetList($completelist = false) {
$list = $config->fields['assets'];
}
$ret = [];
foreach ($list as $lo) {
foreach ($list as $lo) {
if (class_exists($lo)) {
$ret[$lo] = $lo::getTypeName(Session::getPluralNumber())." ($lo)";
}
Expand Down
105 changes: 54 additions & 51 deletions inc/impact.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,29 +324,41 @@ static function showOppositeListForItem(CommonGLPI $item, $direction, $title, $o
$itemtypes[$rec[$itemtype_active]] = $rec[$itemtype_active];
}

$query = "";
$query = [];
$subQueries = [];
foreach ($itemtypes as $itemtype) {
if ($query != '') {
$query .= "\nUNION\n";
}

$query .= "SELECT rel.id as assocID, rel.date_creation, rel.$itemtype_active as itemtype, rel.$items_id_active as items_id, it.`name`
FROM ".self::getTable()." AS rel
JOIN `".$itemtype::getTable()."` AS it ON rel.`$itemtype_active`='$itemtype' AND rel.`$items_id_active`=it.`id`
WHERE rel.$itemtype_passive = '". $item::getType()."' AND rel.$items_id_passive = ".$item->fields['id'];
$subQueries[] = [
'SELECT' => ["rel.id AS assocID", "rel.date_creation", "rel.$itemtype_active AS itemtype", "rel.$items_id_active AS items_id", "it.name"],
'FROM' => self::getTable()." AS rel",
'INNER JOIN' => [$itemtype::getTable()." AS it" => [
'FKEY' => [
'rel' => $items_id_active,
'it' => 'id',
['AND' => [
"rel.$itemtype_active" => $itemtype
]
]
]
]
],
'WHERE' => [
'AND' => [
"rel.$itemtype_passive" => $item::getType(),
"rel.$items_id_passive" => $item->fields['id']
]
]
];
}

if ($query != '') {
$query = "SELECT * FROM (\n$query\n) AS elts\nORDER BY $sort $order";
if(count($subQueries) > 1) {
$query = new QueryUnion($subQueries, true);
} elseif(count($subQueries) == 1) {
$query = $subQueries[0];
}

$number = 0; // by default
if ($query != '') {
if(!empty($query)) {
$result = $DB->request($query);

$number = count($result);

}

$impacts = [];
Expand Down Expand Up @@ -492,44 +504,35 @@ static function dropdownAllDevices($myname, $itemtype, $items_id = 0, $admin = 0

$rand = $params['rand'];

if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] == 0) {
echo Html::hidden($myname, ['value' => '']);
echo Html::hidden($params['myname'], ['value' => 0]);
echo "<div id='relation_all_devices$rand'>";
$types = PluginImpactsConfig::getAssetList();
$emptylabel = Dropdown::EMPTY_VALUE;
Dropdown::showItemTypes($myname, array_keys($types), [
'emptylabel' => $emptylabel,
'value' => $itemtype,
'rand' => $rand,
'display_emptychoice' => true
]);

} else {
echo "<div id='relation_all_devices$rand'>";
if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"]&pow(2,
Ticket::HELPDESK_ALL_HARDWARE)) {
$types = PluginImpactsConfig::getAssetList();
$emptylabel = Dropdown::EMPTY_VALUE;
Dropdown::showItemTypes($myname, array_keys($types), [
'emptylabel' => $emptylabel,
'value' => $itemtype,
'rand' => $rand,
'display_emptychoice' => true
]);
//$found_type = isset($types[$itemtype]);

Ajax::updateItemOnSelectEvent(
"dropdown_$myname$rand",
"results_$myname$rand",
$CFG_GLPI["root_doc"]."/ajax/dropdownAllItems.php",
[
'idtable' => '__VALUE__',
'name' => $params['myname'],
'rand' => $rand,
'used' => $params['used'],
'admin' => $admin,
'multiple' => $params['multiple'],
'entity_restrict' => $entity_restrict,
]
);
echo "<span id='results_$myname$rand'>\n";
Ajax::updateItemOnSelectEvent(
"dropdown_$myname$rand",
"results_$myname$rand",
$CFG_GLPI["root_doc"]."/ajax/dropdownAllItems.php",
[
'idtable' => '__VALUE__',
'name' => $params['myname'],
'rand' => $rand,
'used' => $params['used'],
'admin' => $admin,
'multiple' => $params['multiple'],
'entity_restrict' => $entity_restrict,
]
);
echo "<span id='results_$myname$rand'>\n";

echo "</span>\n";
echo "</div>";

echo "</span>\n";
}
echo "</div>";
}
return $rand;
}

Expand Down
Binary file added pics/Group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pics/KnowbaseItem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pics/PluginDatabasesDatabase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pics/Supplier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// ----------------------------------------------------------------------


define('IMPACTS_VERSION', '1.3.1');
define('IMPACTS_VERSION', '1.3.2');

// Minimal GLPI version, inclusive
define("IMPACTS_MIN_GLPI", "9.3");
Expand Down

0 comments on commit 6fa605d

Please sign in to comment.