[2] | 1 | <?php |
---|
| 2 | /***************************************************************************\ |
---|
| 3 | * eGroupWare - Contacts Center * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * Storage Object Classes * |
---|
| 6 | * Written by: * |
---|
| 7 | * - Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br> * |
---|
| 8 | * sponsored by Celepar - http://celepar.pr.gov.br * |
---|
| 9 | * ------------------------------------------------------------------------- * |
---|
| 10 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 11 | * under the terms of the GNU General Public License as published by the * |
---|
| 12 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 13 | * option) any later version. * |
---|
| 14 | \***************************************************************************/ |
---|
| 15 | class so_group { |
---|
| 16 | |
---|
| 17 | var $db; |
---|
| 18 | var $owner; |
---|
| 19 | |
---|
| 20 | function so_group () |
---|
| 21 | { |
---|
| 22 | $this->db = $GLOBALS['phpgw']->db; |
---|
| 23 | $this->owner = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | function select($id = '') |
---|
| 27 | { |
---|
[752] | 28 | $query = 'SELECT id_group,title,short_name FROM phpgw_cc_groups '; |
---|
[2] | 29 | if($id != '') |
---|
[752] | 30 | $query .= 'WHERE id_group ='.$id; |
---|
[2] | 31 | |
---|
| 32 | $query .= ' ORDER BY title'; |
---|
| 33 | |
---|
| 34 | if (!$this->db->query($query)) |
---|
| 35 | { |
---|
| 36 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | $return = false; |
---|
| 40 | |
---|
| 41 | while($this->db->next_record()) |
---|
| 42 | { |
---|
| 43 | $return[] = $this->db->row(); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | return $return; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | function remove_accents($string) { |
---|
| 50 | return strtr($string, |
---|
| 51 | "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ", |
---|
| 52 | "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | function insert($data) |
---|
| 56 | { |
---|
[3348] | 57 | $this->db->query("select * from phpgw_cc_groups where |
---|
| 58 | upper(title) like '".strtoupper($data['title'])."' and owner=".$this->owner); |
---|
| 59 | if($this->db->next_record()) |
---|
| 60 | return false;//Não posso criar grupos com nomes iguais |
---|
[2] | 61 | $shortName = $this -> remove_accents(strtolower(str_replace(" ","", $data['title']))); |
---|
| 62 | |
---|
| 63 | $query = "INSERT INTO phpgw_cc_groups(title, owner,short_name) ". |
---|
| 64 | "VALUES('".$data['title']."',".$this->owner.",'".$shortName."')"; |
---|
| 65 | |
---|
| 66 | if (!$this->db->query($query)) |
---|
| 67 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 68 | |
---|
| 69 | $objSequence = $this->db->query("SELECT last_value FROM seq_phpgw_cc_groups"); |
---|
| 70 | $id = $objSequence -> fields['last_value']; |
---|
| 71 | $this -> updateContactsByGroup($id, $data['contact_in_list']); |
---|
| 72 | |
---|
| 73 | return $id; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | function update($data) |
---|
| 77 | { |
---|
[3348] | 78 | $this->db->query("select * from phpgw_cc_groups where |
---|
| 79 | id_group!='".$data['id_group']."' and |
---|
| 80 | upper(title) like '".strtoupper($data['title'])."' and owner=".$this->owner); |
---|
| 81 | if($this->db->next_record()) |
---|
| 82 | return false;//Não posso criar grupos com nomes iguais |
---|
[2] | 83 | $shortName = $this -> remove_accents(strtolower(str_replace(" ","", $data['title']))); |
---|
| 84 | |
---|
| 85 | $query = "UPDATE phpgw_cc_groups SET title = '".$data['title']."',short_name = '".$shortName."' WHERE id_group = ".$data['id_group']; |
---|
| 86 | |
---|
| 87 | if (!$this->db->query($query)) |
---|
| 88 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 89 | |
---|
| 90 | $this -> updateContactsByGroup($data['id_group'], $data['contact_in_list']); |
---|
| 91 | |
---|
| 92 | return True; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | function delete($data) |
---|
| 96 | { |
---|
| 97 | $query = "DELETE FROM phpgw_cc_groups WHERE id_group = ".$data['id_group']; |
---|
| 98 | |
---|
| 99 | if (!$this->db->query($query)) |
---|
| 100 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 101 | |
---|
| 102 | $this -> deleteContactsByGroup($data['id_group'], $data['contact_in_list']); |
---|
| 103 | |
---|
| 104 | return True; |
---|
| 105 | } |
---|
| 106 | |
---|
[4498] | 107 | /*! |
---|
| 108 | * @function select_owner_groups |
---|
| 109 | * @abstract Busca todos os grupos do usuário atual. |
---|
| 110 | * @author Luiz Carlos Viana Melo - Prognus |
---|
| 111 | * @param (integer) $id_owner O ID do usuário. |
---|
| 112 | * @return Retorna uma estrutura contendo: |
---|
| 113 | * array( |
---|
| 114 | * array( |
---|
| 115 | * id_group => O ID do grupo; |
---|
| 116 | * title => O nome do grupo; |
---|
| 117 | * short_name => O nome abreviado do grupo. |
---|
| 118 | * ) |
---|
| 119 | * ) |
---|
| 120 | */ |
---|
| 121 | function select_owner_groups($id_owner = false) |
---|
| 122 | { |
---|
| 123 | $query = 'SELECT id_group, title, short_name FROM phpgw_cc_groups '; |
---|
| 124 | if ($id_owner) |
---|
| 125 | $query .= 'WHERE owner = ' . $id_owner. ' ORDER BY title;'; |
---|
| 126 | else |
---|
| 127 | $query .= 'WHERE owner = ' . $this->owner . ' ORDER BY title;'; |
---|
| 128 | |
---|
| 129 | if (!$this->db->query($query)) |
---|
| 130 | { |
---|
| 131 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | $return = false; |
---|
| 135 | |
---|
| 136 | while($this->db->next_record()) |
---|
| 137 | { |
---|
| 138 | $return[] = $this->db->row(); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | return $return; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /*! |
---|
| 145 | * @function select_contact_groups |
---|
| 146 | * @abstract Seleciona os grupos do contato. |
---|
| 147 | * @author Luiz Carlos Viana Melo - Prognus |
---|
| 148 | * @param (integer) $id_contact O ID do contato. |
---|
| 149 | * @return Retorna uma estrutura contendo: |
---|
| 150 | * array( |
---|
| 151 | * array( |
---|
| 152 | * id_contact => O ID do contato; |
---|
| 153 | * id_group => O ID do grupo; |
---|
| 154 | * title => O nome do grupo; |
---|
| 155 | * short_name => O nome abreviado do grupo. |
---|
| 156 | * ) |
---|
| 157 | * ) |
---|
| 158 | */ |
---|
| 159 | function select_contact_groups($id_contact) |
---|
| 160 | { |
---|
| 161 | $query = 'SELECT Contato.id_contact, ContatoGprs.id_connection, Grupos.id_group, Grupos.title, ' . |
---|
| 162 | 'Grupos.short_name FROM phpgw_cc_contact_conns Contato, ' . |
---|
| 163 | 'phpgw_cc_connections Conexao, phpgw_cc_contact_grps ContatoGprs, ' . |
---|
| 164 | 'phpgw_cc_groups Grupos WHERE Contato.id_contact = ' . $id_contact . |
---|
| 165 | ' AND Contato.id_connection = Conexao.id_connection AND ' . |
---|
| 166 | 'Conexao.id_connection = ContatoGprs.id_connection AND ' . |
---|
| 167 | 'ContatoGprs.id_group = Grupos.id_group ORDER BY title'; |
---|
| 168 | |
---|
| 169 | if (!$this->db->query($query)) |
---|
| 170 | { |
---|
| 171 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | $return = false; |
---|
| 175 | |
---|
| 176 | while($this->db->next_record()) |
---|
| 177 | { |
---|
| 178 | $return[] = $this->db->row(); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | return $return; |
---|
| 182 | } |
---|
| 183 | |
---|
[2] | 184 | function deleteContactFromGroups($id) |
---|
| 185 | { |
---|
| 186 | $query = "DELETE FROM phpgw_cc_contact_grps WHERE id_connection = ".$id; |
---|
| 187 | |
---|
| 188 | if (!$this->db->query($query)) |
---|
| 189 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 190 | |
---|
| 191 | return True; |
---|
| 192 | } |
---|
| 193 | |
---|
[3334] | 194 | function selectGroupsOwnerCanImportContacts($owner) { |
---|
[3344] | 195 | $query = "select id_group,title,short_name from phpgw_cc_groups where owner=$owner or owner in (select B.acl_location::bigint from phpgw_acl A, phpgw_acl B where |
---|
| 196 | A.acl_location=B.acl_account::text and A.acl_account::text=B.acl_location |
---|
| 197 | and A.acl_appname = 'contactcenter' and B.acl_appname = 'contactcenter' |
---|
| 198 | and A.acl_rights & 4 <> 0 and B.acl_rights & 1 <> 0 |
---|
| 199 | and A.acl_location = '".$owner."')"; //He can import contacts only to his groups, or shared groups that he gave read permission. |
---|
| 200 | |
---|
[3334] | 201 | $this->db->query($query); |
---|
| 202 | |
---|
| 203 | $return = array(); |
---|
| 204 | |
---|
| 205 | while($this->db->next_record()) |
---|
| 206 | { |
---|
| 207 | $return[] = $this->db->row(); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | return $return; |
---|
| 211 | |
---|
| 212 | } |
---|
| 213 | |
---|
[1280] | 214 | //Owner = null means the owner setted on constructor. |
---|
| 215 | function selectAllContacts( $field = false ,$shared_from=null) |
---|
[2] | 216 | { |
---|
[3215] | 217 | if ( $shared_from == NULL ) |
---|
| 218 | { |
---|
[3216] | 219 | $query = 'select' |
---|
[4470] | 220 | . ' C.id_connection,' |
---|
| 221 | . ' A.id_contact,' |
---|
| 222 | . ' A.names_ordered,' |
---|
| 223 | . ' A.alias,' |
---|
| 224 | . ' A.birthdate,' |
---|
| 225 | . ' A.sex,' |
---|
| 226 | . ' A.pgp_key,' |
---|
| 227 | . ' A.notes,' |
---|
| 228 | . ' A.web_page,' |
---|
| 229 | . ' A.corporate_name,' |
---|
| 230 | . ' A.job_title,' |
---|
| 231 | . ' A.department,' |
---|
| 232 | . ' C.connection_name,' |
---|
| 233 | . ' C.connection_value,' |
---|
| 234 | . ' B.id_typeof_contact_connection,' |
---|
[3216] | 235 | . ' phpgw_cc_contact_addrs.id_typeof_contact_address,' |
---|
| 236 | . ' phpgw_cc_addresses.address1,' |
---|
[3322] | 237 | . ' phpgw_cc_addresses.address2,' |
---|
[3216] | 238 | . ' phpgw_cc_addresses.complement,' |
---|
| 239 | . ' phpgw_cc_addresses.postal_code,' |
---|
| 240 | . ' phpgw_cc_city.city_name,' |
---|
| 241 | . ' phpgw_cc_state.state_name,' |
---|
[3217] | 242 | . ' phpgw_cc_addresses.id_country' |
---|
| 243 | ; |
---|
[3215] | 244 | |
---|
[3216] | 245 | $query .= ' from' |
---|
[4355] | 246 | . ' phpgw_cc_contact A' |
---|
| 247 | . ' inner join phpgw_cc_contact_conns B on ( A.id_contact = B.id_contact )' |
---|
| 248 | . ' inner join phpgw_cc_connections C on ( B.id_connection = C.id_connection )' |
---|
| 249 | . ' left join phpgw_cc_contact_addrs on ( A.id_contact = phpgw_cc_contact_addrs.id_contact )' |
---|
[3216] | 250 | . ' left join phpgw_cc_addresses on ( phpgw_cc_contact_addrs.id_address = phpgw_cc_addresses.id_address )' |
---|
| 251 | . ' left join phpgw_cc_city on ( phpgw_cc_addresses.id_city = phpgw_cc_city.id_city )' |
---|
[3217] | 252 | . ' left join phpgw_cc_state on ( phpgw_cc_addresses.id_state = phpgw_cc_state.id_state)' |
---|
| 253 | ; |
---|
[3215] | 254 | |
---|
[3216] | 255 | $query .= ' where' |
---|
[4355] | 256 | . " A.id_owner = {$this->owner}" |
---|
[3217] | 257 | //. ' and phpgw_cc_connections.connection_is_default = true' |
---|
| 258 | ; |
---|
[3215] | 259 | |
---|
[1280] | 260 | } |
---|
| 261 | else { |
---|
| 262 | $sub_query = 'select A.id_related from phpgw_cc_contact_rels A,phpgw_acl B |
---|
| 263 | where B.acl_location!=\'run\' and A.id_contact = B.acl_location::bigint and A.id_related = B.acl_account and |
---|
| 264 | B.acl_appname = \'contactcenter\' and B.acl_rights & 1 <> 0 |
---|
| 265 | and A.id_typeof_contact_relation=1 and A.id_contact = '.$shared_from.' and A.id_related='.$this->owner; |
---|
[3215] | 266 | |
---|
[1280] | 267 | $query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value , B.id_typeof_contact_connection from phpgw_cc_contact A,'. |
---|
| 268 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C where '. |
---|
| 269 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection and '. |
---|
| 270 | 'A.id_owner in ('.$shared_from.',('.$sub_query.'))'. |
---|
| 271 | ' and C.connection_is_default = true '; |
---|
| 272 | } |
---|
[16] | 273 | |
---|
[702] | 274 | if ( $field == 'only_email' ) |
---|
[4355] | 275 | $query .= 'and B.id_typeof_contact_connection = 1 '; |
---|
[702] | 276 | |
---|
[4355] | 277 | $query .= ' order by A.names_ordered, C.connection_value'; |
---|
[702] | 278 | |
---|
[2] | 279 | if (!$this->db->query($query)) |
---|
| 280 | { |
---|
| 281 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 282 | } |
---|
[3215] | 283 | |
---|
[576] | 284 | $return = array(); |
---|
[3215] | 285 | |
---|
[2] | 286 | while($this->db->next_record()) |
---|
| 287 | { |
---|
| 288 | $return[] = $this->db->row(); |
---|
| 289 | } |
---|
[3215] | 290 | |
---|
| 291 | if( ! count( $return ) ) |
---|
| 292 | return $return; |
---|
| 293 | |
---|
[4121] | 294 | $all_contacts = array(); |
---|
[3215] | 295 | foreach( $return as $i => $object ) |
---|
| 296 | { |
---|
[3216] | 297 | if ( ! array_key_exists( $object[ 'id_contact' ], $all_contacts ) ) |
---|
| 298 | $all_contacts[ $object[ 'id_contact' ] ] = array( |
---|
| 299 | 'connection_value' => '', |
---|
| 300 | 'phone' => '', |
---|
[3217] | 301 | 'mobile' => '', |
---|
[3216] | 302 | 'names_ordered' => '', |
---|
| 303 | 'id_contact' => '', |
---|
| 304 | 'id_connection' => '', |
---|
| 305 | 'alias' => '', |
---|
[3322] | 306 | 'birthdate' => '', |
---|
| 307 | 'sex' => '', |
---|
| 308 | 'pgp_key' => '', |
---|
| 309 | 'notes' => '', |
---|
| 310 | 'web_page' => '', |
---|
| 311 | 'corporate_name' => '', |
---|
| 312 | 'job_title' => '', |
---|
| 313 | 'department' => '', |
---|
[3217] | 314 | 'main-mail' => '', |
---|
| 315 | 'aternative-mail' => '', |
---|
| 316 | 'business-phone' => '', |
---|
[3216] | 317 | 'business-address' => '', |
---|
[3217] | 318 | 'business-complement' => '', |
---|
| 319 | 'business-postal_code' => '', |
---|
| 320 | 'business-city_name' => '', |
---|
| 321 | 'business-state_name' => '', |
---|
| 322 | 'business-id_country' => '', |
---|
[3322] | 323 | 'business-fax' => '', |
---|
| 324 | 'business-pager' => '', |
---|
| 325 | 'business-mobile' => '', |
---|
| 326 | 'business-address-2' => '', |
---|
[3217] | 327 | 'home-phone' => '', |
---|
[3216] | 328 | 'home-address' => '', |
---|
[3217] | 329 | 'home-complement' => '', |
---|
| 330 | 'home-postal_code' => '', |
---|
| 331 | 'home-city_name' => '', |
---|
| 332 | 'home-state_name' => '', |
---|
[3322] | 333 | 'home-fax' => '', |
---|
| 334 | 'home-pager' => '', |
---|
| 335 | 'home-address-2' => '' |
---|
| 336 | |
---|
| 337 | |
---|
[3216] | 338 | ); |
---|
| 339 | |
---|
[3215] | 340 | switch( $object[ 'id_typeof_contact_connection' ] ) |
---|
| 341 | { |
---|
| 342 | case 1 : |
---|
| 343 | $all_contacts[ $object[ 'id_contact' ] ][ 'connection_value' ] = $object[ 'connection_value' ]; |
---|
[3217] | 344 | switch ( strtolower( $object[ 'connection_name' ] ) ) |
---|
| 345 | { |
---|
| 346 | case 'alternativo' : |
---|
| 347 | $all_contacts[ $object[ 'id_contact' ] ][ 'alternative-mail' ] = $object[ 'connection_value' ]; |
---|
| 348 | break; |
---|
| 349 | case 'principal' : |
---|
| 350 | $all_contacts[ $object[ 'id_contact' ] ][ 'main-mail' ] = $object[ 'connection_value' ]; |
---|
| 351 | break; |
---|
| 352 | } |
---|
[3215] | 353 | break; |
---|
| 354 | case 2 : |
---|
| 355 | $all_contacts[ $object[ 'id_contact' ] ][ 'phone' ] = $object[ 'connection_value' ]; |
---|
[3217] | 356 | switch ( strtolower( $object[ 'connection_name' ] ) ) |
---|
| 357 | { |
---|
| 358 | case 'casa' : |
---|
| 359 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-phone' ] = $object[ 'connection_value' ]; |
---|
| 360 | break; |
---|
| 361 | case 'celular' : |
---|
| 362 | $all_contacts[ $object[ 'id_contact' ] ][ 'mobile' ] = $object[ 'connection_value' ]; |
---|
| 363 | break; |
---|
| 364 | case 'trabalho' : |
---|
| 365 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-phone' ] = $object[ 'connection_value' ]; |
---|
[3322] | 366 | break; |
---|
| 367 | case 'fax' : |
---|
| 368 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-fax' ] = $object[ 'connection_value' ]; |
---|
[3217] | 369 | break; |
---|
[3322] | 370 | case 'pager' : |
---|
| 371 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-pager' ] = $object[ 'connection_value' ]; |
---|
| 372 | break; |
---|
| 373 | case 'celular corporativo' : |
---|
| 374 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-mobile' ] = $object[ 'connection_value' ]; |
---|
| 375 | break; |
---|
| 376 | case 'pager corporativo' : |
---|
| 377 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-pager' ] = $object[ 'connection_value' ]; |
---|
| 378 | break; |
---|
| 379 | case 'fax corporativo' : |
---|
| 380 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-fax' ] = $object[ 'connection_value' ]; |
---|
| 381 | break; |
---|
[3217] | 382 | } |
---|
[3215] | 383 | break; |
---|
[293] | 384 | } |
---|
[3215] | 385 | |
---|
| 386 | $all_contacts[ $object[ 'id_contact' ] ][ 'names_ordered' ] = $object[ 'names_ordered' ]; |
---|
| 387 | $all_contacts[ $object[ 'id_contact' ] ][ 'id_contact' ] = $object[ 'id_contact' ]; |
---|
| 388 | $all_contacts[ $object[ 'id_contact' ] ][ 'id_connection' ] = $object[ 'id_connection' ]; |
---|
[3322] | 389 | $all_contacts[ $object[ 'id_contact' ] ][ 'alias' ] = $object[ 'alias' ]; |
---|
| 390 | $all_contacts[ $object[ 'id_contact' ] ][ 'birthdate' ] = $object[ 'birthdate' ]; |
---|
| 391 | $all_contacts[ $object[ 'id_contact' ] ][ 'sex' ] = $object[ 'sex' ]; |
---|
| 392 | $all_contacts[ $object[ 'id_contact' ] ][ 'pgp_key' ] = $object[ 'pgp_key' ]; |
---|
| 393 | $all_contacts[ $object[ 'id_contact' ] ][ 'notes' ] = $object[ 'notes' ]; |
---|
| 394 | $all_contacts[ $object[ 'id_contact' ] ][ 'web_page' ] = $object[ 'web_page' ]; |
---|
| 395 | $all_contacts[ $object[ 'id_contact' ] ][ 'corporate_name' ]= $object[ 'corporate_name' ]; |
---|
| 396 | $all_contacts[ $object[ 'id_contact' ] ][ 'job_title' ] = $object[ 'job_title' ]; |
---|
| 397 | $all_contacts[ $object[ 'id_contact' ] ][ 'department' ] = $object[ 'department' ]; |
---|
[3216] | 398 | |
---|
| 399 | switch( $object[ 'id_typeof_contact_address' ] ) |
---|
| 400 | { |
---|
| 401 | case 1 : |
---|
| 402 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-address' ] = $object[ 'address1' ]; |
---|
[3322] | 403 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-address-2' ] = $object[ 'address2' ]; |
---|
[3216] | 404 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-complement' ] = $object[ 'complement' ]; |
---|
| 405 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-postal_code' ] = $object[ 'postal_code' ]; |
---|
| 406 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-city_name' ] = $object[ 'city_name' ]; |
---|
| 407 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-state_name' ] = $object[ 'state_name' ]; |
---|
| 408 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-id_country' ] = $object[ 'id_country' ]; |
---|
| 409 | break; |
---|
| 410 | case 2 : |
---|
| 411 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-address' ] = $object[ 'address1' ]; |
---|
[3322] | 412 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-address-2' ] = $object[ 'address2' ]; |
---|
[3216] | 413 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-complement' ] = $object[ 'complement' ]; |
---|
| 414 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-postal_code' ] = $object[ 'postal_code' ]; |
---|
| 415 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-city_name' ] = $object[ 'city_name' ]; |
---|
| 416 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-state_name' ] = $object[ 'state_name' ]; |
---|
| 417 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-id_country' ] = $object[ 'id_country' ]; |
---|
| 418 | break; |
---|
| 419 | } |
---|
[293] | 420 | } |
---|
[3215] | 421 | |
---|
[293] | 422 | return array_values($all_contacts); |
---|
[3215] | 423 | } |
---|
| 424 | |
---|
[4510] | 425 | function verifyContact($email, $name, $phone) |
---|
[2] | 426 | { |
---|
[4510] | 427 | if ($email) { |
---|
| 428 | |
---|
| 429 | $query = 'select A.names_ordered, C.id_connection from phpgw_cc_contact A,'. |
---|
| 430 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C where '. |
---|
| 431 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
| 432 | 'and B.id_typeof_contact_connection = 1 and '. |
---|
| 433 | "A.id_owner ='" .$this->owner."' and C.connection_value = '".$email. "'"; |
---|
| 434 | |
---|
| 435 | if (!$this->db->query($query)) |
---|
| 436 | { |
---|
| 437 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | $return = false; |
---|
| 441 | |
---|
| 442 | while($this->db->next_record()) |
---|
| 443 | { |
---|
| 444 | $row = $this->db->row(); |
---|
| 445 | $return[] = $row['names_ordered']; |
---|
| 446 | } |
---|
| 447 | } |
---|
| 448 | |
---|
| 449 | if (!$return && $phone) { |
---|
| 450 | |
---|
| 451 | $query = 'select A.names_ordered, C.id_connection from phpgw_cc_contact A,'. |
---|
| 452 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C where '. |
---|
| 453 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
| 454 | 'and B.id_typeof_contact_connection = 2 and '. |
---|
| 455 | "A.id_owner ='" .$this->owner."' and C.connection_value = '".$phone. "'"; |
---|
| 456 | |
---|
| 457 | if (!$this->db->query($query)) |
---|
| 458 | { |
---|
| 459 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | $return = false; |
---|
| 463 | |
---|
| 464 | while($this->db->next_record()) |
---|
| 465 | { |
---|
| 466 | $row = $this->db->row(); |
---|
| 467 | $return[] = $row['names_ordered']; |
---|
| 468 | } |
---|
| 469 | |
---|
[2] | 470 | } |
---|
[4510] | 471 | |
---|
| 472 | if (!$return && $name) { |
---|
| 473 | |
---|
| 474 | $query = "select names_ordered, C.id_connection from phpgw_cc_contact where id_owner = '" . $this->owner . "' and RTRIM(names_ordered) = '". $name. "'"; |
---|
| 475 | |
---|
| 476 | if (!$this->db->query($query)) |
---|
| 477 | { |
---|
| 478 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 479 | } |
---|
[2] | 480 | |
---|
[4510] | 481 | $return = false; |
---|
[2] | 482 | |
---|
[4510] | 483 | while($this->db->next_record()) |
---|
| 484 | { |
---|
| 485 | $row = $this->db->row(); |
---|
| 486 | $return[] = $row['names_ordered']; |
---|
| 487 | } |
---|
| 488 | |
---|
[2] | 489 | } |
---|
[4510] | 490 | $return[] = $row['id_connection']; |
---|
| 491 | |
---|
[2] | 492 | return $return; |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | function selectContactsByGroup($idGroup) |
---|
| 496 | { |
---|
[3702] | 497 | $query = 'select C.id_connection, A.names_ordered, C.connection_value, A.id_contact from phpgw_cc_contact A,'. |
---|
[2] | 498 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '. |
---|
| 499 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
[4477] | 500 | 'and '. |
---|
[752] | 501 | //'A.id_owner ='.$this->owner.' and'. |
---|
| 502 | ' D.id_connection = C.id_connection and D.id_group = '.$idGroup. |
---|
[2] | 503 | ' order by A.names_ordered'; |
---|
| 504 | |
---|
| 505 | if (!$this->db->query($query)) |
---|
| 506 | { |
---|
| 507 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | $return = false; |
---|
| 511 | |
---|
| 512 | |
---|
| 513 | while($this->db->next_record()) |
---|
| 514 | { |
---|
| 515 | $return[] = $this->db->row(); |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | return $return; |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | function selectContactsByGroupAlias($alias) |
---|
| 522 | { |
---|
| 523 | $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ". |
---|
| 524 | "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ". |
---|
| 525 | "A.id_contact = B.id_contact and B.id_connection = C.id_connection ". |
---|
[4498] | 526 | " and ". |
---|
[2] | 527 | "A.id_owner =".$this->owner." and ". |
---|
| 528 | "D.id_group = E.id_group and ". |
---|
| 529 | "D.id_connection = C.id_connection and E.short_name = '".$alias. |
---|
| 530 | "' order by A.names_ordered"; |
---|
| 531 | |
---|
| 532 | if (!$this->db->query($query)) |
---|
| 533 | { |
---|
| 534 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 535 | } |
---|
| 536 | |
---|
| 537 | $return = false; |
---|
| 538 | |
---|
| 539 | |
---|
| 540 | while($this->db->next_record()) |
---|
| 541 | { |
---|
| 542 | $return[] = $this->db->row(); |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | return $return; |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | function insertContactsByGroup($idGroup, $contacts) |
---|
| 549 | { |
---|
| 550 | |
---|
| 551 | foreach($contacts as $index => $idConnection) |
---|
| 552 | { |
---|
| 553 | $query = "INSERT INTO phpgw_cc_contact_grps(id_group,id_connection) ". |
---|
| 554 | "VALUES(".$idGroup.",".$idConnection.")"; |
---|
| 555 | |
---|
| 556 | if (!$this->db->query($query)) |
---|
| 557 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | return True; |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | function updateContactsByGroup($id_group, $contacts) |
---|
| 564 | { |
---|
| 565 | |
---|
| 566 | $query = 'select C.id_connection from phpgw_cc_contact A,'. |
---|
| 567 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '. |
---|
| 568 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
[4498] | 569 | ' and '. |
---|
[1280] | 570 | //'A.id_owner ='.$this->owner.' and D.id_connection = C.id_connection and D.id_group = '.$id_group. |
---|
| 571 | ' D.id_connection = C.id_connection and D.id_group = '.$id_group. //If I have the group ID, why ask about owner? |
---|
[2] | 572 | ' order by A.names_ordered'; |
---|
| 573 | |
---|
| 574 | if (!$this->db->query($query)) |
---|
| 575 | { |
---|
| 576 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | $return = false; |
---|
| 580 | |
---|
| 581 | |
---|
| 582 | while($this->db->next_record()) |
---|
| 583 | { |
---|
| 584 | $return[] = $this->db->row(); |
---|
| 585 | |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | $array_connections = array(); |
---|
| 589 | |
---|
| 590 | if($return) { |
---|
| 591 | foreach($return as $index => $connection){ |
---|
| 592 | array_push($array_connections,$connection['id_connection']); |
---|
| 593 | } |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | if(!is_array($contacts)) |
---|
| 597 | $contacts = array(); |
---|
| 598 | |
---|
| 599 | if(!is_array($connections)) |
---|
| 600 | $connections = array(); |
---|
| 601 | |
---|
| 602 | $connections_to_add = array_diff($contacts, $array_connections); |
---|
| 603 | $connections_to_remove = array_diff($array_connections,$contacts); |
---|
| 604 | |
---|
| 605 | if($connections_to_add){ |
---|
| 606 | $this -> insertContactsByGroup($id_group, $connections_to_add); |
---|
| 607 | } |
---|
| 608 | |
---|
| 609 | if($connections_to_remove){ |
---|
| 610 | $this -> deleteContactsByGroup($id_group, $connections_to_remove); |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | return True; |
---|
| 614 | } |
---|
| 615 | |
---|
[4502] | 616 | function updateContactGroups($id_defaultconnection, $connections, $groups) |
---|
| 617 | { |
---|
| 618 | if (is_array($groups) && count($groups) > 0) |
---|
| 619 | { |
---|
| 620 | $query = "UPDATE phpgw_cc_contact_grps SET id_connection = " . $id_defaultconnection . " WHERE ("; |
---|
| 621 | $more = false; |
---|
| 622 | foreach ($connections as $connection) |
---|
| 623 | { |
---|
| 624 | if ($more) |
---|
| 625 | $query .= " OR "; |
---|
| 626 | $query .= "id_connection = " . $connection['id_connection']; |
---|
| 627 | $more = true; |
---|
| 628 | } |
---|
| 629 | $query .= ") AND ("; |
---|
| 630 | $more = false; |
---|
| 631 | foreach ($groups as $group) |
---|
| 632 | { |
---|
| 633 | if ($more) |
---|
| 634 | $query .= " OR "; |
---|
| 635 | $query .= "id_group = " . $group['id_group']; |
---|
| 636 | $more = true; |
---|
| 637 | } |
---|
| 638 | $query .= ");"; |
---|
| 639 | if (!$this->db->query($query)) |
---|
| 640 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 641 | |
---|
| 642 | return true; |
---|
| 643 | } |
---|
| 644 | } |
---|
| 645 | |
---|
[2] | 646 | function deleteContactsByGroup($id_group, $contacts = null) |
---|
| 647 | { |
---|
| 648 | |
---|
| 649 | $query = "DELETE FROM phpgw_cc_contact_grps "; |
---|
| 650 | |
---|
| 651 | if($contacts) { |
---|
| 652 | $index = 0; |
---|
| 653 | |
---|
| 654 | foreach($contacts as $a => $id_connection) { |
---|
| 655 | |
---|
| 656 | if($index++) |
---|
| 657 | $query .= " OR"; |
---|
| 658 | else |
---|
| 659 | $query .= " WHERE ("; |
---|
| 660 | |
---|
| 661 | $query .= " id_connection = ".$id_connection; |
---|
| 662 | } |
---|
| 663 | $query .= ") AND "; |
---|
| 664 | } |
---|
| 665 | else |
---|
| 666 | $query.= " WHERE "; |
---|
| 667 | |
---|
| 668 | $query.= "id_group = ".$id_group; |
---|
| 669 | |
---|
| 670 | |
---|
| 671 | if (!$this->db->query($query)) |
---|
| 672 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 673 | |
---|
| 674 | return True; |
---|
| 675 | } |
---|
[3334] | 676 | |
---|
| 677 | function add_user_by_name($id_group){ |
---|
| 678 | $query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value, B.id_typeof_contact_connection'. |
---|
| 679 | ' from phpgw_cc_contact A, phpgw_cc_contact_conns B, phpgw_cc_connections C'. |
---|
| 680 | ' where A.id_contact = B.id_contact and B.id_connection = C.id_connection'. |
---|
| 681 | ' and A.last_update = (select max(up.last_update) from phpgw_cc_contact up where up.id_owner ='.$this->owner.")". |
---|
| 682 | ' and A.id_owner ='.$this->owner.' and C.connection_is_default = true'. |
---|
| 683 | ' order by A.names_ordered,C.connection_value'; |
---|
| 684 | |
---|
| 685 | |
---|
| 686 | if (!$this->db->query($query)){ |
---|
| 687 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | $return = array(); |
---|
| 691 | |
---|
| 692 | $array_connections = array(); |
---|
| 693 | while($this->db->next_record()){ |
---|
| 694 | $return = $this->db->row(); |
---|
| 695 | array_push($array_connections, $return['id_connection']); |
---|
| 696 | } |
---|
| 697 | $this -> insertContactsByGroup($id_group, $array_connections); |
---|
| 698 | |
---|
| 699 | } |
---|
| 700 | |
---|
[2] | 701 | } |
---|
| 702 | ?> |
---|