1 | <?php |
---|
2 | /***************************************************************************\ |
---|
3 | * eGroupWare - Contacts Center * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * Written by: * |
---|
6 | * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * |
---|
7 | * sponsored by Thyamad - http://www.thyamad.com |
---|
8 | * ------------------------------------------------------------------------- * |
---|
9 | * This program is free software; you can redistribute it and/or modify it * |
---|
10 | * under the terms of the GNU General Public License as published by the * |
---|
11 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
12 | * option) any later version. * |
---|
13 | \***************************************************************************/ |
---|
14 | |
---|
15 | |
---|
16 | /* This is a special class that handles requests to a catalog that is actually |
---|
17 | * a catalog group. So this class actually performs all the requests in its |
---|
18 | * catalog childs. |
---|
19 | */ |
---|
20 | |
---|
21 | include_once('class.abo_catalog.inc.php'); |
---|
22 | |
---|
23 | class bo_catalog_group_catalog extends abo_catalog |
---|
24 | { |
---|
25 | var $external; |
---|
26 | var $fields = array( |
---|
27 | 'id_contact' => true, |
---|
28 | 'status' => true, |
---|
29 | 'photo' => true, |
---|
30 | 'alias' => true, |
---|
31 | 'prefix' => true, |
---|
32 | 'given_names' => true, |
---|
33 | 'family_names' => true, |
---|
34 | 'names_ordered' => true, |
---|
35 | 'suffix' => true, |
---|
36 | 'birthdate' => true, |
---|
37 | 'sex' => true, |
---|
38 | 'pgp_key' => true, |
---|
39 | 'notes' => true, |
---|
40 | |
---|
41 | /* Array fields */ |
---|
42 | 'companies' => true, |
---|
43 | 'relations' => true, |
---|
44 | 'addresses' => true, |
---|
45 | 'connections' => true |
---|
46 | ); |
---|
47 | |
---|
48 | /*! |
---|
49 | |
---|
50 | @function bo_people_catalog |
---|
51 | @abstract Constructor |
---|
52 | @author Raphael Derosso Pereira |
---|
53 | |
---|
54 | */ |
---|
55 | function bo_catalog_group_catalog(& $bo_contactcenter, & $catalog, $external = 0 ) |
---|
56 | { |
---|
57 | $this->bo_contactcenter = & $bo_contactcenter; |
---|
58 | $this->catalog = & $catalog; |
---|
59 | $this->external = $external; |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | /*! |
---|
64 | |
---|
65 | @function find |
---|
66 | @abstract Returns all the IDs of the entries found in all child |
---|
67 | catalogues that corresponds to the specified rules. |
---|
68 | @author Raphael Derosso Pereira |
---|
69 | |
---|
70 | @param SEE class bo_contactcenter for usage |
---|
71 | |
---|
72 | */ |
---|
73 | function find($what, $rules, $other, $area=false, $recursive=false) |
---|
74 | { |
---|
75 | if ($ldap_info = $this->catalog['ldap']) |
---|
76 | { |
---|
77 | $meta_catalog =& CreateObject('contactcenter.bo_global_ldap_catalog',$ldap_info['id_source'], $ldap_info['context'], $this->external); |
---|
78 | return $meta_catalog->find($what, $rules, $other, false, $recursive); |
---|
79 | } |
---|
80 | |
---|
81 | $results = array(); |
---|
82 | |
---|
83 | reset($this->catalog); |
---|
84 | while(list(, $new_catalog) = each($this->catalog['sub_branch'])) |
---|
85 | { |
---|
86 | //print_r($new_catalog); |
---|
87 | //echo 'Setting catalog: <b>'.$new_catalog['name'].'</b><br>'; |
---|
88 | $new_catalog = $this->bo_contactcenter->set_catalog($new_catalog); |
---|
89 | |
---|
90 | //if($new_catalog) echo 'Setado corretamente!<br><br>'; else echo 'Erro ao setar<br><br>'; |
---|
91 | |
---|
92 | if ($new_catalog['type'] === 'empty') |
---|
93 | { |
---|
94 | continue; |
---|
95 | } |
---|
96 | |
---|
97 | $temp_res = $this->bo_contactcenter->catalog->find($what, $rules, $other, false, $recursive); |
---|
98 | if (is_array($temp_res) and count($temp_res)) |
---|
99 | { |
---|
100 | foreach ($temp_res as $id => $value) |
---|
101 | { |
---|
102 | $result[$id] = $value; |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | //$this->bo_contactcenter->set_catalog($this->catalog); |
---|
108 | return $result; |
---|
109 | } |
---|
110 | |
---|
111 | /*! |
---|
112 | |
---|
113 | @function get_single_entry |
---|
114 | @abstract Returns all information requested about one contact |
---|
115 | @author Raphael Derosso Pereira |
---|
116 | |
---|
117 | @param integer $id_contact The contact ID |
---|
118 | @param array $fields The array returned by get_fields whith true |
---|
119 | on the fields to be taken. |
---|
120 | |
---|
121 | */ |
---|
122 | function get_single_entry ( $id_contact, $fields ) |
---|
123 | { |
---|
124 | if (!is_array($fields)) |
---|
125 | { |
---|
126 | if (is_object($GLOBALS['phpgw']->log)) |
---|
127 | { |
---|
128 | $GLOBALS['phpgw']->log->message(array( |
---|
129 | 'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.', |
---|
130 | 'line' => __LINE__, |
---|
131 | 'file' => __FILE__)); |
---|
132 | |
---|
133 | $GLOBALS['phpgw']->log->commit(); |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | $contact_array = $this->get_multiple_entries(array($id_contact), $fields); |
---|
142 | |
---|
143 | if (!count($contact_array)) |
---|
144 | { |
---|
145 | return false; |
---|
146 | } |
---|
147 | |
---|
148 | if($contact_array[0]) |
---|
149 | $contact_data = $contact_array[0]; |
---|
150 | else |
---|
151 | $contact_data = $contact_array[$id_contact]; |
---|
152 | |
---|
153 | if (!is_array($contact_data)) |
---|
154 | { |
---|
155 | return false; |
---|
156 | } |
---|
157 | |
---|
158 | return $contact_data; |
---|
159 | } |
---|
160 | |
---|
161 | /*! |
---|
162 | |
---|
163 | @function get_multiple_entries |
---|
164 | @abstract Returns multiple Contacts data into one array |
---|
165 | @author Raphael Derosso Pereira |
---|
166 | |
---|
167 | @param array $id_contacts The Contacts IDs |
---|
168 | @param array $fields The Contacts fields to be retrieved |
---|
169 | @param array $other_data Other informations. The format is: |
---|
170 | $other_data = array( |
---|
171 | 'offset' => <offset>, |
---|
172 | 'limit' => <max_num_returns>, |
---|
173 | 'sort' => <sort>, |
---|
174 | 'order_by' => <order by> |
---|
175 | ); |
---|
176 | |
---|
177 | */ |
---|
178 | function get_multiple_entries ( $id_contacts, $fields, $other_data = false ) |
---|
179 | { |
---|
180 | if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data))) |
---|
181 | { |
---|
182 | if (is_object($GLOBALS['phpgw']->log)) |
---|
183 | { |
---|
184 | $GLOBALS['phpgw']->log->message(array( |
---|
185 | 'text' => 'F-BadcontactcenterParam, wrong get_multiple_entry parameter type.', |
---|
186 | 'line' => __LINE__, |
---|
187 | 'file' => __FILE__)); |
---|
188 | |
---|
189 | $GLOBALS['phpgw']->log->commit(); |
---|
190 | } |
---|
191 | else { |
---|
192 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | $contacts = array(); |
---|
197 | |
---|
198 | if ($other_data) |
---|
199 | { |
---|
200 | //TODO |
---|
201 | } |
---|
202 | |
---|
203 | /* First check if this is a LDAP Catalog Group. In this case, just leave the |
---|
204 | * subtree search for the LDAP server |
---|
205 | */ |
---|
206 | if ($ldap_info = $this->catalog['ldap']) |
---|
207 | { |
---|
208 | $meta_catalog = CreateObject('contactcenter.bo_global_ldap_catalog', $ldap_info['id_source'], $ldap_info['context'], $this->external); |
---|
209 | return $meta_catalog->get_multiple_entries($id_contacts, $fields, $other_data); |
---|
210 | } |
---|
211 | |
---|
212 | /* Search for the catalog of the first entry and try to get all ids from that |
---|
213 | * catalog. Repeat to the ones not found until there's none missing or no more |
---|
214 | * catalogs. |
---|
215 | */ |
---|
216 | |
---|
217 | $contacts = array(); |
---|
218 | reset($this->catalog); |
---|
219 | while (list($level,$branch) = each($this->catalog['sub_branch'])) |
---|
220 | { |
---|
221 | $this->bo_contactcenter->set_catalog($branch); |
---|
222 | $contacts += $this->bo_contactcenter->catalog->get_multiple_entries($id_contacts, $fields, $other_data); |
---|
223 | |
---|
224 | reset($contacts); |
---|
225 | while (list($id) = each($contacts)) |
---|
226 | { |
---|
227 | if ($id_contacts[$id]) |
---|
228 | { |
---|
229 | unset($id_contacts[$id]); |
---|
230 | } |
---|
231 | } |
---|
232 | |
---|
233 | if (!count($id_contacts)) |
---|
234 | { |
---|
235 | break; |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | $this->bo_contactcenter->set_catalog($this->catalog); |
---|
240 | |
---|
241 | return $contacts; |
---|
242 | } |
---|
243 | |
---|
244 | function get_all_entries_ids () |
---|
245 | { |
---|
246 | // TODO! |
---|
247 | return null; |
---|
248 | } |
---|
249 | |
---|
250 | /*********************************************************************\ |
---|
251 | * Methods to get general fields * |
---|
252 | \*********************************************************************/ |
---|
253 | |
---|
254 | /*********************************************************************\ |
---|
255 | * Methods to Include Data * |
---|
256 | \*********************************************************************/ |
---|
257 | |
---|
258 | /*********************************************************************\ |
---|
259 | * Methods to Alter Data * |
---|
260 | \*********************************************************************/ |
---|
261 | |
---|
262 | /*********************************************************************\ |
---|
263 | * Methods to Remove Data * |
---|
264 | \*********************************************************************/ |
---|
265 | |
---|
266 | } |
---|
267 | ?> |
---|