Passed
Branch development (e0e718)
by Nils
04:45
created

tree.php ➔ recursiveTree()   F

Complexity

Conditions 44
Paths > 20000

Size

Total Lines 198
Code Lines 131

Duplication

Lines 15
Ratio 7.58 %

Importance

Changes 0
Metric Value
cc 44
eloc 131
nc 24966
nop 1
dl 15
loc 198
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 124 and the first side effect is on line 15.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @file          tree.php
4
 * @author        Nils Laumaillé
5
 * @version       2.1.27
6
 * @copyright     (c) 2009-2017 Nils Laumaillé
7
 * @licensing     GNU GPL-3.0
8
 * @link          http://www.teampass.net
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
require_once 'SecureHandler.php';
16
session_start();
17
if (!isset($_SESSION['CPM']) || $_SESSION['CPM'] != 1 || !isset($_SESSION['key']) || empty($_SESSION['key'])) {
18
    die('Hacking attempt...');
19
}
20
21
// Load config
22
if (file_exists('../includes/config/tp.config.php')) {
23
    require_once '../includes/config/tp.config.php';
24
} elseif (file_exists('./includes/config/tp.config.php')) {
25
    require_once './includes/config/tp.config.php';
26
} else {
27
    throw new Exception("Error file '/includes/config/tp.config.php' not exists", 1);
28
}
29
30
// includes
31
require_once $SETTINGS['cpassman_dir'].'/includes/config/include.php';
32
require_once $SETTINGS['cpassman_dir'].'/sources/SplClassLoader.php';
33
require_once $SETTINGS['cpassman_dir'].'/sources/main.functions.php';
34
require_once $SETTINGS['cpassman_dir'].'/includes/language/'.$_SESSION['user_language'].'.php';
35
include $SETTINGS['cpassman_dir'].'/includes/config/settings.php';
36
37
// header
38
header("Content-type: text/html; charset=utf-8");
39
header("Cache-Control: no-cache, must-revalidate");
40
41
// Define Timezone
42
if (isset($SETTINGS['timezone'])) {
43
    date_default_timezone_set($SETTINGS['timezone']);
44
} else {
45
    date_default_timezone_set('UTC');
46
}
47
48
// Connect to mysql server
49
require_once $SETTINGS['cpassman_dir'].'/includes/libraries/Database/Meekrodb/db.class.php';
50
$pass = defuse_return_decrypted($pass);
51
DB::$host = $server;
52
DB::$user = $user;
53
DB::$password = $pass;
54
DB::$dbName = $database;
55
DB::$port = $port;
56
DB::$encoding = $encoding;
57
DB::$error_handler = true;
58
$link = mysqli_connect($server, $user, $pass, $database, $port);
59
$link->set_charset($encoding);
60
61
//Build tree
62
$tree = new SplClassLoader('Tree\NestedTree', $SETTINGS['cpassman_dir'].'/includes/libraries');
63
$tree->register();
64
$tree = new Tree\NestedTree\NestedTree($pre.'nested_tree', 'id', 'parent_id', 'title');
65
$folders = $tree->getDescendants();
66
67
// define temporary sessions
68
if ($_SESSION['user_admin'] == 1
0 ignored issues
show
introduced by
Consider adding parentheses for clarity. Current Interpretation: {currentAssign}, Probably Intended Meaning: {alternativeAssign}
Loading history...
69
    && (isset($SETTINGS_EXT['admin_full_right']) === true && $SETTINGS_EXT['admin_full_right'] === '1')
70
    || isset($SETTINGS_EXT['admin_full_right']) === false
71
) {
72
    $_SESSION['groupes_visibles'] = $_SESSION['personal_visible_groups'];
73
    $_SESSION['groupes_visibles_list'] = implode(',', $_SESSION['groupes_visibles']);
74
}
75
// prepare some variables
76
if (isset($_COOKIE['jstree_select']) === true
77
    && empty($_COOKIE['jstree_select']) === false
78
) {
79
    $firstGroup = str_replace("#li_", "", $_COOKIE['jstree_select']);
80
} else {
81
    $firstGroup = "";
82
}
83
if (isset($_SESSION['list_folders_limited']) === true
84
    && count($_SESSION['list_folders_limited']) > 0
85
) {
86
    $listFoldersLimitedKeys = @array_keys($_SESSION['list_folders_limited']);
87
} else {
88
    $listFoldersLimitedKeys = array();
89
}
90
// list of items accessible but not in an allowed folder
91
if (isset($_SESSION['list_restricted_folders_for_items']) === true
92
    && count($_SESSION['list_restricted_folders_for_items']) > 0) {
93
    $listRestrictedFoldersForItemsKeys = @array_keys($_SESSION['list_restricted_folders_for_items']);
94
} else {
95
    $listRestrictedFoldersForItemsKeys = array();
96
}
97
98
$ret_json = $last_visible_parent = '';
99
$parent = "#";
100
$last_visible_parent_level = 1;
101
102
// build the tree to be displayed
103
if (isset($_GET['id']) === true
104
    && is_numeric(intval($_GET['id'])) === true
105
    && isset($_SESSION['user_settings']['treeloadstrategy']) === true
106
    && $_SESSION['user_settings']['treeloadstrategy'] === "sequential"
107
) {
108
    buildNodeTree($_GET['id']);
109
} elseif (isset($_SESSION['user_settings']['treeloadstrategy']) === true
110
    && $_SESSION['user_settings']['treeloadstrategy'] === "sequential"
111
) {
112
    buildNodeTree(0);
113
} else {
114
    $completTree = $tree->getTreeWithChildren();
115
    foreach ($completTree[0]->children as $child) {
116
        recursiveTree($child);
117
    }
118
}
119
echo '['.$ret_json.']';
120
121
/*
122
* Get through asked folders
123
*/
124
function buildNodeTree($nodeId)
125
{
126
    global $ret_json, $listFoldersLimitedKeys, $listRestrictedFoldersForItemsKeys, $tree, $LANG, $SETTINGS;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
127
128
    // Load library
129
    require_once $SETTINGS['cpassman_dir'].'/includes/libraries/protect/SuperGlobal/SuperGlobal.php';
130
    $superGlobal = new protect\SuperGlobal\SuperGlobal();
131
132
    // Prepare superGlobal variables
133
    $session_forbiden_pfs =                         $superGlobal->get("forbiden_pfs", "SESSION");
134
    $session_groupes_visibles =                     $superGlobal->get("groupes_visibles", "SESSION");
135
    $session_list_restricted_folders_for_items =    $superGlobal->get("list_restricted_folders_for_items", "SESSION");
136
    $session_user_id =                              $superGlobal->get("user_id", "SESSION");
137
    $session_login =                                $superGlobal->get("login", "SESSION");
138
    $session_no_access_folders =                    $superGlobal->get("no_access_folders", "SESSION");
139
    $session_list_folders_limited =                 $superGlobal->get("list_folders_limited", "SESSION");
140
    $session_read_only_folders =                    $superGlobal->get("read_only_folders", "SESSION");
141
    $session_personal_folders =                    $superGlobal->get("personal_folders", "SESSION");
142
    $session_personal_visible_groups =                    $superGlobal->get("personal_visible_groups", "SESSION");
143
144
    // Be sure that user can only see folders he/she is allowed to
145
    if (in_array($nodeId, $session_forbiden_pfs) === false
146
        || in_array($nodeId, $session_groupes_visibles) === true
147
        || in_array($nodeId, $listFoldersLimitedKeys) === true
148
        || in_array($nodeId, $listRestrictedFoldersForItemsKeys) === true
149
    ) {
150
        $displayThisNode = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $displayThisNode is dead and can be removed.
Loading history...
151
        $hide_node = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $hide_node is dead and can be removed.
Loading history...
152
        $nbChildrenItems = 0;
153
154
        // Check if any allowed folder is part of the descendants of this node
155
        $nodeDescendants = $tree->getDescendants($nodeId, false, true, false);
156
        foreach ($nodeDescendants as $node) {
157
            $displayThisNode = false;
158
            if ((in_array($node->id, $session_forbiden_pfs) === false
159
                || in_array($node->id, $session_groupes_visibles) === true
160
                || in_array($node->id, $listFoldersLimitedKeys) === true
161
                || in_array($node->id, $listRestrictedFoldersForItemsKeys)) === true && (
162
                in_array(
163
                    $node->id,
164
                    array_merge($session_groupes_visibles, $session_list_restricted_folders_for_items)
165
                ) === true
166
                || @in_array($node->id, $listFoldersLimitedKeys) === true
167
                || @in_array($node->id, $listRestrictedFoldersForItemsKeys) === true
168
                || in_array($node->id, $session_no_access_folders) === true
169
                )
170
            ) {
171
                $displayThisNode = true;
172
            }
173
174
            if ($displayThisNode === true) {
175
                $hide_node = $show_but_block = false;
176
                $text = "";
177
                $title = "";
178
179
                // get count of Items in this folder
180
                DB::query(
181
                    "SELECT * FROM ".prefix_table("items")."
182
                    WHERE inactif=%i AND id_tree = %i",
183
                    0,
184
                    $node->id
185
                );
186
                $itemsNb = DB::count();
187
188
                // get info about current folder
189
                DB::query(
190
                    "SELECT * FROM ".prefix_table("nested_tree")."
191
                    WHERE parent_id = %i",
192
                    $node->id
193
                );
194
                $childrenNb = DB::count();
195
196
                // If personal Folder, convert id into user name
197
                if ($node->title === $session_user_id && $node->nlevel === '1') {
198
                    $node->title = $session_login;
199
                }
200
201
                // Decode if needed
202
                $node->title = htmlspecialchars_decode($node->title, ENT_QUOTES);
203
204
                // prepare json return for current node
205
                if ($node->parent_id == 0) {
206
                    $parent = "#";
207
                } else {
208
                    $parent = "li_".$node->parent_id;
209
                }
210
211
                // special case for READ-ONLY folder
212
                if ($_SESSION['user_read_only'] === true && !in_array($node->id, $session_personal_folders)) {
213
                    $title = $LANG['read_only_account'];
214
                }
215
                $text .= str_replace("&", "&amp;", $node->title);
216
                $restricted = "0";
217
                $folderClass = "folder";
218
219
                if (in_array($node->id, $session_groupes_visibles)) {
220
                    if (in_array($node->id, $session_read_only_folders)) {
221
                        $text = "<i class='fa fa-eye'></i>&nbsp;".$text;
222
                        $title = $LANG['read_only_account'];
223
                        $restricted = 1;
224
                        $folderClass = "folder_not_droppable";
225
                    } elseif ($_SESSION['user_read_only'] === true && !in_array($node->id, $session_personal_visible_groups)) {
226
                        $text = "<i class='fa fa-eye'></i>&nbsp;".$text;
227
                    }
228
                    $text .= ' (<span class=\'items_count\' id=\'itcount_'.$node->id.'\'>'.$itemsNb.'</span>';
229
                    // display tree counters
230
                    if (isset($SETTINGS['tree_counters']) && $SETTINGS['tree_counters'] == 1) {
231
                        $text .= '|'.$nbChildrenItems.'|'.(count($nodeDescendants) - 1);
232
                    }
233
                    $text .= ')';
234
                } elseif (in_array($node->id, $listFoldersLimitedKeys)) {
235
                    $restricted = "1";
236
                    if ($_SESSION['user_read_only'] === true) {
237
                        $text = "<i class='fa fa-eye'></i>&nbsp;".$text;
238
                    }
239
                    $text .= ' (<span class=\'items_count\' id=\'itcount_'.$node->id.'\'>'.count($session_list_folders_limited[$node->id]).'</span>';
240
                } elseif (in_array($node->id, $listRestrictedFoldersForItemsKeys)) {
241
                    $restricted = "1";
242
                    if ($_SESSION['user_read_only'] === true) {
243
                        $text = "<i class='fa fa-eye'></i>&nbsp;".$text;
244
                    }
245
                    $text .= ' (<span class=\'items_count\' id=\'itcount_'.$node->id.'\'>'.count($session_list_restricted_folders_for_items[$node->id]).'</span>';
246
                } else {
247
                    $restricted = "1";
248
                    $folderClass = "folder_not_droppable";
249
                    if (isset($SETTINGS['show_only_accessible_folders']) && $SETTINGS['show_only_accessible_folders'] === "1") {
250
                        // folder is not visible
251
                            $nodeDirectDescendants = $tree->getDescendants($nodeId, false, true, true);
252
                        if (count($nodeDirectDescendants) > 0) {
253
                            // show it but block it
254
                            $hide_node = false;
255
                            $show_but_block = true;
256
                        } else {
257
                            // hide it
258
                            $hide_node = true;
259
                        }
260
                    } else {
261
                        // folder is visible but not accessible by user
262
                        $show_but_block = true;
263
                    }
264
                }
265
266
                // if required, separate the json answer for each folder
267
                if (!empty($ret_json)) {
268
                    $ret_json .= ", ";
269
                }
270
271
                // json
272
                if ($hide_node === false && $show_but_block === false) {
273
                    $ret_json .= '{'.
274
                        '"id":"li_'.$node->id.'"'.
275
                        ', "parent":"'.$parent.'"'.
276
                        ', "children":'.($childrenNb == 0 ? "false" : "true").
277
                        ', "text":"'.str_replace('"', '&quot;', $text).'"'.
278
                        ', "li_attr":{"class":"jstreeopen", "title":"ID ['.$node->id.'] '.$title.'"}'.
279
                        ', "a_attr":{"id":"fld_'.$node->id.'", "class":"'.$folderClass.' nodblclick" , "onclick":"ListerItems(\''.$node->id.'\', \''.$restricted.'\', 0, 1)"}'.
280
                    '}';
281
                } elseif ($show_but_block === true) {
282
                    $ret_json .= '{'.
283
                        '"id":"li_'.$node->id.'"'.
284
                        ', "parent":"'.$parent.'"'.
285
                        ', "children":'.($childrenNb == 0 ? "false" : "true").
286
                        ', "text":"<i class=\'fa fa-close mi-red\'></i>&nbsp;'.$text.'"'.
287
                        ', "li_attr":{"class":"", "title":"ID ['.$node->id.'] '.$LANG['no_access'].'"}'.
288
                    '}';
289
                }
290
            }
291
        }
292
    }
293
}
294
295
/*
296
* Get through complete tree
297
*/
298
function recursiveTree($nodeId)
299
{
300
    global $completTree, $ret_json, $listFoldersLimitedKeys, $listRestrictedFoldersForItemsKeys, $tree, $LANG, $last_visible_parent, $last_visible_parent_level, $SETTINGS;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
301
302
    // Load library
303
    require_once $SETTINGS['cpassman_dir'].'/includes/libraries/protect/SuperGlobal/SuperGlobal.php';
304
    $superGlobal = new protect\SuperGlobal\SuperGlobal();
305
306
    // Prepare superGlobal variables
307
    $session_forbiden_pfs =                         $superGlobal->get("forbiden_pfs", "SESSION");
308
    $session_groupes_visibles =                     $superGlobal->get("groupes_visibles", "SESSION");
309
    $session_list_restricted_folders_for_items =    $superGlobal->get("list_restricted_folders_for_items", "SESSION");
310
    $session_user_id =                              $superGlobal->get("user_id", "SESSION");
311
    $session_login =                                $superGlobal->get("login", "SESSION");
312
    $session_user_read_only =                       $superGlobal->get("user_read_only", "SESSION");
313
    $session_no_access_folders =                    $superGlobal->get("no_access_folders", "SESSION");
314
    $session_list_folders_limited =                 $superGlobal->get("list_folders_limited", "SESSION");
315
    $session_read_only_folders =                    $superGlobal->get("read_only_folders", "SESSION");
316
317
    // Be sure that user can only see folders he/she is allowed to
318
    if (in_array($completTree[$nodeId]->id, $session_forbiden_pfs) === false
319
        || in_array($completTree[$nodeId]->id, $session_groupes_visibles) === true
320
        || in_array($completTree[$nodeId]->id, $listFoldersLimitedKeys) === true
321
        || in_array($completTree[$nodeId]->id, $listRestrictedFoldersForItemsKeys) === true
322
    ) {
323
        $displayThisNode = false;
324
        $hide_node = false;
325
        $nbChildrenItems = 0;
326
327
        // Check if any allowed folder is part of the descendants of this node
328
        $nodeDescendants = $tree->getDescendants($completTree[$nodeId]->id, true, false, true);
329
        foreach ($nodeDescendants as $node) {
330
            // manage tree counters
331
            if (isset($SETTINGS['tree_counters']) === true && $SETTINGS['tree_counters'] === "1"
332
                && in_array(
333
                    $node,
334
                    array_merge($session_groupes_visibles, $session_list_restricted_folders_for_items)
335
                ) === true
336
            ) {
337
                DB::query(
338
                    "SELECT * FROM ".prefix_table("items")."
339
                    WHERE inactif=%i AND id_tree = %i",
340
                    0,
341
                    $node
342
                );
343
                $nbChildrenItems += DB::count();
344
            }
345
            if (in_array(
346
                $node,
347
                array_merge(
348
                    $session_groupes_visibles,
349
                    $session_list_restricted_folders_for_items,
350
                    $session_no_access_folders
351
                )
352
            ) === true
353
                || @in_array($node, $listFoldersLimitedKeys) === true
354
                || @in_array($node, $listRestrictedFoldersForItemsKeys) === true
355
            ) {
356
                $displayThisNode = true;
357
                $hide_node = $show_but_block = false;
358
                $text = $title = "";
359
            }
360
        }
361
362
        if ($displayThisNode === true) {
363
            // get info about current folder
364
            DB::query(
365
                "SELECT * FROM ".prefix_table("items")."
366
                WHERE inactif=%i AND id_tree = %i",
367
                0,
368
                $completTree[$nodeId]->id
369
            );
370
            $itemsNb = DB::count();
371
372
            // If personal Folder, convert id into user name
373
            if ($completTree[$nodeId]->title == $session_user_id && $completTree[$nodeId]->nlevel == 1) {
374
                $completTree[$nodeId]->title = $session_login;
375
            }
376
377
            // Decode if needed
378
            $completTree[$nodeId]->title = htmlspecialchars_decode($completTree[$nodeId]->title, ENT_QUOTES);
379
380
            // special case for READ-ONLY folder
381
            if ($session_user_read_only === true
382
                && in_array($completTree[$nodeId]->id, $session_user_read_only) === false
383
            ) {
384
                $title = $LANG['read_only_account'];
385
            }
386
            $text .= str_replace("&", "&amp;", $completTree[$nodeId]->title);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $text does not seem to be defined for all execution paths leading up to this point.
Loading history...
387
            $restricted = "0";
388
            $folderClass = "folder";
389
390
            if (in_array($completTree[$nodeId]->id, $session_groupes_visibles) === true) {
391
                if (in_array($completTree[$nodeId]->id, $session_read_only_folders) === true) {
392
                    $text = "<i class='fa fa-eye'></i>&nbsp;".$text;
393
                    $title = $LANG['read_only_account'];
394
                    $restricted = 1;
395
                    $folderClass = "folder_not_droppable";
396
                } elseif ($session_user_read_only === true
397
                    && in_array($completTree[$nodeId]->id, $_SESSION['personal_visible_groups']) === false
398
                ) {
399
                    $text = "<i class='fa fa-eye'></i>&nbsp;".$text;
400
                }
401
                $text .= ' (<span class=\'items_count\' id=\'itcount_'.$completTree[$nodeId]->id.'\'>'.$itemsNb.'</span>';
402
                // display tree counters
403
                if (isset($SETTINGS['tree_counters']) === true
404
                    && $SETTINGS['tree_counters'] == 1
405
                ) {
406
                    $text .= '|'.$nbChildrenItems.'|'.(count($nodeDescendants) - 1);
407
                }
408
                $text .= ')';
409
            } elseif (in_array($completTree[$nodeId]->id, $listFoldersLimitedKeys) === true) {
410
                $restricted = "1";
411
                if ($session_user_read_only === true) {
412
                    $text = "<i class='fa fa-eye'></i>&nbsp;".$text;
413
                }
414
                $text .= ' (<span class=\'items_count\' id=\'itcount_'.$completTree[$nodeId]->id.'\'>'.count($session_list_folders_limited[$completTree[$nodeId]->id]).'</span>';
415
            } elseif (in_array($completTree[$nodeId]->id, $listRestrictedFoldersForItemsKeys) === true) {
416
                $restricted = "1";
417
                if ($_SESSION['user_read_only'] === true) {
418
                    $text = "<i class='fa fa-eye'></i>&nbsp;".$text;
419
                }
420
                $text .= ' (<span class=\'items_count\' id=\'itcount_'.$completTree[$nodeId]->id.'\'>'.count($_SESSION['list_restricted_folders_for_items'][$completTree[$nodeId]->id]).'</span>';
421
            } else {
422
                $restricted = "1";
423
                $folderClass = "folder_not_droppable";
424
                if (isset($SETTINGS['show_only_accessible_folders']) === true
425
                    && $SETTINGS['show_only_accessible_folders'] === "1"
426
                    && $nbChildrenItems === 0
427
                ) {
428
                    // folder should not be visible
429
                    // only if it has no descendants
430
                    $nodeDirectDescendants = $tree->getDescendants($nodeId, false, false, true);
431
                    if (count(
432
                        array_diff(
433
                            $nodeDirectDescendants,
434
                            array_merge(
435
                                $session_groupes_visibles,
436
                                array_keys($session_list_restricted_folders_for_items)
437
                            )
438
                        )
439
                    ) !== count($nodeDirectDescendants)) {
440
                        // show it but block it
441
                        $show_but_block = true;
442
                        $hide_node = false;
443
                    } else {
444
                        // hide it
445
                        $hide_node = true;
446
                    }
447
                } else {
448
                    // folder is visible but not accessible by user
449
                    $show_but_block = true;
450
                }
451
            }
452
453
            // prepare json return for current node
454
            if ($completTree[$nodeId]->parent_id === "0") {
455
                $parent = "#";
456
            } else {
457
                $parent = "li_".$completTree[$nodeId]->parent_id;
458
            }
459
460
            // handle displaying
461
            if (isset($SETTINGS['show_only_accessible_folders']) === true
462
                && $SETTINGS['show_only_accessible_folders'] === "1"
463
            ) {
464
                if ($hide_node === true) {
465
                    $last_visible_parent = $parent;
466
                    $last_visible_parent_level = $completTree[$nodeId]->nlevel--;
467
                } elseif ($completTree[$nodeId]->nlevel < $last_visible_parent_level) {
468
                    $last_visible_parent = "";
469
                }
470
            }
471
472
473
            // json
474
            if ($hide_node === false && $show_but_block === false) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $show_but_block does not seem to be defined for all execution paths leading up to this point.
Loading history...
475
                $ret_json .= (!empty($ret_json) ? ", " : "").'{'.
476
                    '"id":"li_'.$completTree[$nodeId]->id.'"'.
477
                    ', "parent":"'.(empty($last_visible_parent) ? $parent : $last_visible_parent).'"'.
478
                    ', "text":"'.str_replace('"', '&quot;', $text).'"'.
479
                    ', "li_attr":{"class":"jstreeopen", "title":"ID ['.$completTree[$nodeId]->id.'] '.$title.'"}'.
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $title does not seem to be defined for all execution paths leading up to this point.
Loading history...
480
                    ', "a_attr":{"id":"fld_'.$completTree[$nodeId]->id.'", "class":"'.$folderClass.'" , "onclick":"ListerItems(\''.$completTree[$nodeId]->id.'\', \''.$restricted.'\', 0, 1)", "ondblclick":"LoadTreeNode(\''.$completTree[$nodeId]->id.'\')"}'.
481
                '}';
482
            } elseif ($show_but_block === true) {
483
                $ret_json .= (!empty($ret_json) ? ", " : "").'{'.
484
                    '"id":"li_'.$completTree[$nodeId]->id.'"'.
485
                    ', "parent":"'.(empty($last_visible_parent) ? $parent : $last_visible_parent).'"'.
486
                    ', "text":"<i class=\'fa fa-close mi-red\'></i>&nbsp;'.$text.'"'.
487
                    ', "li_attr":{"class":"", "title":"ID ['.$completTree[$nodeId]->id.'] '.$LANG['no_access'].'"}'.
488
                '}';
489
            }
490
            foreach ($completTree[$nodeId]->children as $child) {
491
                recursiveTree($child);
492
            }
493
        }
494
    }
495
}
496