1 | <?php |
---|
2 | |
---|
3 | class ContactsResource extends CatalogAdapter { |
---|
4 | public function post($request){ |
---|
5 | // to Receive POST Params (use $this->params) |
---|
6 | parent::post($request); |
---|
7 | |
---|
8 | if($this-> isLoggedIn()) |
---|
9 | { |
---|
10 | |
---|
11 | if($this->getParams()) { |
---|
12 | $search = trim($this->getParam('search')); |
---|
13 | $search = ($search ? mb_convert_encoding($search,"ISO_8859-1", "UTF8") : ""); |
---|
14 | $contactID = $this->getParam('contactID'); |
---|
15 | |
---|
16 | $search_string = "%$search%"; |
---|
17 | |
---|
18 | $arr_params = array(); |
---|
19 | |
---|
20 | if($this->getParam('contactType') == 1) { |
---|
21 | if($search != "") { |
---|
22 | $arr_params[] = $search_string; |
---|
23 | $arr_params[] = $search_string; |
---|
24 | $arr_params[] = $search_string; |
---|
25 | $query_contact = "(A.alias ilike ? or A.names_ordered ilike ? or C.connection_value ilike ?) and"; |
---|
26 | } |
---|
27 | elseif($this->getParam('contactID') > 0){ |
---|
28 | $arr_params[] = $contactID; |
---|
29 | $query_contact = "A.id_contact = ? and "; |
---|
30 | } |
---|
31 | } |
---|
32 | elseif($this->getParam('contactType') == 2){ |
---|
33 | if($this-> getMinArgumentSearch() <= strlen($search)) |
---|
34 | return $this->getGlobalContacts($search, $contactID ); |
---|
35 | else{ |
---|
36 | Errors::runException("CATALOG_MIN_ARGUMENT_SEARCH", $this-> getMinArgumentSearch()); |
---|
37 | } |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | //ADICIONA O ID_OWNER |
---|
42 | $arr_params[] = $this->getUserId(); |
---|
43 | |
---|
44 | $query = 'select |
---|
45 | B.id_typeof_contact_connection, |
---|
46 | A.photo, |
---|
47 | A.id_contact, |
---|
48 | A.alias, |
---|
49 | A.given_names, |
---|
50 | A.family_names, |
---|
51 | A.names_ordered, |
---|
52 | A.birthdate, |
---|
53 | A.notes, |
---|
54 | C.connection_value |
---|
55 | from |
---|
56 | phpgw_cc_contact A, |
---|
57 | phpgw_cc_contact_conns B, |
---|
58 | phpgw_cc_connections C |
---|
59 | where |
---|
60 | A.id_contact = B.id_contact and |
---|
61 | B.id_connection = C.id_connection and |
---|
62 | '.$query_contact.' |
---|
63 | A.id_owner = ? |
---|
64 | group by |
---|
65 | B.id_typeof_contact_connection, |
---|
66 | A.photo, |
---|
67 | A.id_contact, |
---|
68 | A.alias, |
---|
69 | A.given_names, |
---|
70 | A.family_names, |
---|
71 | A.names_ordered, |
---|
72 | A.birthdate, |
---|
73 | A.notes, |
---|
74 | C.connection_value |
---|
75 | order by |
---|
76 | lower(A.names_ordered)'; |
---|
77 | |
---|
78 | $resQuery = $this->getDb()->Link_ID->query($query,$arr_params); |
---|
79 | |
---|
80 | $contacts = array(); |
---|
81 | while($row = $resQuery->fetchRow()) { |
---|
82 | |
---|
83 | $id = $row['id_contact']; |
---|
84 | $contactType = ($row['id_typeof_contact_connection'] == 2 ? 'contactPhones' : 'contactMails'); |
---|
85 | |
---|
86 | if($contacts[$id] != null){ |
---|
87 | $contacts[$id][$contactType][] = $row['connection_value']; |
---|
88 | } |
---|
89 | else{ |
---|
90 | $contacts[$id] = array( |
---|
91 | 'contactID' => $row['id_contact'], |
---|
92 | $contactType => array($row['connection_value']), |
---|
93 | 'contactAlias' => ($row['alias'] != null ? mb_convert_encoding($row['alias'],"UTF8", "ISO_8859-1") : ""), |
---|
94 | 'contactFirstName' => ($row['given_names'] != null ? mb_convert_encoding($row['given_names'],"UTF8", "ISO_8859-1") : ""), |
---|
95 | 'contactLastName' => ($row['family_names'] != null ? mb_convert_encoding($row['family_names'],"UTF8", "ISO_8859-1") : ""), |
---|
96 | 'contactFullName' => ($row['names_ordered'] != null ? mb_convert_encoding($row['names_ordered'],"UTF8", "ISO_8859-1") : ""), |
---|
97 | 'contactBirthDate' => ($row['birthdate'] != null ? $row['birthdate'] : ""), |
---|
98 | 'contactNotes' => ($row['notes'] != null ? mb_convert_encoding($row['notes'],"UTF8", "ISO_8859-1") : ""), |
---|
99 | 'contactHasImagePicture' => ($row['photo'] != null ? 1 : 0), |
---|
100 | ); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | $result = array ( 'contacts' => array_values($contacts)); |
---|
105 | $this->setResult($result); |
---|
106 | } |
---|
107 | //to Send Response (JSON RPC format) |
---|
108 | return $this->getResponse(); |
---|
109 | } |
---|
110 | |
---|
111 | } |
---|