Revision 75bb5037
Added by Renato Botelho over 8 years ago
src/etc/inc/itemid.inc | ||
---|---|---|
32 | 32 |
function delete_id($id, &$array) { |
33 | 33 |
global $config; |
34 | 34 |
|
35 |
// Index to delete |
|
36 |
$delete_index = NULL; |
|
37 |
|
|
38 | 35 |
if (!is_array($array)) { |
39 | 36 |
return false; |
40 | 37 |
} |
41 | 38 |
|
42 | 39 |
// Search for the item in the array |
43 |
foreach ($array as $key => $item) { |
|
44 |
// If this item is the one we want to delete |
|
45 |
if (isset($item['associated-rule-id']) && $item['associated-rule-id'] == $id) { |
|
46 |
$delete_index = $key; |
|
47 |
$if = $item['interface']; |
|
48 |
break; |
|
49 |
} |
|
50 |
} |
|
40 |
$delete_index = get_id($id, $array); |
|
51 | 41 |
|
52 | 42 |
// If we found the item, unset it |
53 |
if ($delete_index !== NULL) { |
|
54 |
unset($array[$delete_index]); |
|
55 |
|
|
56 |
// Update the separators |
|
57 |
$a_separators = &$config['filter']['separator'][strtolower($if)]; |
|
58 |
$ridx = ifridx($if, $delete_index); // get rule index within interface |
|
59 |
$mvnrows = -1; |
|
60 |
move_separators($a_separators, $ridx, $mvnrows); |
|
61 |
|
|
62 |
return true; |
|
63 |
} else { |
|
43 |
if ($delete_index === false) { |
|
64 | 44 |
return false; |
65 | 45 |
} |
66 | 46 |
|
47 |
$if = $array[$delete_index]['interface']; |
|
48 |
unset($array[$delete_index]); |
|
49 |
|
|
50 |
// Update the separators |
|
51 |
$a_separators = &$config['filter']['separator'][strtolower($if)]; |
|
52 |
// get rule index within interface |
|
53 |
$ridx = ifridx($if, $delete_index); |
|
54 |
$mvnrows = -1; |
|
55 |
move_separators($a_separators, $ridx, $mvnrows); |
|
56 |
|
|
57 |
return true; |
|
67 | 58 |
} |
68 | 59 |
|
69 | 60 |
/****f* itemid/get_id |
... | ... | |
85 | 76 |
// Search for the item in the array |
86 | 77 |
foreach ($array as $key => $item) { |
87 | 78 |
// If this item is the one we want to delete |
88 |
if (isset($item['associated-rule-id']) && $item['associated-rule-id'] == $id) { |
|
79 |
if (isset($item['associated-rule-id']) && |
|
80 |
$item['associated-rule-id'] == $id) { |
|
89 | 81 |
return $key; |
90 | 82 |
} |
91 | 83 |
} |
Also available in: Unified diff
Simplify logic