[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' |
---|
[4315] | 143 | . ' C.id_connection,' |
---|
| 144 | . ' A.id_contact,' |
---|
| 145 | . ' A.names_ordered,' |
---|
| 146 | . ' A.alias,' |
---|
| 147 | . ' A.birthdate,' |
---|
| 148 | . ' A.sex,' |
---|
| 149 | . ' A.pgp_key,' |
---|
| 150 | . ' A.notes,' |
---|
| 151 | . ' A.web_page,' |
---|
| 152 | . ' A.corporate_name,' |
---|
| 153 | . ' A.job_title,' |
---|
| 154 | . ' A.department,' |
---|
| 155 | . ' C.connection_name,' |
---|
| 156 | . ' C.connection_value,' |
---|
| 157 | . ' B.id_typeof_contact_connection,' |
---|
[3216] | 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' |
---|
[4315] | 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' |
---|
[4315] | 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' ) |
---|
[4315] | 198 | $query .= ' and B.id_typeof_contact_connection = 1 '; |
---|
[702] | 199 | |
---|
[4315] | 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 | |
---|
[4088] | 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 | { |
---|
| 350 | $query = 'select A.names_ordered from phpgw_cc_contact A,'. |
---|
| 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(); |
---|
| 366 | $return[] = $row['names_ordered']; |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | return $return; |
---|
| 370 | } |
---|
| 371 | |
---|
| 372 | function selectContactsByGroup($idGroup) |
---|
| 373 | { |
---|
[3702] | 374 | $query = 'select C.id_connection, A.names_ordered, C.connection_value, A.id_contact from phpgw_cc_contact A,'. |
---|
[2] | 375 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '. |
---|
| 376 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
| 377 | 'and B.id_typeof_contact_connection = 1 and '. |
---|
[752] | 378 | //'A.id_owner ='.$this->owner.' and'. |
---|
| 379 | ' D.id_connection = C.id_connection and D.id_group = '.$idGroup. |
---|
[2] | 380 | ' order by A.names_ordered'; |
---|
| 381 | |
---|
| 382 | if (!$this->db->query($query)) |
---|
| 383 | { |
---|
| 384 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | $return = false; |
---|
| 388 | |
---|
| 389 | |
---|
| 390 | while($this->db->next_record()) |
---|
| 391 | { |
---|
| 392 | $return[] = $this->db->row(); |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | return $return; |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | function selectContactsByGroupAlias($alias) |
---|
| 399 | { |
---|
| 400 | $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ". |
---|
| 401 | "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ". |
---|
| 402 | "A.id_contact = B.id_contact and B.id_connection = C.id_connection ". |
---|
| 403 | "and B.id_typeof_contact_connection = 1 and ". |
---|
| 404 | "A.id_owner =".$this->owner." and ". |
---|
| 405 | "D.id_group = E.id_group and ". |
---|
| 406 | "D.id_connection = C.id_connection and E.short_name = '".$alias. |
---|
| 407 | "' order by A.names_ordered"; |
---|
| 408 | |
---|
| 409 | if (!$this->db->query($query)) |
---|
| 410 | { |
---|
| 411 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | $return = false; |
---|
| 415 | |
---|
| 416 | |
---|
| 417 | while($this->db->next_record()) |
---|
| 418 | { |
---|
| 419 | $return[] = $this->db->row(); |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | return $return; |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | function insertContactsByGroup($idGroup, $contacts) |
---|
| 426 | { |
---|
| 427 | |
---|
| 428 | foreach($contacts as $index => $idConnection) |
---|
| 429 | { |
---|
| 430 | $query = "INSERT INTO phpgw_cc_contact_grps(id_group,id_connection) ". |
---|
| 431 | "VALUES(".$idGroup.",".$idConnection.")"; |
---|
| 432 | |
---|
| 433 | if (!$this->db->query($query)) |
---|
| 434 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | return True; |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | function updateContactsByGroup($id_group, $contacts) |
---|
| 441 | { |
---|
| 442 | |
---|
| 443 | $query = 'select C.id_connection from phpgw_cc_contact A,'. |
---|
| 444 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '. |
---|
| 445 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
| 446 | 'and B.id_typeof_contact_connection = 1 and '. |
---|
[1280] | 447 | //'A.id_owner ='.$this->owner.' and D.id_connection = C.id_connection and D.id_group = '.$id_group. |
---|
| 448 | ' D.id_connection = C.id_connection and D.id_group = '.$id_group. //If I have the group ID, why ask about owner? |
---|
[2] | 449 | ' order by A.names_ordered'; |
---|
| 450 | |
---|
| 451 | if (!$this->db->query($query)) |
---|
| 452 | { |
---|
| 453 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | $return = false; |
---|
| 457 | |
---|
| 458 | |
---|
| 459 | while($this->db->next_record()) |
---|
| 460 | { |
---|
| 461 | $return[] = $this->db->row(); |
---|
| 462 | |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | $array_connections = array(); |
---|
| 466 | |
---|
| 467 | if($return) { |
---|
| 468 | foreach($return as $index => $connection){ |
---|
| 469 | array_push($array_connections,$connection['id_connection']); |
---|
| 470 | } |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | if(!is_array($contacts)) |
---|
| 474 | $contacts = array(); |
---|
| 475 | |
---|
| 476 | if(!is_array($connections)) |
---|
| 477 | $connections = array(); |
---|
| 478 | |
---|
| 479 | $connections_to_add = array_diff($contacts, $array_connections); |
---|
| 480 | $connections_to_remove = array_diff($array_connections,$contacts); |
---|
| 481 | |
---|
| 482 | if($connections_to_add){ |
---|
| 483 | $this -> insertContactsByGroup($id_group, $connections_to_add); |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | if($connections_to_remove){ |
---|
| 487 | $this -> deleteContactsByGroup($id_group, $connections_to_remove); |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | return True; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | function deleteContactsByGroup($id_group, $contacts = null) |
---|
| 494 | { |
---|
| 495 | |
---|
| 496 | $query = "DELETE FROM phpgw_cc_contact_grps "; |
---|
| 497 | |
---|
| 498 | if($contacts) { |
---|
| 499 | $index = 0; |
---|
| 500 | |
---|
| 501 | foreach($contacts as $a => $id_connection) { |
---|
| 502 | |
---|
| 503 | if($index++) |
---|
| 504 | $query .= " OR"; |
---|
| 505 | else |
---|
| 506 | $query .= " WHERE ("; |
---|
| 507 | |
---|
| 508 | $query .= " id_connection = ".$id_connection; |
---|
| 509 | } |
---|
| 510 | $query .= ") AND "; |
---|
| 511 | } |
---|
| 512 | else |
---|
| 513 | $query.= " WHERE "; |
---|
| 514 | |
---|
| 515 | $query.= "id_group = ".$id_group; |
---|
| 516 | |
---|
| 517 | |
---|
| 518 | if (!$this->db->query($query)) |
---|
| 519 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 520 | |
---|
| 521 | return True; |
---|
| 522 | } |
---|
[3334] | 523 | |
---|
| 524 | function add_user_by_name($id_group){ |
---|
| 525 | $query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value, B.id_typeof_contact_connection'. |
---|
| 526 | ' from phpgw_cc_contact A, phpgw_cc_contact_conns B, phpgw_cc_connections C'. |
---|
| 527 | ' where A.id_contact = B.id_contact and B.id_connection = C.id_connection'. |
---|
| 528 | ' and A.last_update = (select max(up.last_update) from phpgw_cc_contact up where up.id_owner ='.$this->owner.")". |
---|
| 529 | ' and A.id_owner ='.$this->owner.' and C.connection_is_default = true'. |
---|
| 530 | ' order by A.names_ordered,C.connection_value'; |
---|
| 531 | |
---|
| 532 | |
---|
| 533 | if (!$this->db->query($query)){ |
---|
| 534 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
| 535 | } |
---|
| 536 | |
---|
| 537 | $return = array(); |
---|
| 538 | |
---|
| 539 | $array_connections = array(); |
---|
| 540 | while($this->db->next_record()){ |
---|
| 541 | $return = $this->db->row(); |
---|
| 542 | array_push($array_connections, $return['id_connection']); |
---|
| 543 | } |
---|
| 544 | $this -> insertContactsByGroup($id_group, $array_connections); |
---|
| 545 | |
---|
| 546 | } |
---|
| 547 | |
---|
[2] | 548 | } |
---|
| 549 | ?> |
---|