FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix(Core): item validation when loading trees · pluginsGLPI/treeview@e17b02f · GitHub

Repository navigation

Commit e17b02f

Browse files
committed
Fix(Core): item validation when loading trees
1 parent b2b679a commit e17b02f

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎front/config.form.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
$config = new PluginTreeviewConfig();
3434
if (isset($_POST['update'])) {
35+
if (isset($_POST['target']) && !in_array($_POST['target'], ['_blank', 'right'], true)) {
36+
unset($_POST['target']);
37+
}
3538
$config->update($_POST);
3639
Html::back();
3740
} elseif (Plugin::isPluginActive('treeview')) {

‎front/preference.form.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
//Save user preferences
3636
if (isset($_POST['plugin_treeview_user_preferences_save'])) {
37-
$pref->update($_POST);
37+
if (!($own_id = $pref->checkIfPreferenceExists(Session::getLoginUserID()))) {
38+
$own_id = $pref->addDefaultPreference(Session::getLoginUserID());
39+
}
40+
$pref->update(['id' => $own_id, 'show_on_load' => (int) ($_POST['show_on_load'] ?? 0)]);
3841
Html::back();
3942
}

‎inc/config.class.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function getNodesFromDb()
239239
$closeSameLevel = $this->fields['closeSameLevel'];
240240

241241
// Load the settings in JavaSript so that dTree script can apply them
242-
echo "d.config.target = '" . $target . "';\n";
242+
echo "d.config.target = " . json_encode($target) . ";\n";
243243
echo 'd.config.folderLinks = ' . $folderLinks . ";\n";
244244
echo 'd.config.useSelection = ' . $useSelection . ";\n";
245245
echo 'd.config.useLines = ' . $useLines . ";\n";
@@ -267,7 +267,7 @@ public function getNodesFromDb()
267267
// Is this the first time we load the page?
268268
if (isset($_GET['nodes']) && $_GET['nodes'] != '') {
269269
// If no then get all the nodes requested by the client
270-
$nodes = array_reverse(explode('.', $_GET['nodes']));
270+
$nodes = array_map('intval', array_reverse(explode('.', $_GET['nodes'])));
271271
} else {
272272
// If yes then get only the root node
273273
$nodes[0] = 0;
@@ -319,7 +319,7 @@ public function getNodesFromDb()
319319
", true, -1,'');\n";
320320
$dontLoad = 'true';
321321
// Then add aloso its items
322-
foreach (self::$types as $type) {
322+
foreach (self::getTypes() as $type) {
323323

324324
if (!class_exists($type) || !is_a($type, CommonDBTM::class, true)) {
325325
continue;
@@ -344,7 +344,7 @@ public function getNodesFromDb()
344344
$criteria['WHERE']['is_deleted'] = 0;
345345
}
346346

347-
if ($this->isEntityAssign()) {
347+
if ($item->isEntityAssign()) {
348348
$criteria['WHERE']['entities_id'] = $_SESSION['glpiactive_entity'];
349349
}
350350

@@ -451,9 +451,9 @@ public function getNodesFromDb()
451451

452452
// Open the tree to the desired node
453453
if ($openedType != -1) {
454-
echo 'd.openTo(' . htmlspecialchars((string) $openedType) . ");\n";
454+
echo 'd.openTo(' . (int) $openedType . ");\n";
455455
} else {
456-
echo 'd.openTo(' . $nodes[count($nodes) - 1] . ");\n";
456+
echo 'd.openTo(' . (int) $nodes[count($nodes) - 1] . ");\n";
457457
}
458458
}
459459

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL