Projet

Général

Profil

Télécharger (2,98 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / inc / itemid.inc @ 34bb5eb0

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
	if (!is_array($array))
49
		return false;
50

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

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

    
68
}
69

    
70
/****f* itemid/get_id
71
 * NAME
72
 *   get_id - Get an item id with ['associated-rule-id'] = $id from $array
73
 * INPUTS
74
 *   $id       - string: The ID to get
75
 *   $array    - array to get the item from
76
 * RESULT
77
 *   mixed   - The id, NULL if not found
78
 ******/
79
function get_id($id, &$array) {
80
	// Use $foo = &get_id('id', array('id'=>'value'));
81

    
82
	if (!is_array($array))
83
		return false;
84

    
85
	// Search for the item in the array
86
	foreach ($array as $key => $item){
87
		// If this item is the one we want to delete
88
		if (isset($item['associated-rule-id']) && $item['associated-rule-id']==$id)
89
			return $key;
90
	}
91

    
92
	return false;
93
}
94

    
95
/****f* itemid/get_unique_id
96
 * NAME
97
 *   get_unique_id - get a unique identifier
98
 * RESULT
99
 *   string     - unique id
100
 ******/
101
function get_unique_id(){
102

    
103
	return uniqid("nat_", true);
104
}
105

    
106
?>
(29-29/67)