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 | include_once('class.abo_catalog.inc.php'); |
---|
16 | class bo_people_catalog extends abo_catalog |
---|
17 | { |
---|
18 | |
---|
19 | var $fields = array( |
---|
20 | 'id_contact' => true, |
---|
21 | 'status' => true, |
---|
22 | 'photo' => true, |
---|
23 | 'alias' => true, |
---|
24 | 'prefix' => true, |
---|
25 | 'given_names' => true, |
---|
26 | 'family_names' => true, |
---|
27 | 'names_ordered' => true, |
---|
28 | 'suffix' => true, |
---|
29 | 'birthdate' => true, |
---|
30 | 'sex' => true, |
---|
31 | 'pgp_key' => true, |
---|
32 | 'notes' => true, |
---|
33 | 'corporate_name'=> true, |
---|
34 | 'job_title' => true, |
---|
35 | 'department' => true, |
---|
36 | 'web_page' => true, |
---|
37 | /* Array fields */ |
---|
38 | 'companies' => true, |
---|
39 | 'relations' => true, |
---|
40 | 'addresses' => true, |
---|
41 | 'connections' => true |
---|
42 | ); |
---|
43 | |
---|
44 | /*! |
---|
45 | |
---|
46 | @function bo_people_catalog |
---|
47 | @abstract Constructor |
---|
48 | @author Raphael Derosso Pereira |
---|
49 | |
---|
50 | */ |
---|
51 | function bo_people_catalog() |
---|
52 | { |
---|
53 | $this->init(); |
---|
54 | } |
---|
55 | |
---|
56 | /*! |
---|
57 | @function find |
---|
58 | @abstract Find function for this catalog |
---|
59 | @author Raphael Derosso Pereira |
---|
60 | |
---|
61 | */ |
---|
62 | function find($what, $rules=false, $other=false) |
---|
63 | { |
---|
64 | if (is_array($what) and count($what)) |
---|
65 | { |
---|
66 | $found = false; |
---|
67 | |
---|
68 | foreach ($what as $value) |
---|
69 | { |
---|
70 | if (strpos($value, 'contact') === 0) |
---|
71 | { |
---|
72 | $found = true; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | if (!$found) |
---|
77 | { |
---|
78 | return $this->sql_find($what, $rules, $other); |
---|
79 | } |
---|
80 | |
---|
81 | if ($rules and is_array($rules)) |
---|
82 | { |
---|
83 | array_push($rules, array( |
---|
84 | 'field' => 'contact.id_owner', |
---|
85 | 'type' => '=', |
---|
86 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
87 | )); |
---|
88 | } |
---|
89 | else |
---|
90 | { |
---|
91 | $rules = array( |
---|
92 | 0 => array( |
---|
93 | 'field' => 'contact.id_owner', |
---|
94 | 'type' => '=', |
---|
95 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
96 | ) |
---|
97 | ); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | return $this->sql_find($what, $rules, $other); |
---|
102 | } |
---|
103 | |
---|
104 | /*! |
---|
105 | |
---|
106 | @function get_single_entry |
---|
107 | @abstract Returns all information requested about one contact |
---|
108 | @author Raphael Derosso Pereira |
---|
109 | |
---|
110 | @param integer $id_contact The contact ID |
---|
111 | @param array $fields The array returned by get_fields whith true |
---|
112 | on the fields to be taken. |
---|
113 | |
---|
114 | */ |
---|
115 | function get_single_entry ( $id_contact, $fields ) |
---|
116 | { |
---|
117 | if (!is_array($fields)) |
---|
118 | { |
---|
119 | if (is_object($GLOBALS['phpgw']->log)) |
---|
120 | { |
---|
121 | $GLOBALS['phpgw']->log->message(array( |
---|
122 | 'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.', |
---|
123 | 'line' => __LINE__, |
---|
124 | 'file' => __FILE__)); |
---|
125 | |
---|
126 | $GLOBALS['phpgw']->log->commit(); |
---|
127 | } |
---|
128 | else |
---|
129 | { |
---|
130 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | // Verify permissions |
---|
135 | $permissions = $this->security->get_permissions('entry', $id_contact); |
---|
136 | |
---|
137 | if (!$permissions['read']) |
---|
138 | { |
---|
139 | return false; |
---|
140 | } |
---|
141 | |
---|
142 | //$contact_data = $this->fields; |
---|
143 | |
---|
144 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
145 | |
---|
146 | foreach ($fields as $field => $trueness) |
---|
147 | { |
---|
148 | if (!$trueness) |
---|
149 | { |
---|
150 | //unset($contact_data[$field]); |
---|
151 | continue; |
---|
152 | } |
---|
153 | |
---|
154 | switch ($field) |
---|
155 | { |
---|
156 | case 'companies': |
---|
157 | $companies = $this->get_companies($id_contact,$trueness); |
---|
158 | |
---|
159 | if (is_array($companies) and count($companies)) |
---|
160 | { |
---|
161 | $contact_data['companies'] = $companies; |
---|
162 | } |
---|
163 | break; |
---|
164 | |
---|
165 | case 'relations': |
---|
166 | $relations = $this->get_relations($id_contact,$trueness); |
---|
167 | |
---|
168 | if (is_array($relations) and count($relations)) |
---|
169 | { |
---|
170 | $contact_data['relations'] = $relations; |
---|
171 | } |
---|
172 | break; |
---|
173 | |
---|
174 | case 'addresses': |
---|
175 | $addresses = $this->get_addresses($id_contact,$trueness); |
---|
176 | |
---|
177 | if (is_array($addresses) and count($addresses)) |
---|
178 | { |
---|
179 | $contact_data['addresses'] = $addresses; |
---|
180 | } |
---|
181 | break; |
---|
182 | |
---|
183 | case 'connections': |
---|
184 | $connections = $this->get_connections($id_contact,$trueness); |
---|
185 | |
---|
186 | if (is_array($connections) and count($connections)) |
---|
187 | { |
---|
188 | $contact_data['connections'] = $connections; |
---|
189 | } |
---|
190 | break; |
---|
191 | |
---|
192 | case 'prefix': |
---|
193 | $id = $contact->get_prefix(); |
---|
194 | if ($id) |
---|
195 | { |
---|
196 | $prefix = CreateObject('contactcenter.so_prefix', $id); |
---|
197 | $contact_data['id_prefix'] = $id; |
---|
198 | $contact_data['prefix'] = $prefix->get_prefix(); |
---|
199 | } |
---|
200 | break; |
---|
201 | |
---|
202 | case 'suffix': |
---|
203 | $id = $contact->get_suffix(); |
---|
204 | if ($id) |
---|
205 | { |
---|
206 | $suffix = CreateObject('contactcenter.so_suffix', $id); |
---|
207 | $contact_data['id_suffix'] = $id; |
---|
208 | $contact_data['suffix'] = $suffix->get_suffix(); |
---|
209 | } |
---|
210 | break; |
---|
211 | |
---|
212 | case 'status': |
---|
213 | $id = $contact->get_status(); |
---|
214 | if ($id) |
---|
215 | { |
---|
216 | $status = CreateObject('contactcenter.so_status', $id); |
---|
217 | $contact_data['id_status'] = $id; |
---|
218 | $contact_data['status'] = $status->get_status(); |
---|
219 | } |
---|
220 | break; |
---|
221 | |
---|
222 | default: |
---|
223 | //$func_name = 'contact->get_'.$field; |
---|
224 | //$contact_data[$field] = $this->$func_name(); |
---|
225 | $contact_data[$field] = $contact->get_field($field); |
---|
226 | break; |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | if (!is_array($contact_data)) |
---|
231 | { |
---|
232 | return false; |
---|
233 | } |
---|
234 | |
---|
235 | return $contact_data; |
---|
236 | } |
---|
237 | |
---|
238 | /*! |
---|
239 | |
---|
240 | @function get_multiple_entries |
---|
241 | @abstract Returns multiple Contacts data into one array |
---|
242 | @author Raphael Derosso Pereira |
---|
243 | |
---|
244 | @param array $id_contacts The Contacts IDs |
---|
245 | @param array $fields The Contacts fields to be retrieved |
---|
246 | @param array $other_data Other informations. The format is: |
---|
247 | $other_data = array( |
---|
248 | 'offset' => <offset>, |
---|
249 | 'limit' => <max_num_returns>, |
---|
250 | 'sort' => <sort>, |
---|
251 | 'order_by' => <order by> |
---|
252 | ); |
---|
253 | |
---|
254 | */ |
---|
255 | function get_multiple_entries ( $id_contacts, $fields, $other_data = false ) |
---|
256 | { |
---|
257 | if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data))) |
---|
258 | { |
---|
259 | if (is_object($GLOBALS['phpgw']->log)) |
---|
260 | { |
---|
261 | $GLOBALS['phpgw']->log->message(array( |
---|
262 | 'text' => 'F-BadcontactcenterParam, wrong get_multiple_entry parameter type.', |
---|
263 | 'line' => __LINE__, |
---|
264 | 'file' => __FILE__)); |
---|
265 | |
---|
266 | $GLOBALS['phpgw']->log->commit(); |
---|
267 | } |
---|
268 | else { |
---|
269 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
270 | } |
---|
271 | } |
---|
272 | |
---|
273 | $contacts = array(); |
---|
274 | |
---|
275 | if ($other_data) |
---|
276 | { |
---|
277 | //TODO |
---|
278 | } |
---|
279 | |
---|
280 | foreach ($id_contacts as $id) |
---|
281 | { |
---|
282 | $contact = $this->get_single_entry($id,$fields); |
---|
283 | if ($contact) |
---|
284 | { |
---|
285 | $contacts[$id] = $contact; |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | return $contacts; |
---|
290 | } |
---|
291 | |
---|
292 | /*! |
---|
293 | |
---|
294 | @function get_all_entries_ids |
---|
295 | @abstract Returns the IDs of all the entries in this catalog |
---|
296 | @author Raphael Derosso Pereira |
---|
297 | |
---|
298 | */ |
---|
299 | function get_all_entries_ids () |
---|
300 | { |
---|
301 | $search_fields = array('contact.id_contact', 'contact.names_ordered'); |
---|
302 | $search_other = array('order' => 'contact.names_ordered'); |
---|
303 | |
---|
304 | $result_i = $this->find($search_fields, null, $search_other); |
---|
305 | |
---|
306 | if (is_array($result_i) and count($result_i)) |
---|
307 | { |
---|
308 | $result = array(); |
---|
309 | foreach($result_i as $result_part) |
---|
310 | { |
---|
311 | $result[] = $result_part['id_contact']; |
---|
312 | } |
---|
313 | |
---|
314 | return $result; |
---|
315 | } |
---|
316 | |
---|
317 | return null; |
---|
318 | } |
---|
319 | |
---|
320 | /*! |
---|
321 | |
---|
322 | @function get_relations |
---|
323 | @abstract Returns the IDs of all Contacts relations |
---|
324 | @author Raphael Derosso Pereira |
---|
325 | |
---|
326 | @param integer $id_contact The Contact ID |
---|
327 | |
---|
328 | @return The following array: |
---|
329 | $return = array( |
---|
330 | 'relation1' => array( |
---|
331 | 'id_relation' => <id_relation>, |
---|
332 | 'id_type' => <id_type>, |
---|
333 | 'type' => '<type_name>', |
---|
334 | 'is_subordinated' => <trueness> |
---|
335 | ), |
---|
336 | 'relation2' => array(...), |
---|
337 | ... |
---|
338 | ); |
---|
339 | |
---|
340 | */ |
---|
341 | function get_relations ($id_contact,$extra=false) |
---|
342 | { |
---|
343 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
344 | $relations = $contact->get_relations(); |
---|
345 | |
---|
346 | $count = 1; |
---|
347 | foreach($relations as $id => $type) |
---|
348 | { |
---|
349 | $relation = CreateObject('contactcenter.so_contact_relation_type', $type); |
---|
350 | |
---|
351 | if ($extra === 'subordinated' and $relation->get_is_subordinated()) |
---|
352 | { |
---|
353 | $return['relation'.$count]['id_relation'] = $id; |
---|
354 | $return['relation'.$count]['id_type'] = $type; |
---|
355 | $return['relation'.$count]['type'] = $relation->get_type_name(); |
---|
356 | $return['relation'.$count]['is_subordinated'] = $relation->get_is_subordinated(); |
---|
357 | $count++; |
---|
358 | } |
---|
359 | else if ($extra !== 'subordinated') |
---|
360 | { |
---|
361 | $return['relation'.$count]['id_relation'] = $id; |
---|
362 | $return['relation'.$count]['id_type'] = $type; |
---|
363 | $return['relation'.$count]['type'] = $relation->get_type_name(); |
---|
364 | $return['relation'.$count]['is_subordinated'] = $relation->get_is_subordinated(); |
---|
365 | $count++; |
---|
366 | } |
---|
367 | } |
---|
368 | |
---|
369 | return $return; |
---|
370 | } |
---|
371 | |
---|
372 | /*! |
---|
373 | |
---|
374 | @function get_addresses |
---|
375 | @abstract Returns all Contacts Address Information |
---|
376 | @author Raphael Derosso Pereira |
---|
377 | |
---|
378 | @param integer $id_contact The Contact ID |
---|
379 | |
---|
380 | @return The following array: |
---|
381 | $return = array( |
---|
382 | 'address1' => array( |
---|
383 | 'id_address' => <id_address>, |
---|
384 | 'id_type' => <id_type>, |
---|
385 | 'type' => '<type_name>', |
---|
386 | 'address1' => '<address1>', |
---|
387 | 'address2' => '<address2>', |
---|
388 | 'complement' => '<complement>', |
---|
389 | 'address_other' => '<address_other>', |
---|
390 | 'postal_code' => '<postal_code>', |
---|
391 | 'po_box' => '<po_box>', |
---|
392 | 'id_city' => '<city>', |
---|
393 | 'city_name' => (string), |
---|
394 | 'city_timezone' => (int), |
---|
395 | 'city_geo_location' => (string), |
---|
396 | 'id_state' => (int), |
---|
397 | 'state_name' => (string), |
---|
398 | 'state_symbol' => (string), |
---|
399 | 'id_country' => (int), |
---|
400 | 'country_name' => (string), |
---|
401 | 'address_is_default' => <trueness> |
---|
402 | ), |
---|
403 | 'address2' => array(...), |
---|
404 | ... |
---|
405 | ); |
---|
406 | |
---|
407 | */ |
---|
408 | function get_addresses ( $id_contact,$extra=false ) |
---|
409 | { |
---|
410 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
411 | $addresses = $contact->get_addresses(extra); |
---|
412 | |
---|
413 | foreach($addresses as $id => $type) |
---|
414 | { |
---|
415 | $address = CreateObject('contactcenter.so_address',$id); |
---|
416 | $address_type = CreateObject('contactcenter.so_contact_address_type',$type); |
---|
417 | |
---|
418 | if ($extra === 'default' and $address->is_default()) |
---|
419 | { |
---|
420 | $return['address'.$type]['id_address'] = $id; |
---|
421 | $return['address'.$type]['id_typeof_address'] = $type; |
---|
422 | $return['address'.$type]['type'] = $address_type->get_type_name(); |
---|
423 | $return['address'.$type]['address1'] = $address->get_address1(); |
---|
424 | $return['address'.$type]['address2'] = $address->get_address2(); |
---|
425 | $return['address'.$type]['complement'] = $address->get_complement(); |
---|
426 | $return['address'.$type]['address_other'] = $address->get_address_other(); |
---|
427 | $return['address'.$type]['postal_code'] = $address->get_postal_code(); |
---|
428 | $return['address'.$type]['po_box'] = $address->get_po_box(); |
---|
429 | $return['address'.$type]['address_is_default'] = true; |
---|
430 | $return['address'.$type]['id_city'] = $id_city = $address->get_id_city(); |
---|
431 | $return['address'.$type]['id_state'] = $id_state = $address->get_id_state(); |
---|
432 | $return['address'.$type]['id_country'] = $id_country = $address->get_id_country(); |
---|
433 | |
---|
434 | if ($id_city) |
---|
435 | { |
---|
436 | $city = CreateObject('contactcenter.so_city',$id_city); |
---|
437 | $return['address'.$type]['city_name'] = $city->get_city_name(); |
---|
438 | $return['address'.$type]['city_timezone'] = $city->get_city_timezone(); |
---|
439 | $return['address'.$type]['city_geo_location'] = $city->get_city_geo_location(); |
---|
440 | } |
---|
441 | |
---|
442 | if ($id_state) |
---|
443 | { |
---|
444 | $state = CreateObject('contactcenter.so_state',$id_state); |
---|
445 | $return['address'.$type]['state_name'] = $state->get_state_name(); |
---|
446 | $return['address'.$type]['state_symbol'] = $state->get_state_symbol(); |
---|
447 | $return['address'.$type]['id_country'] = $id_country = $state->get_id_country(); |
---|
448 | } |
---|
449 | |
---|
450 | $country = CreateObject('contactcenter.so_country',$id_country); |
---|
451 | $return['address'.$type]['country_name'] = $country->get_country_name(); |
---|
452 | } |
---|
453 | else if ($extra !== 'default') |
---|
454 | { |
---|
455 | $return['address'.$type]['id_address'] = $id; |
---|
456 | $return['address'.$type]['id_typeof_address'] = $type; |
---|
457 | $return['address'.$type]['type'] = $address_type->get_type_name(); |
---|
458 | $return['address'.$type]['address1'] = $address->get_address1(); |
---|
459 | $return['address'.$type]['address2'] = $address->get_address2(); |
---|
460 | $return['address'.$type]['complement'] = $address->get_complement(); |
---|
461 | $return['address'.$type]['address_other'] = $address->get_address_other(); |
---|
462 | $return['address'.$type]['postal_code'] = $address->get_postal_code(); |
---|
463 | $return['address'.$type]['po_box'] = $address->get_po_box(); |
---|
464 | $return['address'.$type]['address_is_default'] = $address->is_default(); |
---|
465 | $return['address'.$type]['id_city'] = $id_city = $address->get_id_city(); |
---|
466 | $return['address'.$type]['id_state'] = $id_state = $address->get_id_state(); |
---|
467 | $return['address'.$type]['id_country'] = $id_country = $address->get_id_country(); |
---|
468 | |
---|
469 | if ($id_city) |
---|
470 | { |
---|
471 | $city = CreateObject('contactcenter.so_city',$id_city); |
---|
472 | $return['address'.$type]['city_name'] = $city->get_city_name(); |
---|
473 | $return['address'.$type]['city_timezone'] = $city->get_city_timezone(); |
---|
474 | $return['address'.$type]['city_geo_location'] = $city->get_city_geo_location(); |
---|
475 | } |
---|
476 | |
---|
477 | if ($id_state) |
---|
478 | { |
---|
479 | $state = CreateObject('contactcenter.so_state',$id_state); |
---|
480 | $return['address'.$type]['state_name'] = $state->get_state_name(); |
---|
481 | $return['address'.$type]['state_symbol'] = $state->get_state_symbol(); |
---|
482 | $return['address'.$type]['id_country'] = $id_country = $state->get_id_country(); |
---|
483 | } |
---|
484 | |
---|
485 | $country = CreateObject('contactcenter.so_country',$id_country); |
---|
486 | $return['address'.$type]['country_name'] = $country->get_country_name(); |
---|
487 | } |
---|
488 | } |
---|
489 | |
---|
490 | return $return; |
---|
491 | } |
---|
492 | |
---|
493 | |
---|
494 | /*! |
---|
495 | |
---|
496 | @function get_connections |
---|
497 | @abstract Returns all Contacts connections information |
---|
498 | @author Raphael Derosso Pereira |
---|
499 | |
---|
500 | @param integer $id_contact The Contact ID |
---|
501 | |
---|
502 | @return The following array: |
---|
503 | $return = array( |
---|
504 | 'connection1' => array( |
---|
505 | 'id_connection' => <id_connection>, |
---|
506 | 'id_type' => <id_type>, |
---|
507 | 'type' => '<type_name>', |
---|
508 | 'connection_name' => '<connection_name>', |
---|
509 | 'connection_value' => '<connection_value>', |
---|
510 | 'connection_is_default' => '<connection_is_default>' |
---|
511 | ), |
---|
512 | 'connection2' => array(...), |
---|
513 | ... |
---|
514 | ); |
---|
515 | |
---|
516 | */ |
---|
517 | function get_connections ( $id_contact,$extra=false ) |
---|
518 | { |
---|
519 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
520 | $connections = $contact->get_connections(); |
---|
521 | $getDummy = false; |
---|
522 | if ($extra && $extra === 'defaultwdummy') |
---|
523 | { |
---|
524 | $getDummy = true; |
---|
525 | $extra = 'default'; |
---|
526 | } |
---|
527 | |
---|
528 | $count = 1; |
---|
529 | foreach($connections as $id => $type) |
---|
530 | { |
---|
531 | $connection = CreateObject('contactcenter.so_connection', $id); |
---|
532 | if ($getDummy || $connection->get_name() !== 'no_conns') |
---|
533 | { |
---|
534 | if ($extra === 'default' and $connection->is_default()) |
---|
535 | { |
---|
536 | $connection_type = CreateObject('contactcenter.so_contact_connection_type', $type); |
---|
537 | $return['connection'.$count]['id_connection'] = $id; |
---|
538 | $return['connection'.$count]['id_type'] = $type; |
---|
539 | $return['connection'.$count]['type'] = $connection_type->get_type_name(); |
---|
540 | $return['connection'.$count]['connection_name'] = $connection->get_name(); |
---|
541 | $return['connection'.$count]['connection_value'] = $connection->get_value(); |
---|
542 | $return['connection'.$count]['connection_is_default'] = $connection->is_default(); |
---|
543 | $count++; |
---|
544 | } |
---|
545 | else if ($extra !== 'default') |
---|
546 | { |
---|
547 | $connection_type = CreateObject('contactcenter.so_contact_connection_type', $type); |
---|
548 | $return['connection'.$count]['id_connection'] = $id; |
---|
549 | $return['connection'.$count]['id_type'] = $type; |
---|
550 | $return['connection'.$count]['type'] = $connection_type->get_type_name(); |
---|
551 | $return['connection'.$count]['connection_name'] = $connection->get_name(); |
---|
552 | $return['connection'.$count]['connection_value'] = $connection->get_value(); |
---|
553 | $return['connection'.$count]['connection_is_default'] = $connection->is_default(); |
---|
554 | $count++; |
---|
555 | } |
---|
556 | } |
---|
557 | } |
---|
558 | |
---|
559 | return $return; |
---|
560 | } |
---|
561 | |
---|
562 | /* |
---|
563 | * @function update_contact_groups |
---|
564 | * @abstract Atualiza os grupos onde o contato está inserido. |
---|
565 | * @author Luiz Carlos Viana Melo - Prognus |
---|
566 | * @param (integer) $id_contact O ID do contato. |
---|
567 | * @param (array) $groups Os grupos onde o contato será inserido/removido. O |
---|
568 | * formato dos grupos será: |
---|
569 | * array( |
---|
570 | * 'added' => array( |
---|
571 | * id_group => array ( |
---|
572 | * 'id_group' => O ID do grupo. |
---|
573 | * 'title' => O título do grupo. |
---|
574 | * ) |
---|
575 | * ) |
---|
576 | * 'removed' => mesmo formato do added. |
---|
577 | * ) |
---|
578 | */ |
---|
579 | function update_contact_groups($id_contact, $groups, $old_connections = false) |
---|
580 | { |
---|
581 | $connections = $this->get_connections($id_contact, 'defaultwdummy'); |
---|
582 | $default_connection = false; |
---|
583 | foreach ($connections as $connection) |
---|
584 | { |
---|
585 | if (!$default_connection) |
---|
586 | { |
---|
587 | $default_connection = $connection; |
---|
588 | } |
---|
589 | if ($connection['id_type'] === 1) |
---|
590 | { |
---|
591 | $default_connection = $connection; |
---|
592 | } |
---|
593 | if($default_connection['id_type'] === 1) |
---|
594 | { |
---|
595 | break; |
---|
596 | } |
---|
597 | |
---|
598 | } |
---|
599 | |
---|
600 | $altered = false; |
---|
601 | |
---|
602 | if ($default_connection) |
---|
603 | { |
---|
604 | $bo_group = CreateObject('contactcenter.bo_group'); |
---|
605 | $old_groups = $groups['previous_selected']; |
---|
606 | if ($old_connections) |
---|
607 | $bo_group->update_contact_groups($default_connection['id_connection'], $old_connections, $old_groups); |
---|
608 | $added_groups = $groups['added']; |
---|
609 | $removed_groups = $groups['removed']; |
---|
610 | if(is_array($added_groups)) |
---|
611 | foreach ($added_groups as $group) |
---|
612 | { |
---|
613 | $altered = true; |
---|
614 | $c = array(); |
---|
615 | $c[] = $default_connection['id_connection']; |
---|
616 | $bo_group->add_contacts_in_group($group['id_group'], $c); |
---|
617 | } |
---|
618 | if(is_array($removed_groups)) |
---|
619 | foreach ($removed_groups as $group) |
---|
620 | { |
---|
621 | $altered = true; |
---|
622 | $c = array(); |
---|
623 | $c[] = $default_connection['id_connection']; |
---|
624 | $bo_group->remove_contacts_from_group($group['id_group'], $c); |
---|
625 | } |
---|
626 | } |
---|
627 | |
---|
628 | if ($altered) |
---|
629 | { |
---|
630 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
631 | $contact->set_field("last_status", 'U'); |
---|
632 | $contact->set_field("last_update",time()."000"); |
---|
633 | return $contact->commit(); |
---|
634 | } |
---|
635 | } |
---|
636 | |
---|
637 | /*! |
---|
638 | |
---|
639 | @function get_companies |
---|
640 | @abstract Returns all Contacts companies information |
---|
641 | @author Raphael Derosso Pereira |
---|
642 | |
---|
643 | @param integer $id_contact The Contact ID |
---|
644 | |
---|
645 | @return The following array: |
---|
646 | $return = array( |
---|
647 | 'company1' => array( |
---|
648 | 'id_company' => <id_company>, |
---|
649 | 'company_name' => '<company_name>' |
---|
650 | 'title' => '<company_name>', |
---|
651 | 'department' => '<company_value>', |
---|
652 | ), |
---|
653 | 'company2' => array(...), |
---|
654 | ... |
---|
655 | ); |
---|
656 | |
---|
657 | */ |
---|
658 | function get_companies ( $id_contact,$extra=false ) |
---|
659 | { |
---|
660 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
661 | $companies = $contact->get_companies($extra); |
---|
662 | |
---|
663 | $count = 1; |
---|
664 | foreach($companies as $id => $value) |
---|
665 | { |
---|
666 | $company = CreateObject('contactcenter.so_company', $id); |
---|
667 | |
---|
668 | if ($extra === 'default' and $value['default_company']) |
---|
669 | { |
---|
670 | $return['company'.$count]['id_company'] = $id; |
---|
671 | $return['company'.$count]['company_name'] = $company->get_company_name(); |
---|
672 | $return['company'.$count]['title'] = $value['title']; |
---|
673 | $return['company'.$count]['department'] = $value['department']; |
---|
674 | $return['company'.$count]['default_company'] = $value['default_company']; |
---|
675 | $return['company'.$count]['default_contact'] = $value['default_contact']; |
---|
676 | $count++; |
---|
677 | } |
---|
678 | else if ($extra !== 'default') |
---|
679 | { |
---|
680 | $return['company'.$count]['id_company'] = $id; |
---|
681 | $return['company'.$count]['company_name'] = $company->get_company_name(); |
---|
682 | $return['company'.$count]['title'] = $value['title']; |
---|
683 | $return['company'.$count]['department'] = $value['department']; |
---|
684 | $return['company'.$count]['default_company'] = $value['default_company']; |
---|
685 | $return['company'.$count]['default_contact'] = $value['default_contact']; |
---|
686 | $count++; |
---|
687 | } |
---|
688 | } |
---|
689 | |
---|
690 | return $return; |
---|
691 | } |
---|
692 | |
---|
693 | |
---|
694 | /*********************************************************************\ |
---|
695 | * Methods to get general fields * |
---|
696 | \*********************************************************************/ |
---|
697 | |
---|
698 | /*! |
---|
699 | |
---|
700 | @function get_all_prefixes |
---|
701 | @abstract Returns all the registered prefixes |
---|
702 | @author Raphael Derosso Pereira |
---|
703 | |
---|
704 | */ |
---|
705 | function get_all_prefixes ( ) |
---|
706 | { |
---|
707 | $fields = array('prefix.id_prefix','prefix.prefix'); |
---|
708 | |
---|
709 | $prefixes = $this->find($fields); |
---|
710 | |
---|
711 | if (!is_array($prefixes)) |
---|
712 | { |
---|
713 | return false; |
---|
714 | } |
---|
715 | |
---|
716 | while (list(,$prefix) = each($prefixes)) |
---|
717 | { |
---|
718 | $result[$prefix['id_prefix']] = $prefix['prefix']; |
---|
719 | } |
---|
720 | |
---|
721 | return $result; |
---|
722 | } |
---|
723 | |
---|
724 | |
---|
725 | /*! |
---|
726 | |
---|
727 | @function get_all_suffixes |
---|
728 | @abstract Returns all the registered suffixes |
---|
729 | @author Raphael Derosso Pereira |
---|
730 | @return An array as follows: |
---|
731 | $return = array( |
---|
732 | <id_suffix1> => '<suffix_name1>', |
---|
733 | <id_suffix2> => '<suffix_name2>', |
---|
734 | ... |
---|
735 | ); |
---|
736 | |
---|
737 | */ |
---|
738 | function get_all_suffixes ( ) |
---|
739 | { |
---|
740 | $fields = array('suffix.id_suffix','suffix.suffix'); |
---|
741 | |
---|
742 | $suffixes = $this->find($fields); |
---|
743 | |
---|
744 | if (!is_array($suffixes)) |
---|
745 | { |
---|
746 | return false; |
---|
747 | } |
---|
748 | |
---|
749 | while (list(,$suffix) = each($suffixes)) |
---|
750 | { |
---|
751 | $result[$suffix['id_suffix']] = $suffix['suffix']; |
---|
752 | } |
---|
753 | |
---|
754 | return $result; |
---|
755 | } |
---|
756 | |
---|
757 | /*! |
---|
758 | |
---|
759 | @function get_all_status |
---|
760 | @abstract Returns all the registered status |
---|
761 | @author Raphael Derosso Pereira |
---|
762 | @return An array as follows: |
---|
763 | $return = array( |
---|
764 | <id_status1> => '<status_name1>', |
---|
765 | <id_status2> => '<status_name2>', |
---|
766 | ... |
---|
767 | ); |
---|
768 | |
---|
769 | */ |
---|
770 | function get_all_status ( ) |
---|
771 | { |
---|
772 | $fields = array('status.id_status','status.status_name'); |
---|
773 | |
---|
774 | $status = $this->find($fields); |
---|
775 | |
---|
776 | if (!is_array($status)) |
---|
777 | { |
---|
778 | return false; |
---|
779 | } |
---|
780 | |
---|
781 | while (list(,$status_) = each($status)) |
---|
782 | { |
---|
783 | $result[$status_['id_status']] = $status_['status_name']; |
---|
784 | } |
---|
785 | |
---|
786 | return $result; |
---|
787 | } |
---|
788 | |
---|
789 | /*! |
---|
790 | |
---|
791 | @function get_all_relations_types |
---|
792 | @abstract Returns all contacts relations types |
---|
793 | @author Raphael Derosso Pereira |
---|
794 | |
---|
795 | @return array The format of the return is: |
---|
796 | $return = array( |
---|
797 | <id_type1> => '<type1_name>', |
---|
798 | <id_type2> => '<type2_name>', |
---|
799 | ...); |
---|
800 | */ |
---|
801 | function get_all_relations_types ( ) |
---|
802 | { |
---|
803 | $fields = array('typeof_contact_relation.id_typeof_contact_relation', 'typeof_contact_relation.contact_relation_type_name'); |
---|
804 | |
---|
805 | $relation_types = $this->find($fields); |
---|
806 | |
---|
807 | if (!is_array($relation_types)) |
---|
808 | { |
---|
809 | return false; |
---|
810 | } |
---|
811 | |
---|
812 | while (list(,$relation_type) = each($relation_types)) |
---|
813 | { |
---|
814 | $result[$relation_type['id_typeof_contact_relation']] = $relation_type['contact_relation_type_name']; |
---|
815 | } |
---|
816 | |
---|
817 | return $result; |
---|
818 | } |
---|
819 | |
---|
820 | /*! |
---|
821 | |
---|
822 | @function get_all_addresses_types |
---|
823 | @abstract Returns all contacts addresses types |
---|
824 | @author Raphael Derosso Pereira |
---|
825 | |
---|
826 | @return array The format of the return is: |
---|
827 | $return = array( |
---|
828 | <id_type1> => '<type1_name>', |
---|
829 | <id_type2> => '<type2_name>', |
---|
830 | ...); |
---|
831 | */ |
---|
832 | function get_all_addresses_types ( ) |
---|
833 | { |
---|
834 | $fields = array('typeof_contact_address.id_typeof_contact_address', 'typeof_contact_address.contact_address_type_name'); |
---|
835 | |
---|
836 | $address_types = $this->find($fields); |
---|
837 | |
---|
838 | if (!is_array($address_types)) |
---|
839 | { |
---|
840 | return false; |
---|
841 | } |
---|
842 | |
---|
843 | while (list(,$address_type) = each($address_types)) |
---|
844 | { |
---|
845 | $result[$address_type['id_typeof_contact_address']] = $address_type['contact_address_type_name']; |
---|
846 | } |
---|
847 | |
---|
848 | return $result; |
---|
849 | } |
---|
850 | |
---|
851 | /*! |
---|
852 | |
---|
853 | @function get_all_connections_types |
---|
854 | @abstract Returns all contacts connections types |
---|
855 | @author Raphael Derosso Pereira |
---|
856 | |
---|
857 | @return array The format of the return is: |
---|
858 | $return = array( |
---|
859 | <id_type1> => '<type1_name>', |
---|
860 | <id_type2> => '<type2_name>', |
---|
861 | ...); |
---|
862 | */ |
---|
863 | function get_all_connections_types ( ) |
---|
864 | { |
---|
865 | $fields = array('typeof_contact_connection.id_typeof_contact_connection', 'typeof_contact_connection.contact_connection_type_name'); |
---|
866 | |
---|
867 | $connection_types = $this->find($fields); |
---|
868 | |
---|
869 | if (!is_array($connection_types)) |
---|
870 | { |
---|
871 | return false; |
---|
872 | } |
---|
873 | |
---|
874 | while (list(,$connection_type) = each($connection_types)) |
---|
875 | { |
---|
876 | $result[$connection_type['id_typeof_contact_connection']] = $connection_type['contact_connection_type_name']; |
---|
877 | } |
---|
878 | |
---|
879 | return $result; |
---|
880 | } |
---|
881 | |
---|
882 | /*! |
---|
883 | |
---|
884 | @function get_vcard |
---|
885 | @abstract Returns an URL that points to the file |
---|
886 | that contains a vCard of the specified Contact |
---|
887 | @author Raphael Derosso Pereira |
---|
888 | |
---|
889 | @param integer $id_status The Contact ID |
---|
890 | |
---|
891 | */ |
---|
892 | function get_vcard ( $id_contact ) |
---|
893 | { |
---|
894 | } |
---|
895 | |
---|
896 | |
---|
897 | /*********************************************************************\ |
---|
898 | * Methods to Include Data * |
---|
899 | \*********************************************************************/ |
---|
900 | |
---|
901 | /*! |
---|
902 | |
---|
903 | @function add_single_entry |
---|
904 | @abstract Insert a new Contact record in the DB |
---|
905 | @author Raphael Derosso Pereira |
---|
906 | |
---|
907 | @param array $data The Contact Information. |
---|
908 | |
---|
909 | Format: |
---|
910 | |
---|
911 | $data = array( |
---|
912 | 'id_status' => <id_status>, |
---|
913 | 'photo' => '<photo_bin_stream>', |
---|
914 | 'alias' => '<alias>', |
---|
915 | 'id_prefix' => <id_prefix>, |
---|
916 | 'given_names' => '<given_names>', |
---|
917 | 'family_names' => '<family_names>', |
---|
918 | 'names_ordered' => '<names_ordered>', |
---|
919 | 'id_suffix' => <id_suffix>, |
---|
920 | 'birthdate' => '<birthdate>', |
---|
921 | 'sex' => '<sex>', |
---|
922 | 'pgp_key' => '<pgp_key>', |
---|
923 | 'notes' => '<notes>', |
---|
924 | |
---|
925 | 'companies' => array( |
---|
926 | company1 => array( |
---|
927 | 'id_company' => <id_company>, |
---|
928 | 'company_name' => <company_name>, |
---|
929 | 'title' => <title>, |
---|
930 | 'department' => <department>, |
---|
931 | 'default_company' => (bool), |
---|
932 | 'default_contact' => (bool) |
---|
933 | ), |
---|
934 | company2 => array(...), |
---|
935 | ... |
---|
936 | ), |
---|
937 | |
---|
938 | 'relations' => array( |
---|
939 | 'relation1' => array( |
---|
940 | 'id_relation' => <id_relation>, |
---|
941 | 'id_typeof_relation' => <id_typeof_relation>, |
---|
942 | ), |
---|
943 | 'relation2' => array(...), |
---|
944 | ... |
---|
945 | ), |
---|
946 | |
---|
947 | 'addresses' => array( |
---|
948 | 'address1' => array( |
---|
949 | 'id_typeof_address' => <id_typeof_address>, |
---|
950 | 'address1' => '<address1>', |
---|
951 | 'address2' => '<address2>', |
---|
952 | 'complement' => '<complement>', |
---|
953 | 'address_other' => '<address_other>', |
---|
954 | 'postal_code' => '<postal_code>', |
---|
955 | 'po_box' => '<po_box>', |
---|
956 | 'id_city' => '<city>', |
---|
957 | 'address_is_default' => <trueness> |
---|
958 | ), |
---|
959 | 'address2' => array(...), |
---|
960 | ... |
---|
961 | ), |
---|
962 | |
---|
963 | 'connections' => array( |
---|
964 | 'connection1' => array( |
---|
965 | 'id_typeof_connection' => <id_typeof_connection>, |
---|
966 | 'connection_name' => <connection_name>, |
---|
967 | 'connection_value' => <connection_value>, |
---|
968 | 'connection_is_default' => <trueness> |
---|
969 | ), |
---|
970 | 'connection2' => array(...), |
---|
971 | ... |
---|
972 | ), |
---|
973 | |
---|
974 | ); |
---|
975 | |
---|
976 | If any of the above fields doesn't have a value, it should hold false. |
---|
977 | In the case of the multiple-values fields, instead of the array, there |
---|
978 | should be a false. |
---|
979 | |
---|
980 | @return integer $id The Contact ID |
---|
981 | */ |
---|
982 | //alterada para receber a informacao em 'notes' - Rommel Cysne - rommel.cysne@serpro.gov.br |
---|
983 | function add_single_entry ( $data ) |
---|
984 | { |
---|
985 | $permissions = $this->security->get_permissions(); |
---|
986 | |
---|
987 | $exist_connections = false; |
---|
988 | |
---|
989 | if (!$permissions['create']) |
---|
990 | { |
---|
991 | //return false; |
---|
992 | } |
---|
993 | |
---|
994 | $contact = CreateObject('contactcenter.so_contact'); |
---|
995 | $contact->reset_values(); |
---|
996 | |
---|
997 | $altered = false; |
---|
998 | foreach($data as $field => $value) |
---|
999 | { |
---|
1000 | if ($value === false && $field != 'connections') |
---|
1001 | { |
---|
1002 | continue; |
---|
1003 | } |
---|
1004 | |
---|
1005 | $altered = true; |
---|
1006 | switch($field) |
---|
1007 | { |
---|
1008 | case 'photo': |
---|
1009 | case 'alias': |
---|
1010 | case 'id_prefix': |
---|
1011 | case 'id_status': |
---|
1012 | case 'id_suffix': |
---|
1013 | case 'corporate_name': |
---|
1014 | case 'job_title': |
---|
1015 | case 'department': |
---|
1016 | case 'web_page': |
---|
1017 | case 'given_names': |
---|
1018 | case 'family_names': |
---|
1019 | case 'names_ordered': |
---|
1020 | case 'birthdate': |
---|
1021 | case 'sex': |
---|
1022 | case 'pgp_key': |
---|
1023 | case 'notes': |
---|
1024 | $contact->set_field($field,$value); |
---|
1025 | break; |
---|
1026 | |
---|
1027 | case 'companies': |
---|
1028 | foreach($value as $company_fields) |
---|
1029 | { |
---|
1030 | if ($company_fields['company_name']) |
---|
1031 | { |
---|
1032 | $fields = array('company.id_company'); |
---|
1033 | $restric = array( |
---|
1034 | 0 => array( |
---|
1035 | 'field' => 'company.company_name', |
---|
1036 | 'type' => 'iLIKE', |
---|
1037 | 'value' => $company_fields['company_name'] |
---|
1038 | ) |
---|
1039 | ); |
---|
1040 | |
---|
1041 | if($result = $this->find($fields,$restric)) |
---|
1042 | { |
---|
1043 | $id = $result[0]['id_company']; |
---|
1044 | $company_fields['id_company'] = $id; |
---|
1045 | } |
---|
1046 | else |
---|
1047 | { |
---|
1048 | $company = CreateObject('contactcenter.so_company'); |
---|
1049 | $company->reset_values(); |
---|
1050 | $company->set_company_name($company_fields['company_name']); |
---|
1051 | $company->set_field('id_company_owner',$GLOBALS['phpgw_info']['user']['account_id']); |
---|
1052 | $company_fields['id_company'] = $company->commit(); |
---|
1053 | } |
---|
1054 | } |
---|
1055 | |
---|
1056 | $contact->set_company($company_fields); |
---|
1057 | } |
---|
1058 | break; |
---|
1059 | |
---|
1060 | case 'relations': |
---|
1061 | foreach($value as $relation_fields) |
---|
1062 | { |
---|
1063 | $contact->set_relation($relation_fields['id_relation'], $relation_fields['id_typeof_relation']); |
---|
1064 | } |
---|
1065 | break; |
---|
1066 | |
---|
1067 | case 'addresses': |
---|
1068 | foreach($value as $address_fields) |
---|
1069 | { |
---|
1070 | $address = CreateObject('contactcenter.so_address'); |
---|
1071 | $address->reset_values(); |
---|
1072 | foreach($address_fields as $a_field => $a_value) |
---|
1073 | { |
---|
1074 | if ($a_field !== 'id_typeof_address') |
---|
1075 | { |
---|
1076 | $address->set_field($a_field,$a_value); |
---|
1077 | } |
---|
1078 | } |
---|
1079 | $address->commit(); |
---|
1080 | $id_address = $address->get_id(); |
---|
1081 | $contact->set_address($id_address, $address_fields['id_typeof_address']); |
---|
1082 | } |
---|
1083 | break; |
---|
1084 | |
---|
1085 | case 'connections': |
---|
1086 | foreach($value as $connection_name => $connection_fields) |
---|
1087 | { |
---|
1088 | $exist_connections = true; |
---|
1089 | $connection = CreateObject('contactcenter.so_connection'); |
---|
1090 | $connection->reset_values(); |
---|
1091 | |
---|
1092 | foreach($connection_fields as $a_field => $a_value) |
---|
1093 | { |
---|
1094 | if ($a_field !== 'id_typeof_connection') |
---|
1095 | { |
---|
1096 | $connection->set_field($a_field,$a_value); |
---|
1097 | } |
---|
1098 | } |
---|
1099 | |
---|
1100 | $connection->commit(); |
---|
1101 | $id_connection = $connection->get_id(); |
---|
1102 | $contact->set_connection($id_connection, $connection_fields['id_typeof_connection']); |
---|
1103 | } |
---|
1104 | break; |
---|
1105 | |
---|
1106 | default: |
---|
1107 | return false; |
---|
1108 | } |
---|
1109 | } |
---|
1110 | |
---|
1111 | if ($altered) |
---|
1112 | { |
---|
1113 | $contact->set_field('id_owner',$GLOBALS['phpgw_info']['user']['account_id']); |
---|
1114 | //insert a dummy connection if the contact dont have an email and telephone |
---|
1115 | if (!$exist_connections) |
---|
1116 | { |
---|
1117 | $this->add_dummy($contact); |
---|
1118 | } |
---|
1119 | return $contact->commit(); |
---|
1120 | } |
---|
1121 | |
---|
1122 | return false; |
---|
1123 | } |
---|
1124 | |
---|
1125 | /*! |
---|
1126 | |
---|
1127 | @function quick_add |
---|
1128 | @abstract Insert a new Contact record in the DB with just the |
---|
1129 | main fields |
---|
1130 | @author Raphael Derosso Pereira |
---|
1131 | |
---|
1132 | @param array $data The Contact Information. |
---|
1133 | |
---|
1134 | Format: |
---|
1135 | |
---|
1136 | $data = array( |
---|
1137 | 'alias' => '<alias>', |
---|
1138 | 'given_names' => '<given_names>', |
---|
1139 | 'family_names' => '<family_names>', |
---|
1140 | |
---|
1141 | 'connections' => array( |
---|
1142 | 'default_email' => array( |
---|
1143 | 'connection_name' => <connection_name>, |
---|
1144 | 'connection_value' => <connection_value> |
---|
1145 | ), |
---|
1146 | 'default_phone' => array( |
---|
1147 | 'connection_name' => <connection_name>, |
---|
1148 | 'connection_value' => <connection_value> |
---|
1149 | ) |
---|
1150 | ) |
---|
1151 | ); |
---|
1152 | */ |
---|
1153 | //alterada para receber os outros parametros existentes na adicao completa de contatos pessoais |
---|
1154 | //Rommel Cysne - rommel.cysne@serpro.gov.br |
---|
1155 | function quick_add ( $data ) |
---|
1156 | { |
---|
1157 | $permissions = $this->security->get_permissions(); |
---|
1158 | |
---|
1159 | if (!$permissions['create']) |
---|
1160 | { |
---|
1161 | return false; |
---|
1162 | } |
---|
1163 | |
---|
1164 | // TODO: GET THE ORDER TO PUT names_ordered FROM PREFERENCES! |
---|
1165 | |
---|
1166 | $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); |
---|
1167 | |
---|
1168 | if ( !isset($preferences['personCardEmail']) || ( !is_numeric($preferences['personCardEmail'])) ) |
---|
1169 | { |
---|
1170 | $preferences['personCardEmail'] = 1; |
---|
1171 | } |
---|
1172 | if ( !isset($preferences['personCardPhone']) || ( !is_numeric($preferences['personCardPhone'])) ) |
---|
1173 | { |
---|
1174 | $preferences['personCardPhone'] = 2; |
---|
1175 | } |
---|
1176 | |
---|
1177 | if(!$data['is_quick_add']){ |
---|
1178 | $sql = "select * FROM phpgw_cc_state where (upper(state_name) = upper('".$data['addresses']['address_corporative']['id_state']."')) or (upper(state_symbol) = upper('".$data['addresses']['address_corporative']['id_state']."'))"; |
---|
1179 | |
---|
1180 | $this->db->query($sql, __LINE__, __FILE__); |
---|
1181 | |
---|
1182 | $corporative_state = array('id_state'=>2); |
---|
1183 | while($this->db->next_record()) |
---|
1184 | { |
---|
1185 | $corporative_state = $this->db->row(); |
---|
1186 | } |
---|
1187 | |
---|
1188 | $sql = "select * FROM phpgw_cc_city where id_state = ".$corporative_state['id_state']." and upper(city_name) = upper('".$data['addresses']['address_corporative']['id_city']."') "; |
---|
1189 | |
---|
1190 | $this->db->query($sql, __LINE__, __FILE__); |
---|
1191 | |
---|
1192 | $corporative_city = array('id_city'=>null); |
---|
1193 | while($this->db->next_record()) |
---|
1194 | { |
---|
1195 | $corporative_city = $this->db->row(); |
---|
1196 | } |
---|
1197 | |
---|
1198 | //Personal Address |
---|
1199 | |
---|
1200 | $sql = "select * FROM phpgw_cc_state where upper(state_name) = upper('".$data['addresses']['address_personal']['id_state']."')"; |
---|
1201 | |
---|
1202 | $this->db->query($sql, __LINE__, __FILE__); |
---|
1203 | |
---|
1204 | $personal_state = array('id_state'=>2); |
---|
1205 | while($this->db->next_record()) |
---|
1206 | { |
---|
1207 | $personal_state = $this->db->row(); |
---|
1208 | } |
---|
1209 | |
---|
1210 | $sql = "select * FROM phpgw_cc_city where id_state = ".$personal_state['id_state']." and upper(city_name) = upper('".$data['addresses']['address_personal']['id_city']."') "; |
---|
1211 | |
---|
1212 | $this->db->query($sql, __LINE__, __FILE__); |
---|
1213 | |
---|
1214 | $personal_city = array('id_city'=>null); |
---|
1215 | while($this->db->next_record()) |
---|
1216 | { |
---|
1217 | $personal_city = $this->db->row(); |
---|
1218 | } |
---|
1219 | } |
---|
1220 | |
---|
1221 | $new_data = array( |
---|
1222 | 'notes' => $data['notes'], |
---|
1223 | 'alias' => $data['alias'], |
---|
1224 | 'id_status' => 1, |
---|
1225 | 'given_names' => $data['given_names'], |
---|
1226 | 'family_names' => $data['family_names'], |
---|
1227 | 'names_ordered' => $data['given_names'].' '.$data['family_names'], |
---|
1228 | 'family_names' => $data['family_names'], |
---|
1229 | 'alias' => $data['alias'], |
---|
1230 | 'corporate_name' => $data['corporate_name'], |
---|
1231 | 'job_title' => $data['job_title'], |
---|
1232 | 'department' => $data['department'], |
---|
1233 | 'web_page' => $data['web_page'], |
---|
1234 | 'birthdate' => $data['birthdate'], |
---|
1235 | 'pgp_key' => $data['pgp_key'], |
---|
1236 | 'sex' => $data['sex'], |
---|
1237 | ); |
---|
1238 | |
---|
1239 | $i = 1; |
---|
1240 | if ($data['connections']['default_email']['connection_value']) |
---|
1241 | { |
---|
1242 | $new_data['connections']['connection'.$i] = array( |
---|
1243 | 'id_typeof_connection' => $preferences['personCardEmail'], |
---|
1244 | 'connection_name' => $data['connections']['default_email']['connection_name'], |
---|
1245 | 'connection_value' => $data['connections']['default_email']['connection_value'], |
---|
1246 | 'connection_is_default' => 1, |
---|
1247 | ); |
---|
1248 | $i++; |
---|
1249 | } |
---|
1250 | |
---|
1251 | if ($data['connections']['aditional_email']['connection_value']) |
---|
1252 | { |
---|
1253 | $new_data['connections']['connection'.$i] = array( |
---|
1254 | 'id_typeof_connection' => $preferences['personCardEmail'], |
---|
1255 | 'connection_name' => $data['connections']['aditional_email']['connection_name'], |
---|
1256 | 'connection_value' => $data['connections']['aditional_email']['connection_value'], |
---|
1257 | 'connection_is_default' => 0, |
---|
1258 | ); |
---|
1259 | $i++; |
---|
1260 | } |
---|
1261 | |
---|
1262 | if ($data['connections']['default_phone']['connection_value']) |
---|
1263 | { |
---|
1264 | $new_data['connections']['connection'.$i] = array( |
---|
1265 | 'id_typeof_connection' => $preferences['personCardPhone'], |
---|
1266 | 'connection_name' => $data['connections']['default_phone']['connection_name'], |
---|
1267 | 'connection_value' => $data['connections']['default_phone']['connection_value'], |
---|
1268 | 'connection_is_default' => 1, |
---|
1269 | ); |
---|
1270 | |
---|
1271 | |
---|
1272 | foreach($data['connections']['aditional_phone'] as $connection_name => $connection_fields) |
---|
1273 | { |
---|
1274 | if($connection_fields['connection_value'] != ''){ |
---|
1275 | $i++; |
---|
1276 | $new_data['connections']['connection'.$i] = array( |
---|
1277 | 'id_typeof_connection' => $preferences['personCardPhone'], |
---|
1278 | 'connection_name' => $connection_fields['connection_name'], |
---|
1279 | 'connection_value' => $connection_fields['connection_value'], |
---|
1280 | 'connection_is_default' => 0, |
---|
1281 | ); |
---|
1282 | } |
---|
1283 | } |
---|
1284 | |
---|
1285 | }else{ |
---|
1286 | $default =1; |
---|
1287 | if(isset($data['connections']['aditional_phone'])) |
---|
1288 | foreach($data['connections']['aditional_phone'] as $connection_name => $connection_fields) |
---|
1289 | { |
---|
1290 | $i++; |
---|
1291 | $new_data['connections']['connection'.$i] = array( |
---|
1292 | 'id_typeof_connection' => $preferences['personCardPhone'], |
---|
1293 | 'connection_name' => $connection_fields['connection_name'], |
---|
1294 | 'connection_value' => $connection_fields['connection_value'], |
---|
1295 | 'connection_is_default' => $default, |
---|
1296 | ); |
---|
1297 | $default = 0; |
---|
1298 | } |
---|
1299 | } |
---|
1300 | if(!$data['is_quick_add']){ |
---|
1301 | $new_data['addresses']['address'.$i] = array( |
---|
1302 | 'id_typeof_address' => 2, |
---|
1303 | 'address1' => $data['addresses']['address_personal']['address1'], |
---|
1304 | 'address2' => $data['addresses']['address_personal']['address2'], |
---|
1305 | 'complement' => $data['addresses']['address_personal']['complement'], |
---|
1306 | 'postal_code' => $data['addresses']['address_personal']['postal_code'], |
---|
1307 | 'id_country' => $data['addresses']['address_personal']['id_country'], |
---|
1308 | 'id_state' => $personal_state['id_state'], |
---|
1309 | 'id_city' => $personal_city['id_city'], |
---|
1310 | 'address_is_default' => 0, |
---|
1311 | ); |
---|
1312 | $i++; |
---|
1313 | |
---|
1314 | $new_data['addresses']['address'.$i] = array( |
---|
1315 | 'id_typeof_address' => 1, |
---|
1316 | 'address1' => $data['addresses']['address_corporative']['address1'], |
---|
1317 | 'address2' => $data['addresses']['address_corporative']['address2'], |
---|
1318 | 'complement' => $data['addresses']['address_corporative']['complement'], |
---|
1319 | 'postal_code' => $data['addresses']['address_corporative']['postal_code'], |
---|
1320 | 'id_country' => $data['addresses']['address_corporative']['id_country'], |
---|
1321 | 'id_state' => $corporative_state['id_state'], |
---|
1322 | 'id_city' => $corporative_city['id_city'], |
---|
1323 | 'address_is_default' => 1, |
---|
1324 | ); |
---|
1325 | $i++; |
---|
1326 | } |
---|
1327 | |
---|
1328 | $j = 1; |
---|
1329 | |
---|
1330 | /*if($data['addresses']['addr1']['address_value']) |
---|
1331 | { |
---|
1332 | $new_data['addresses']['address'.$j] = array( |
---|
1333 | 'id_typeof_address' => 1, //<id_typeof_address> - 1 - Comercial; 2 - Residencial |
---|
1334 | 'address1' => $data['addresses']['addr1']['address_value'], |
---|
1335 | 'address2' => $data['addresses']['addr2']['address_value'], |
---|
1336 | 'id_country' => 'BR', |
---|
1337 | //'complement' => '<complement>', |
---|
1338 | //'address_other' => '<address_other>', |
---|
1339 | 'postal_code' => $data['addresses']['cep']['address_value'], |
---|
1340 | //'po_box' => '<po_box>', |
---|
1341 | //'id_city' => '<city>', |
---|
1342 | 'address_is_default' => 'false', |
---|
1343 | ); |
---|
1344 | $j++; |
---|
1345 | }*/ |
---|
1346 | |
---|
1347 | |
---|
1348 | return $this->add_single_entry($new_data); |
---|
1349 | } |
---|
1350 | |
---|
1351 | /*! |
---|
1352 | |
---|
1353 | @function add_prefix |
---|
1354 | @abstract Insert a new Prefix in the DB |
---|
1355 | @author Raphael Derosso Pereira |
---|
1356 | |
---|
1357 | @param string $prefix The Prefix |
---|
1358 | @return integer The new ID |
---|
1359 | |
---|
1360 | */ |
---|
1361 | function add_prefix ( $prefix ) |
---|
1362 | { |
---|
1363 | $permissions = $this->security->get_type_permissions(); |
---|
1364 | |
---|
1365 | if (!$permissions['create']) |
---|
1366 | { |
---|
1367 | return false; |
---|
1368 | } |
---|
1369 | } |
---|
1370 | |
---|
1371 | /*! |
---|
1372 | |
---|
1373 | @function add_suffix |
---|
1374 | @abstract Insert a new suffix in the DB |
---|
1375 | @author Raphael Derosso Pereira |
---|
1376 | |
---|
1377 | @param string $suffix The suffix |
---|
1378 | @return integer The new ID |
---|
1379 | |
---|
1380 | */ |
---|
1381 | function add_suffix ( $suffix ) |
---|
1382 | { |
---|
1383 | $permissions = $this->security->get_type_permissions(); |
---|
1384 | |
---|
1385 | if (!$permissions['create']) |
---|
1386 | { |
---|
1387 | return false; |
---|
1388 | } |
---|
1389 | } |
---|
1390 | |
---|
1391 | /*! |
---|
1392 | |
---|
1393 | @function add_status |
---|
1394 | @abstract Insert a new Status in the DB |
---|
1395 | @author Raphael Derosso Pereira |
---|
1396 | |
---|
1397 | @param string $status The Status |
---|
1398 | @return integer The new ID |
---|
1399 | |
---|
1400 | */ |
---|
1401 | function add_status ( $status ) |
---|
1402 | { |
---|
1403 | $permissions = $this->security->get_type_permissions(); |
---|
1404 | |
---|
1405 | if (!$permissions['create']) |
---|
1406 | { |
---|
1407 | return false; |
---|
1408 | } |
---|
1409 | } |
---|
1410 | |
---|
1411 | /*! |
---|
1412 | |
---|
1413 | @function add_relation_type |
---|
1414 | @abstract Insert a new Relation Type in the DB |
---|
1415 | @author Raphael Derosso Pereira |
---|
1416 | |
---|
1417 | @param string $type_name The Relation Type |
---|
1418 | @return integer The new ID |
---|
1419 | |
---|
1420 | */ |
---|
1421 | function add_relation_type ( $type_name ) |
---|
1422 | { |
---|
1423 | $permissions = $this->security->get_type_permissions(); |
---|
1424 | |
---|
1425 | if (!$permissions['create']) |
---|
1426 | { |
---|
1427 | return false; |
---|
1428 | } |
---|
1429 | } |
---|
1430 | |
---|
1431 | /*! |
---|
1432 | |
---|
1433 | @function add_address_type |
---|
1434 | @abstract Insert a new Address Type in the DB |
---|
1435 | @author Raphael Derosso Pereira |
---|
1436 | |
---|
1437 | @param string $type_name The Address Type |
---|
1438 | @return integer The new ID |
---|
1439 | |
---|
1440 | */ |
---|
1441 | function add_address_type ( $type_name ) |
---|
1442 | { |
---|
1443 | $permissions = $this->security->get_type_permissions(); |
---|
1444 | |
---|
1445 | if (!$permissions['create']) |
---|
1446 | { |
---|
1447 | return false; |
---|
1448 | } |
---|
1449 | } |
---|
1450 | |
---|
1451 | /*! |
---|
1452 | |
---|
1453 | @function add_connection_type |
---|
1454 | @abstract Insert a new Connection Type in the DB |
---|
1455 | @author Raphael Derosso Pereira |
---|
1456 | |
---|
1457 | @param string $type_name The Connection Type |
---|
1458 | @return integer The new ID |
---|
1459 | |
---|
1460 | */ |
---|
1461 | function add_connection_type ( $type_name ) |
---|
1462 | { |
---|
1463 | $permissions = $this->security->get_type_permissions(); |
---|
1464 | |
---|
1465 | if (!$permissions['create']) |
---|
1466 | { |
---|
1467 | return false; |
---|
1468 | } |
---|
1469 | } |
---|
1470 | |
---|
1471 | |
---|
1472 | |
---|
1473 | /*********************************************************************\ |
---|
1474 | * Methods to Alter Data * |
---|
1475 | \*********************************************************************/ |
---|
1476 | |
---|
1477 | /*! |
---|
1478 | |
---|
1479 | @function update_single_info |
---|
1480 | @abstract Update information of an existing Contact |
---|
1481 | @author Raphael Derosso Pereira |
---|
1482 | |
---|
1483 | @param integer $id_status The Contact ID |
---|
1484 | @param string $status The new Status value |
---|
1485 | |
---|
1486 | */ |
---|
1487 | function update_single_info ( $id_contact, $data ) |
---|
1488 | { |
---|
1489 | $permissions = $this->security->get_permissions($id_contact); |
---|
1490 | |
---|
1491 | if (!$permissions['write']) |
---|
1492 | { |
---|
1493 | return false; |
---|
1494 | } |
---|
1495 | |
---|
1496 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
1497 | |
---|
1498 | $altered = false; |
---|
1499 | // print_r($data); |
---|
1500 | foreach($data as $field => $value) |
---|
1501 | { |
---|
1502 | if ($value === false) |
---|
1503 | { |
---|
1504 | continue; |
---|
1505 | } |
---|
1506 | |
---|
1507 | $altered = true; |
---|
1508 | switch($field) |
---|
1509 | { |
---|
1510 | case 'photo': |
---|
1511 | case 'alias': |
---|
1512 | case 'id_prefix': |
---|
1513 | case 'id_status': |
---|
1514 | case 'id_suffix': |
---|
1515 | case 'corporate_name': |
---|
1516 | case 'job_title': |
---|
1517 | case 'department': |
---|
1518 | case 'web_page': |
---|
1519 | case 'given_names': |
---|
1520 | case 'family_names': |
---|
1521 | case 'names_ordered': |
---|
1522 | case 'birthdate': |
---|
1523 | case 'sex': |
---|
1524 | case 'pgp_key': |
---|
1525 | case 'notes': |
---|
1526 | $contact->set_field($field,$value); |
---|
1527 | break; |
---|
1528 | |
---|
1529 | case 'companies': |
---|
1530 | foreach($value as $company_fields) |
---|
1531 | { |
---|
1532 | if ($company_fields['company_name']) |
---|
1533 | { |
---|
1534 | $fields = array('company.id_company'); |
---|
1535 | $restric = array( |
---|
1536 | 0 => array( |
---|
1537 | 'field' => 'company.company_name', |
---|
1538 | 'type' => 'iLIKE', |
---|
1539 | 'value' => $company_fields['company_name'] |
---|
1540 | ) |
---|
1541 | ); |
---|
1542 | |
---|
1543 | if($result = $this->find($fields,$restric)) |
---|
1544 | { |
---|
1545 | $id = $result[0]['id_company']; |
---|
1546 | $company_fields['id_company'] = $id; |
---|
1547 | } |
---|
1548 | else |
---|
1549 | { |
---|
1550 | $company = CreateObject('contactcenter.so_company'); |
---|
1551 | $company->reset_values(); |
---|
1552 | $company->set_company_name($company_fields['company_name']); |
---|
1553 | $company->set_field('id_company_owner',$GLOBALS['phpgw_info']['user']['account_id']); |
---|
1554 | $company_fields['id_company'] = $company->commit(); |
---|
1555 | } |
---|
1556 | } |
---|
1557 | |
---|
1558 | $contact->set_company($company_fields); |
---|
1559 | } |
---|
1560 | break; |
---|
1561 | |
---|
1562 | case 'relations': |
---|
1563 | foreach($value as $relation_fields) |
---|
1564 | { |
---|
1565 | $contact->set_relation($relation_fields['id_relation'], $relation_fields['id_typeof_relation']); |
---|
1566 | } |
---|
1567 | break; |
---|
1568 | |
---|
1569 | case 'addresses': |
---|
1570 | if(is_array($value)) |
---|
1571 | foreach($value as $address_name => $address_fields) |
---|
1572 | { |
---|
1573 | if ($address_fields['id_address'] && $address_fields['id_address'] !== '') |
---|
1574 | { |
---|
1575 | $address = CreateObject('contactcenter.so_address', $address_fields['id_address']); |
---|
1576 | } |
---|
1577 | else |
---|
1578 | { |
---|
1579 | $address = CreateObject('contactcenter.so_address'); |
---|
1580 | $address->reset_values(); |
---|
1581 | } |
---|
1582 | |
---|
1583 | if (!isset($address_fields['id_country']) or $address_fields['id_country'] === false) |
---|
1584 | { |
---|
1585 | #var_dump($address_fields); |
---|
1586 | echo(serialize(array( |
---|
1587 | 'file' => __FILE__, |
---|
1588 | 'line' => __LINE__, |
---|
1589 | 'msg' => lang('An Address must have at least a Country'), |
---|
1590 | 'status' => 'aborted' |
---|
1591 | ))); |
---|
1592 | return; |
---|
1593 | } |
---|
1594 | |
---|
1595 | foreach ($address_fields as $f_name => $f_value) |
---|
1596 | { |
---|
1597 | if ($f_value === false) |
---|
1598 | { |
---|
1599 | $address->set_field($f_name, null); |
---|
1600 | } |
---|
1601 | elseif (isset($f_value)) |
---|
1602 | { |
---|
1603 | $address->set_field($f_name, $f_value); |
---|
1604 | } |
---|
1605 | } |
---|
1606 | |
---|
1607 | $address->commit(); |
---|
1608 | $id_address = $address->get_id(); |
---|
1609 | $contact->set_address($id_address, $address_fields['id_typeof_address']); |
---|
1610 | } |
---|
1611 | break; |
---|
1612 | |
---|
1613 | case 'connections': |
---|
1614 | //alteracao para permitir a exibicao de contatos sem email ou telefone |
---|
1615 | $all_removed = true; |
---|
1616 | $added_connection = false; |
---|
1617 | foreach($value as $connection_name => $connection_fields) |
---|
1618 | { |
---|
1619 | if ($connection_name === 'removed_conns') |
---|
1620 | { |
---|
1621 | foreach($connection_fields as $id) |
---|
1622 | { |
---|
1623 | $connection = CreateObject('contactcenter.so_connection', $id); |
---|
1624 | if (!($connection->remove())) |
---|
1625 | { |
---|
1626 | return false; |
---|
1627 | } |
---|
1628 | |
---|
1629 | $contact->remove_connection($id); |
---|
1630 | } |
---|
1631 | |
---|
1632 | continue; |
---|
1633 | } |
---|
1634 | |
---|
1635 | $all_removed = false; |
---|
1636 | // removes the dummy if there is at least one connection |
---|
1637 | if (!$added_connection) |
---|
1638 | { |
---|
1639 | $this->remove_dummy($contact); //remove the dummy |
---|
1640 | } |
---|
1641 | $added_connection = true; |
---|
1642 | $id_connection = $connection_fields['id_connection']; |
---|
1643 | if ($id_connection === '_NEW_' or |
---|
1644 | $id_connection === '') |
---|
1645 | { |
---|
1646 | $connection = CreateObject('contactcenter.so_connection'); |
---|
1647 | $connection->reset_values(); |
---|
1648 | } |
---|
1649 | else |
---|
1650 | { |
---|
1651 | $connection = CreateObject('contactcenter.so_connection', $id_connection); |
---|
1652 | } |
---|
1653 | |
---|
1654 | foreach($connection_fields as $a_field => $a_value) |
---|
1655 | { |
---|
1656 | if ($a_field !== 'id_typeof_connection') |
---|
1657 | { |
---|
1658 | $connection->set_field($a_field,$a_value); |
---|
1659 | } |
---|
1660 | } |
---|
1661 | |
---|
1662 | if (!$connection->commit()) |
---|
1663 | { |
---|
1664 | return false; |
---|
1665 | } |
---|
1666 | $id_connection = $connection->get_id(); |
---|
1667 | $contact->set_connection($id_connection, $connection_fields['id_typeof_connection']); |
---|
1668 | } |
---|
1669 | // add the dummy if there is no other connection |
---|
1670 | if ($all_removed) |
---|
1671 | $this->add_dummy($contact); |
---|
1672 | break; |
---|
1673 | |
---|
1674 | default: |
---|
1675 | echo 'Invalid Field: '.$field.'<br>Value: '.$value; |
---|
1676 | return false; |
---|
1677 | } |
---|
1678 | } |
---|
1679 | |
---|
1680 | if ($altered) |
---|
1681 | { |
---|
1682 | $contact->set_field("last_status", 'U'); |
---|
1683 | $contact->set_field("last_update",time()."000"); |
---|
1684 | return $contact->commit(); |
---|
1685 | } |
---|
1686 | |
---|
1687 | return false; |
---|
1688 | } |
---|
1689 | |
---|
1690 | /*! |
---|
1691 | @function remove_dummy |
---|
1692 | @abstract Remove the dummy connection entry. |
---|
1693 | @author Luiz Carlos Viana Melo - Prognus |
---|
1694 | */ |
---|
1695 | function remove_dummy($so_contact) |
---|
1696 | { |
---|
1697 | //$so_contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
1698 | $connections = $so_contact->get_connections(); |
---|
1699 | foreach ($connections as $id_connection => $type_connection) |
---|
1700 | { |
---|
1701 | $so_connection = CreateObject('contactcenter.so_connection', $id_connection); |
---|
1702 | if ($so_connection->get_field('connection_name') === 'no_conns') //if connection is the dummy one |
---|
1703 | { |
---|
1704 | if (!$so_connection->remove()) |
---|
1705 | { |
---|
1706 | return false; |
---|
1707 | } |
---|
1708 | $so_contact->remove_connection($id_connection); |
---|
1709 | //$so_connection->commit(); |
---|
1710 | break; |
---|
1711 | } |
---|
1712 | } |
---|
1713 | |
---|
1714 | } |
---|
1715 | |
---|
1716 | /*! |
---|
1717 | @function add_dummy |
---|
1718 | @abstract Add a dummy connection entry on a contact. This is necessary for |
---|
1719 | possibility on adding a contact that dont have an email or telephone. |
---|
1720 | @return The dummy's connection ID. |
---|
1721 | @author Luiz Carlos Viana Melo - Prognus |
---|
1722 | */ |
---|
1723 | function add_dummy($so_contact) |
---|
1724 | { |
---|
1725 | $so_connection = CreateObject('contactcenter.so_connection'); |
---|
1726 | $so_connection->reset_values(); |
---|
1727 | |
---|
1728 | $so_connection->set_field('connection_name', 'no_conns'); //defined code for the dummy connection |
---|
1729 | $so_connection->set_field('connection_value', ''); |
---|
1730 | $so_connection->set_field('connection_is_default', true); |
---|
1731 | |
---|
1732 | if (!$so_connection->commit()) |
---|
1733 | { |
---|
1734 | return false; |
---|
1735 | } |
---|
1736 | $id_connection = $so_connection->get_id(); |
---|
1737 | $so_contact->set_connection($id_connection, 2); |
---|
1738 | return $id_connection; |
---|
1739 | } |
---|
1740 | |
---|
1741 | /*! |
---|
1742 | |
---|
1743 | @function update_prefix |
---|
1744 | @abstract Update an existing Prefix |
---|
1745 | @author Raphael Derosso Pereira |
---|
1746 | |
---|
1747 | @param integer $id_prefix The Prefix ID |
---|
1748 | @param string $prefix The new Prefix value |
---|
1749 | |
---|
1750 | */ |
---|
1751 | function update_prefix ( $id_prefix, $prefix ) |
---|
1752 | { |
---|
1753 | $permissions = $this->security->get_type_permissions(); |
---|
1754 | |
---|
1755 | if (!$permissions['alter']) |
---|
1756 | { |
---|
1757 | return false; |
---|
1758 | } |
---|
1759 | } |
---|
1760 | |
---|
1761 | /*! |
---|
1762 | |
---|
1763 | @function update_suffix |
---|
1764 | @abstract Update an existing suffix |
---|
1765 | @author Raphael Derosso Pereira |
---|
1766 | |
---|
1767 | @param integer $id_suffix The suffix ID |
---|
1768 | @param string $suffix The new suffix value |
---|
1769 | |
---|
1770 | */ |
---|
1771 | function update_suffix ( $id_suffix, $suffix ) |
---|
1772 | { |
---|
1773 | $permissions = $this->security->get_type_permissions(); |
---|
1774 | |
---|
1775 | if (!$permissions['alter']) |
---|
1776 | { |
---|
1777 | return false; |
---|
1778 | } |
---|
1779 | } |
---|
1780 | |
---|
1781 | /*! |
---|
1782 | |
---|
1783 | @function update_status |
---|
1784 | @abstract Update an existing Status |
---|
1785 | @author Raphael Derosso Pereira |
---|
1786 | |
---|
1787 | @param integer $id_status The Status ID |
---|
1788 | @param string $status The new Status value |
---|
1789 | |
---|
1790 | */ |
---|
1791 | function update_status ( $id_status, $status ) |
---|
1792 | { |
---|
1793 | $permissions = $this->security->get_type_permissions(); |
---|
1794 | |
---|
1795 | if (!$permissions['alter']) |
---|
1796 | { |
---|
1797 | return false; |
---|
1798 | } |
---|
1799 | } |
---|
1800 | |
---|
1801 | /*! |
---|
1802 | |
---|
1803 | @function update_relation_type |
---|
1804 | @abstract Update an existing Relation Type |
---|
1805 | @author Raphael Derosso Pereira |
---|
1806 | |
---|
1807 | @param integer $id_type The Type ID |
---|
1808 | @param string $type The new type value |
---|
1809 | |
---|
1810 | */ |
---|
1811 | function update_relation_type ( $old_name, $relation_name ) |
---|
1812 | { |
---|
1813 | } |
---|
1814 | |
---|
1815 | /*! |
---|
1816 | |
---|
1817 | @function update_address_type |
---|
1818 | @abstract Update an existing Address Type |
---|
1819 | @author Raphael Derosso Pereira |
---|
1820 | |
---|
1821 | @param integer $id_uype The Type ID |
---|
1822 | @param string $type The new type value |
---|
1823 | |
---|
1824 | */ |
---|
1825 | function update_address_type ( $id_type, $type ) |
---|
1826 | { |
---|
1827 | } |
---|
1828 | |
---|
1829 | /*! |
---|
1830 | |
---|
1831 | @function update_connection_type |
---|
1832 | @abstract Update an existing Connection Type |
---|
1833 | @author Raphael Derosso Pereira |
---|
1834 | |
---|
1835 | @param integer $id_type The Type ID |
---|
1836 | @param string $type The new type value |
---|
1837 | |
---|
1838 | */ |
---|
1839 | function update_connection_type ( $id_type, $type ) |
---|
1840 | { |
---|
1841 | } |
---|
1842 | |
---|
1843 | |
---|
1844 | /*********************************************************************\ |
---|
1845 | * Methods to Remove Data * |
---|
1846 | \*********************************************************************/ |
---|
1847 | |
---|
1848 | /*! |
---|
1849 | |
---|
1850 | @function remove_single_entry |
---|
1851 | @abstract Remove one contact from the DB |
---|
1852 | @author Raphael Derosso Pereira |
---|
1853 | |
---|
1854 | @param integer $id_contact The Contact ID |
---|
1855 | |
---|
1856 | */ |
---|
1857 | function remove_single_entry ( $id_contact ) |
---|
1858 | { |
---|
1859 | $permissions = $this->security->get_permissions(); |
---|
1860 | |
---|
1861 | if (!$permissions['remove']) |
---|
1862 | { |
---|
1863 | return false; |
---|
1864 | } |
---|
1865 | |
---|
1866 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
1867 | |
---|
1868 | if ($contact->get_state() === 'new') |
---|
1869 | { |
---|
1870 | return false; |
---|
1871 | } |
---|
1872 | |
---|
1873 | $addresses = $contact->get_addresses(); |
---|
1874 | $connections = $contact->get_connections(); |
---|
1875 | |
---|
1876 | if (!$contact->remove()) |
---|
1877 | { |
---|
1878 | return false; |
---|
1879 | } |
---|
1880 | |
---|
1881 | foreach ($addresses as $id => $type) |
---|
1882 | { |
---|
1883 | if (!($address = CreateObject('contactcenter.so_address', $id))) |
---|
1884 | { |
---|
1885 | return false; |
---|
1886 | } |
---|
1887 | |
---|
1888 | if (!($address->remove())) |
---|
1889 | { |
---|
1890 | return false; |
---|
1891 | } |
---|
1892 | |
---|
1893 | } |
---|
1894 | $groups = CreateObject('contactcenter.so_group'); |
---|
1895 | |
---|
1896 | foreach ($connections as $id => $type) |
---|
1897 | { |
---|
1898 | if (!($connection = CreateObject('contactcenter.so_connection',$id))) |
---|
1899 | { |
---|
1900 | return false; |
---|
1901 | } |
---|
1902 | $groups->deleteContactFromGroups($id); |
---|
1903 | if (!($connection->remove())) |
---|
1904 | { |
---|
1905 | return false; |
---|
1906 | } |
---|
1907 | |
---|
1908 | } |
---|
1909 | |
---|
1910 | return true; |
---|
1911 | } |
---|
1912 | } |
---|
1913 | ?> |
---|