Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
65f48828
Commit
65f48828
authored
Aug 21, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add legacy_move_config_list_items to legacy base, to replace move pattern in several input forms
parent
f14846c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
legacy_bindings.inc
src/etc/inc/legacy_bindings.inc
+48
-0
No files found.
src/etc/inc/legacy_bindings.inc
View file @
65f48828
...
...
@@ -95,3 +95,51 @@ function legacy_list_aliasses($type) {
}
return
$result
;
}
/**
* Function to move selected array items before another one.
* Mainly used in form processing.
* @param array $source config section to apply move on
* @param int $id item number to move selected to (before)
* @param array $items item numbers to move
* @return new constructed list
*/
function
legacy_move_config_list_items
(
$source
,
$id
,
$items
)
{
$new_config
=
array
();
if
(
!
is_array
(
$source
))
{
// input of wrong type, return empty array
return
array
();
}
elseif
(
!
is_array
(
$items
)
||
!
is_numericint
(
$id
))
{
// selected items isn't an array or selected item isn't an int, return input
return
$source
;
}
else
{
// input types are valid, move items around
// copy all rules before selected target ($id) and not in items
for
(
$i
=
0
;
$i
<
min
(
$id
,
count
(
$source
));
$i
++
)
{
if
(
!
in_array
(
$i
,
$items
))
{
$new_config
[]
=
$source
[
$i
];
}
}
// next copy all selected rules (=before $id)
for
(
$i
=
0
;
$i
<
count
(
$source
);
$i
++
)
{
if
(
$i
!=
$id
&&
in_array
(
$i
,
$items
))
{
$new_config
[]
=
$source
[
$i
];
}
}
// copy $id rule
if
(
$id
<
count
(
$source
))
{
$new_config
[]
=
$source
[
$id
];
}
/* copy all rules > $id and not selected */
for
(
$i
=
$id
+
1
;
$i
<
count
(
$source
);
$i
++
)
{
if
(
!
in_array
(
$i
,
$items
))
{
$new_config
[]
=
$source
[
$i
];
}
}
return
$new_config
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment