[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 | |
---|
| 107 | function deleteContactFromGroups($id) |
---|
| 108 | { |
---|
| 109 | $query = "DELETE FROM phpgw_cc_contact_grps WHERE id_connection = ".$id; |
---|
| 110 | |
---|
| 111 | if (!$this->db->query($query)) |
---|
| 112 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 113 | |
---|
| 114 | return True; |
---|
| 115 | } |
---|
| 116 | |
---|
[3334] | 117 | function selectGroupsOwnerCanImportContacts($owner) { |
---|
[3344] | 118 | $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 |
---|
| 119 | A.acl_location=B.acl_account::text and A.acl_account::text=B.acl_location |
---|
| 120 | and A.acl_appname = 'contactcenter' and B.acl_appname = 'contactcenter' |
---|
| 121 | and A.acl_rights & 4 <> 0 and B.acl_rights & 1 <> 0 |
---|
| 122 | and A.acl_location = '".$owner."')"; //He can import contacts only to his groups, or shared groups that he gave read permission. |
---|
| 123 | |
---|
[3334] | 124 | $this->db->query($query); |
---|
| 125 | |
---|
| 126 | $return = array(); |
---|
| 127 | |
---|
| 128 | while($this->db->next_record()) |
---|
| 129 | { |
---|
| 130 | $return[] = $this->db->row(); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | return $return; |
---|
| 134 | |
---|
| 135 | } |
---|
| 136 | |
---|
[1280] | 137 | //Owner = null means the owner setted on constructor. |
---|
| 138 | function selectAllContacts( $field = false ,$shared_from=null) |
---|
[2] | 139 | { |
---|
[3215] | 140 | if ( $shared_from == NULL ) |
---|
| 141 | { |
---|
[3216] | 142 | $query = 'select' |
---|
| 143 | . ' phpgw_cc_connections.id_connection,' |
---|
| 144 | . ' phpgw_cc_contact.id_contact,' |
---|
| 145 | . ' phpgw_cc_contact.names_ordered,' |
---|
| 146 | . ' phpgw_cc_contact.alias,' |
---|
[3322] | 147 | . ' phpgw_cc_contact.birthdate,' |
---|
| 148 | . ' phpgw_cc_contact.sex,' |
---|
| 149 | . ' phpgw_cc_contact.pgp_key,' |
---|
| 150 | . ' phpgw_cc_contact.notes,' |
---|
| 151 | . ' phpgw_cc_contact.web_page,' |
---|
| 152 | . ' phpgw_cc_contact.corporate_name,' |
---|
| 153 | . ' phpgw_cc_contact.job_title,' |
---|
| 154 | . ' phpgw_cc_contact.department,' |
---|
[3217] | 155 | . ' phpgw_cc_connections.connection_name,' |
---|
[3216] | 156 | . ' phpgw_cc_connections.connection_value,' |
---|
| 157 | . ' phpgw_cc_contact_conns.id_typeof_contact_connection,' |
---|
| 158 | . ' phpgw_cc_contact_addrs.id_typeof_contact_address,' |
---|
| 159 | . ' phpgw_cc_addresses.address1,' |
---|
[3322] | 160 | . ' phpgw_cc_addresses.address2,' |
---|
[3216] | 161 | . ' phpgw_cc_addresses.complement,' |
---|
| 162 | . ' phpgw_cc_addresses.postal_code,' |
---|
| 163 | . ' phpgw_cc_city.city_name,' |
---|
| 164 | . ' phpgw_cc_state.state_name,' |
---|
[3217] | 165 | . ' phpgw_cc_addresses.id_country' |
---|
| 166 | ; |
---|
[3215] | 167 | |
---|
[3216] | 168 | $query .= ' from' |
---|
[4355] | 169 | . ' phpgw_cc_contact A' |
---|
| 170 | . ' inner join phpgw_cc_contact_conns B on ( A.id_contact = B.id_contact )' |
---|
| 171 | . ' inner join phpgw_cc_connections C on ( B.id_connection = C.id_connection )' |
---|
| 172 | . ' left join phpgw_cc_contact_addrs on ( A.id_contact = phpgw_cc_contact_addrs.id_contact )' |
---|
[3216] | 173 | . ' left join phpgw_cc_addresses on ( phpgw_cc_contact_addrs.id_address = phpgw_cc_addresses.id_address )' |
---|
| 174 | . ' left join phpgw_cc_city on ( phpgw_cc_addresses.id_city = phpgw_cc_city.id_city )' |
---|
[3217] | 175 | . ' left join phpgw_cc_state on ( phpgw_cc_addresses.id_state = phpgw_cc_state.id_state)' |
---|
| 176 | ; |
---|
[3215] | 177 | |
---|
[3216] | 178 | $query .= ' where' |
---|
[4355] | 179 | . " A.id_owner = {$this->owner}" |
---|
[3217] | 180 | //. ' and phpgw_cc_connections.connection_is_default = true' |
---|
| 181 | ; |
---|
[3215] | 182 | |
---|
[1280] | 183 | } |
---|
| 184 | else { |
---|
| 185 | $sub_query = 'select A.id_related from phpgw_cc_contact_rels A,phpgw_acl B |
---|
| 186 | where B.acl_location!=\'run\' and A.id_contact = B.acl_location::bigint and A.id_related = B.acl_account and |
---|
| 187 | B.acl_appname = \'contactcenter\' and B.acl_rights & 1 <> 0 |
---|
| 188 | and A.id_typeof_contact_relation=1 and A.id_contact = '.$shared_from.' and A.id_related='.$this->owner; |
---|
[3215] | 189 | |
---|
[1280] | 190 | $query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value , B.id_typeof_contact_connection from phpgw_cc_contact A,'. |
---|
| 191 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C where '. |
---|
| 192 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection and '. |
---|
| 193 | 'A.id_owner in ('.$shared_from.',('.$sub_query.'))'. |
---|
| 194 | ' and C.connection_is_default = true '; |
---|
| 195 | } |
---|
[16] | 196 | |
---|
[702] | 197 | if ( $field == 'only_email' ) |
---|
[4355] | 198 | $query .= 'and B.id_typeof_contact_connection = 1 '; |
---|
[702] | 199 | |
---|
[4355] | 200 | $query .= ' order by A.names_ordered, C.connection_value'; |
---|
[702] | 201 | |
---|
[2] | 202 | if (!$this->db->query($query)) |
---|
| 203 | { |
---|
| 204 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 205 | } |
---|
[3215] | 206 | |
---|
[576] | 207 | $return = array(); |
---|
[3215] | 208 | |
---|
[2] | 209 | while($this->db->next_record()) |
---|
| 210 | { |
---|
| 211 | $return[] = $this->db->row(); |
---|
| 212 | } |
---|
[3215] | 213 | |
---|
| 214 | if( ! count( $return ) ) |
---|
| 215 | return $return; |
---|
| 216 | |
---|
[4121] | 217 | $all_contacts = array(); |
---|
[3215] | 218 | foreach( $return as $i => $object ) |
---|
| 219 | { |
---|
[3216] | 220 | if ( ! array_key_exists( $object[ 'id_contact' ], $all_contacts ) ) |
---|
| 221 | $all_contacts[ $object[ 'id_contact' ] ] = array( |
---|
| 222 | 'connection_value' => '', |
---|
| 223 | 'phone' => '', |
---|
[3217] | 224 | 'mobile' => '', |
---|
[3216] | 225 | 'names_ordered' => '', |
---|
| 226 | 'id_contact' => '', |
---|
| 227 | 'id_connection' => '', |
---|
| 228 | 'alias' => '', |
---|
[3322] | 229 | 'birthdate' => '', |
---|
| 230 | 'sex' => '', |
---|
| 231 | 'pgp_key' => '', |
---|
| 232 | 'notes' => '', |
---|
| 233 | 'web_page' => '', |
---|
| 234 | 'corporate_name' => '', |
---|
| 235 | 'job_title' => '', |
---|
| 236 | 'department' => '', |
---|
[3217] | 237 | 'main-mail' => '', |
---|
| 238 | 'aternative-mail' => '', |
---|
| 239 | 'business-phone' => '', |
---|
[3216] | 240 | 'business-address' => '', |
---|
[3217] | 241 | 'business-complement' => '', |
---|
| 242 | 'business-postal_code' => '', |
---|
| 243 | 'business-city_name' => '', |
---|
| 244 | 'business-state_name' => '', |
---|
| 245 | 'business-id_country' => '', |
---|
[3322] | 246 | 'business-fax' => '', |
---|
| 247 | 'business-pager' => '', |
---|
| 248 | 'business-mobile' => '', |
---|
| 249 | 'business-address-2' => '', |
---|
[3217] | 250 | 'home-phone' => '', |
---|
[3216] | 251 | 'home-address' => '', |
---|
[3217] | 252 | 'home-complement' => '', |
---|
| 253 | 'home-postal_code' => '', |
---|
| 254 | 'home-city_name' => '', |
---|
| 255 | 'home-state_name' => '', |
---|
[3322] | 256 | 'home-fax' => '', |
---|
| 257 | 'home-pager' => '', |
---|
| 258 | 'home-address-2' => '' |
---|
| 259 | |
---|
| 260 | |
---|
[3216] | 261 | ); |
---|
| 262 | |
---|
[3215] | 263 | switch( $object[ 'id_typeof_contact_connection' ] ) |
---|
| 264 | { |
---|
| 265 | case 1 : |
---|
| 266 | $all_contacts[ $object[ 'id_contact' ] ][ 'connection_value' ] = $object[ 'connection_value' ]; |
---|
[3217] | 267 | switch ( strtolower( $object[ 'connection_name' ] ) ) |
---|
| 268 | { |
---|
| 269 | case 'alternativo' : |
---|
| 270 | $all_contacts[ $object[ 'id_contact' ] ][ 'alternative-mail' ] = $object[ 'connection_value' ]; |
---|
| 271 | break; |
---|
| 272 | case 'principal' : |
---|
| 273 | $all_contacts[ $object[ 'id_contact' ] ][ 'main-mail' ] = $object[ 'connection_value' ]; |
---|
| 274 | break; |
---|
| 275 | } |
---|
[3215] | 276 | break; |
---|
| 277 | case 2 : |
---|
| 278 | $all_contacts[ $object[ 'id_contact' ] ][ 'phone' ] = $object[ 'connection_value' ]; |
---|
[3217] | 279 | switch ( strtolower( $object[ 'connection_name' ] ) ) |
---|
| 280 | { |
---|
| 281 | case 'casa' : |
---|
| 282 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-phone' ] = $object[ 'connection_value' ]; |
---|
| 283 | break; |
---|
| 284 | case 'celular' : |
---|
| 285 | $all_contacts[ $object[ 'id_contact' ] ][ 'mobile' ] = $object[ 'connection_value' ]; |
---|
| 286 | break; |
---|
| 287 | case 'trabalho' : |
---|
| 288 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-phone' ] = $object[ 'connection_value' ]; |
---|
[3322] | 289 | break; |
---|
| 290 | case 'fax' : |
---|
| 291 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-fax' ] = $object[ 'connection_value' ]; |
---|
[3217] | 292 | break; |
---|
[3322] | 293 | case 'pager' : |
---|
| 294 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-pager' ] = $object[ 'connection_value' ]; |
---|
| 295 | break; |
---|
| 296 | case 'celular corporativo' : |
---|
| 297 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-mobile' ] = $object[ 'connection_value' ]; |
---|
| 298 | break; |
---|
| 299 | case 'pager corporativo' : |
---|
| 300 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-pager' ] = $object[ 'connection_value' ]; |
---|
| 301 | break; |
---|
| 302 | case 'fax corporativo' : |
---|
| 303 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-fax' ] = $object[ 'connection_value' ]; |
---|
| 304 | break; |
---|
[3217] | 305 | } |
---|
[3215] | 306 | break; |
---|
[293] | 307 | } |
---|
[3215] | 308 | |
---|
| 309 | $all_contacts[ $object[ 'id_contact' ] ][ 'names_ordered' ] = $object[ 'names_ordered' ]; |
---|
| 310 | $all_contacts[ $object[ 'id_contact' ] ][ 'id_contact' ] = $object[ 'id_contact' ]; |
---|
| 311 | $all_contacts[ $object[ 'id_contact' ] ][ 'id_connection' ] = $object[ 'id_connection' ]; |
---|
[3322] | 312 | $all_contacts[ $object[ 'id_contact' ] ][ 'alias' ] = $object[ 'alias' ]; |
---|
| 313 | $all_contacts[ $object[ 'id_contact' ] ][ 'birthdate' ] = $object[ 'birthdate' ]; |
---|
| 314 | $all_contacts[ $object[ 'id_contact' ] ][ 'sex' ] = $object[ 'sex' ]; |
---|
| 315 | $all_contacts[ $object[ 'id_contact' ] ][ 'pgp_key' ] = $object[ 'pgp_key' ]; |
---|
| 316 | $all_contacts[ $object[ 'id_contact' ] ][ 'notes' ] = $object[ 'notes' ]; |
---|
| 317 | $all_contacts[ $object[ 'id_contact' ] ][ 'web_page' ] = $object[ 'web_page' ]; |
---|
| 318 | $all_contacts[ $object[ 'id_contact' ] ][ 'corporate_name' ]= $object[ 'corporate_name' ]; |
---|
| 319 | $all_contacts[ $object[ 'id_contact' ] ][ 'job_title' ] = $object[ 'job_title' ]; |
---|
| 320 | $all_contacts[ $object[ 'id_contact' ] ][ 'department' ] = $object[ 'department' ]; |
---|
[3216] | 321 | |
---|
| 322 | switch( $object[ 'id_typeof_contact_address' ] ) |
---|
| 323 | { |
---|
| 324 | case 1 : |
---|
| 325 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-address' ] = $object[ 'address1' ]; |
---|
[3322] | 326 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-address-2' ] = $object[ 'address2' ]; |
---|
[3216] | 327 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-complement' ] = $object[ 'complement' ]; |
---|
| 328 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-postal_code' ] = $object[ 'postal_code' ]; |
---|
| 329 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-city_name' ] = $object[ 'city_name' ]; |
---|
| 330 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-state_name' ] = $object[ 'state_name' ]; |
---|
| 331 | $all_contacts[ $object[ 'id_contact' ] ][ 'business-id_country' ] = $object[ 'id_country' ]; |
---|
| 332 | break; |
---|
| 333 | case 2 : |
---|
| 334 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-address' ] = $object[ 'address1' ]; |
---|
[3322] | 335 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-address-2' ] = $object[ 'address2' ]; |
---|
[3216] | 336 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-complement' ] = $object[ 'complement' ]; |
---|
| 337 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-postal_code' ] = $object[ 'postal_code' ]; |
---|
| 338 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-city_name' ] = $object[ 'city_name' ]; |
---|
| 339 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-state_name' ] = $object[ 'state_name' ]; |
---|
| 340 | $all_contacts[ $object[ 'id_contact' ] ][ 'home-id_country' ] = $object[ 'id_country' ]; |
---|
| 341 | break; |
---|
| 342 | } |
---|
[293] | 343 | } |
---|
[3215] | 344 | |
---|
[293] | 345 | return array_values($all_contacts); |
---|
[3215] | 346 | } |
---|
| 347 | |
---|
[2] | 348 | function verifyContact($email) |
---|
| 349 | { |
---|
[3970] | 350 | $query = 'select A.names_ordered, C.id_connection from phpgw_cc_contact A,'. |
---|
[2] | 351 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C where '. |
---|
| 352 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
| 353 | 'and B.id_typeof_contact_connection = 1 and '. |
---|
| 354 | 'A.id_owner ='.$this->owner.' and C.connection_value = \''.$email.'\''; |
---|
| 355 | |
---|
| 356 | if (!$this->db->query($query)) |
---|
| 357 | { |
---|
| 358 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | $return = false; |
---|
| 362 | |
---|
| 363 | while($this->db->next_record()) |
---|
| 364 | { |
---|
| 365 | $row = $this->db->row(); |
---|
[3970] | 366 | $return[] = $row['names_ordered']; |
---|
| 367 | $return[] = $row['id_connection']; |
---|
[2] | 368 | } |
---|
| 369 | |
---|
| 370 | return $return; |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | function selectContactsByGroup($idGroup) |
---|
| 374 | { |
---|
[3702] | 375 | $query = 'select C.id_connection, A.names_ordered, C.connection_value, A.id_contact from phpgw_cc_contact A,'. |
---|
[2] | 376 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '. |
---|
| 377 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
| 378 | 'and B.id_typeof_contact_connection = 1 and '. |
---|
[752] | 379 | //'A.id_owner ='.$this->owner.' and'. |
---|
| 380 | ' D.id_connection = C.id_connection and D.id_group = '.$idGroup. |
---|
[2] | 381 | ' order by A.names_ordered'; |
---|
| 382 | |
---|
| 383 | if (!$this->db->query($query)) |
---|
| 384 | { |
---|
| 385 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | $return = false; |
---|
| 389 | |
---|
| 390 | |
---|
| 391 | while($this->db->next_record()) |
---|
| 392 | { |
---|
| 393 | $return[] = $this->db->row(); |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | return $return; |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | function selectContactsByGroupAlias($alias) |
---|
| 400 | { |
---|
| 401 | $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ". |
---|
| 402 | "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ". |
---|
| 403 | "A.id_contact = B.id_contact and B.id_connection = C.id_connection ". |
---|
| 404 | "and B.id_typeof_contact_connection = 1 and ". |
---|
| 405 | "A.id_owner =".$this->owner." and ". |
---|
| 406 | "D.id_group = E.id_group and ". |
---|
| 407 | "D.id_connection = C.id_connection and E.short_name = '".$alias. |
---|
| 408 | "' order by A.names_ordered"; |
---|
| 409 | |
---|
| 410 | if (!$this->db->query($query)) |
---|
| 411 | { |
---|
| 412 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | $return = false; |
---|
| 416 | |
---|
| 417 | |
---|
| 418 | while($this->db->next_record()) |
---|
| 419 | { |
---|
| 420 | $return[] = $this->db->row(); |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | return $return; |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | function insertContactsByGroup($idGroup, $contacts) |
---|
| 427 | { |
---|
| 428 | |
---|
| 429 | foreach($contacts as $index => $idConnection) |
---|
| 430 | { |
---|
| 431 | $query = "INSERT INTO phpgw_cc_contact_grps(id_group,id_connection) ". |
---|
| 432 | "VALUES(".$idGroup.",".$idConnection.")"; |
---|
| 433 | |
---|
| 434 | if (!$this->db->query($query)) |
---|
| 435 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | return True; |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | function updateContactsByGroup($id_group, $contacts) |
---|
| 442 | { |
---|
| 443 | |
---|
| 444 | $query = 'select C.id_connection from phpgw_cc_contact A,'. |
---|
| 445 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '. |
---|
| 446 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
| 447 | 'and B.id_typeof_contact_connection = 1 and '. |
---|
[1280] | 448 | //'A.id_owner ='.$this->owner.' and D.id_connection = C.id_connection and D.id_group = '.$id_group. |
---|
| 449 | ' D.id_connection = C.id_connection and D.id_group = '.$id_group. //If I have the group ID, why ask about owner? |
---|
[2] | 450 | ' order by A.names_ordered'; |
---|
| 451 | |
---|
| 452 | if (!$this->db->query($query)) |
---|
| 453 | { |
---|
| 454 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | $return = false; |
---|
| 458 | |
---|
| 459 | |
---|
| 460 | while($this->db->next_record()) |
---|
| 461 | { |
---|
| 462 | $return[] = $this->db->row(); |
---|
| 463 | |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | $array_connections = array(); |
---|
| 467 | |
---|
| 468 | if($return) { |
---|
| 469 | foreach($return as $index => $connection){ |
---|
| 470 | array_push($array_connections,$connection['id_connection']); |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | if(!is_array($contacts)) |
---|
| 475 | $contacts = array(); |
---|
| 476 | |
---|
| 477 | if(!is_array($connections)) |
---|
| 478 | $connections = array(); |
---|
| 479 | |
---|
| 480 | $connections_to_add = array_diff($contacts, $array_connections); |
---|
| 481 | $connections_to_remove = array_diff($array_connections,$contacts); |
---|
| 482 | |
---|
| 483 | if($connections_to_add){ |
---|
| 484 | $this -> insertContactsByGroup($id_group, $connections_to_add); |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | if($connections_to_remove){ |
---|
| 488 | $this -> deleteContactsByGroup($id_group, $connections_to_remove); |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | return True; |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | function deleteContactsByGroup($id_group, $contacts = null) |
---|
| 495 | { |
---|
| 496 | |
---|
| 497 | $query = "DELETE FROM phpgw_cc_contact_grps "; |
---|
| 498 | |
---|
| 499 | if($contacts) { |
---|
| 500 | $index = 0; |
---|
| 501 | |
---|
| 502 | foreach($contacts as $a => $id_connection) { |
---|
| 503 | |
---|
| 504 | if($index++) |
---|
| 505 | $query .= " OR"; |
---|
| 506 | else |
---|
| 507 | $query .= " WHERE ("; |
---|
| 508 | |
---|
| 509 | $query .= " id_connection = ".$id_connection; |
---|
| 510 | } |
---|
| 511 | $query .= ") AND "; |
---|
| 512 | } |
---|
| 513 | else |
---|
| 514 | $query.= " WHERE "; |
---|
| 515 | |
---|
| 516 | $query.= "id_group = ".$id_group; |
---|
| 517 | |
---|
| 518 | |
---|
| 519 | if (!$this->db->query($query)) |
---|
| 520 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 521 | |
---|
| 522 | return True; |
---|
| 523 | } |
---|
[3334] | 524 | |
---|
| 525 | function add_user_by_name($id_group){ |
---|
| 526 | $query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value, B.id_typeof_contact_connection'. |
---|
| 527 | ' from phpgw_cc_contact A, phpgw_cc_contact_conns B, phpgw_cc_connections C'. |
---|
| 528 | ' where A.id_contact = B.id_contact and B.id_connection = C.id_connection'. |
---|
| 529 | ' and A.last_update = (select max(up.last_update) from phpgw_cc_contact up where up.id_owner ='.$this->owner.")". |
---|
| 530 | ' and A.id_owner ='.$this->owner.' and C.connection_is_default = true'. |
---|
| 531 | ' order by A.names_ordered,C.connection_value'; |
---|
| 532 | |
---|
| 533 | |
---|
| 534 | if (!$this->db->query($query)){ |
---|
| 535 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 536 | } |
---|
| 537 | |
---|
| 538 | $return = array(); |
---|
| 539 | |
---|
| 540 | $array_connections = array(); |
---|
| 541 | while($this->db->next_record()){ |
---|
| 542 | $return = $this->db->row(); |
---|
| 543 | array_push($array_connections, $return['id_connection']); |
---|
| 544 | } |
---|
| 545 | $this -> insertContactsByGroup($id_group, $array_connections); |
---|
| 546 | |
---|
| 547 | } |
---|
| 548 | |
---|
[2] | 549 | } |
---|
| 550 | ?> |
---|