Project

General

Profile

Download (2.65 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
/*
4
	pfSense_MODULE:	utils
5
*/
6

    
7
/*
8
		Copyright (C) 2009 Janne Enberg <janne.enberg@lietu.net>
9
		All rights reserved.
10

    
11
        Redistribution and use in source and binary forms, with or without
12
        modification, are permitted provided that the following conditions are met:
13

    
14
        1. Redistributions of source code must retain the above copyright notice,
15
           this list of conditions and the following disclaimer.
16

    
17
        2. Redistributions in binary form must reproduce the above copyright
18
           notice, this list of conditions and the following disclaimer in the
19
           documentation and/or other materials provided with the distribution.
20

    
21
        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
        POSSIBILITY OF SUCH DAMAGE.
31

    
32
		DISABLE_PHP_LINT_CHECKING
33
*/
34

    
35
/****f* itemid/delete_id
36
 * NAME
37
 *   delete_id - delete an item with ['id'] = $id from $array
38
 * INPUTS
39
 *   $id       - int: The ID to delete
40
 *   $array    - array to delete the item from
41
 * RESULT
42
 *   boolean   - true if item was found and deleted
43
 ******/
44
function delete_id($id, &$array){
45
	// Index to delete
46
	$delete_index = NULL;
47

    
48
	// Search for the item in the array
49
	foreach ($array as $key => $item){
50
		// If this item is the one we want to delete
51
		if(isset($item['id']) && $item['id']==$id ){
52
			$delete_index = $key;
53
			break;
54
		}
55
	}
56

    
57
	// If we found the item, unset it
58
	if( $delete_index!==NULL ){
59
		unset($array[$delete_index]);
60
		return true;
61
	} else {
62
		return false;
63
	}
64

    
65
}
66

    
67
/****f* itemid/get_next_id
68
 * NAME
69
 *   get_next_id - find the next available id from an item list
70
 * INPUTS
71
 *   $array      - array of items to get the id for
72
 * RESULT
73
 *   integer     - the next available id
74
 ******/
75
function get_next_id($array){
76
	// Default value
77
	$next_id = 1;
78

    
79
	// Search for IDs
80
	foreach ($array as $item){
81
		// If this item has an ID, and it's higher or equal to the current "next ID", use that + 1 as the next ID
82
		if(isset($item['id']) && $item['id']>=$next_id ){
83
			$next_id = $item['id'] + 1;
84
		}
85
	}
86
	return $next_id;
87
}
88

    
89
?>
(21-21/46)