Projet

Général

Profil

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

univnautes / etc / inc / itemid.inc @ 340ce958

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
*/
33

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

    
47
	if (!is_array($array))
48
		return false;
49

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

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

    
67
}
68

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

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

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

    
91
	return false;
92
}
93

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

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

    
105
?>
(30-30/68)