source: sandbox/2.2.0.2/contactcenter/inc/class.so_group.inc.php @ 4498

Revision 4498, 21.1 KB checked in by airton, 13 years ago (diff)

Ticket #1925 - Permitir associar um contato com um grupo na tela de criação do contato

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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                {
28                        $query = 'SELECT id_group,title,short_name FROM phpgw_cc_groups ';
29                        if($id != '')
30                                $query .= 'WHERE id_group ='.$id;
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                {
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
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                {
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
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                /*!
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               
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               
194                function selectGroupsOwnerCanImportContacts($owner) {
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                       
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               
214                //Owner = null means the owner setted on constructor.
215                function selectAllContacts( $field = false ,$shared_from=null)
216                {
217                        if ( $shared_from == NULL )
218                        {
219                                $query = 'select'
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,'
235                                                . ' phpgw_cc_contact_addrs.id_typeof_contact_address,'
236                                                . ' phpgw_cc_addresses.address1,'
237                                                . ' phpgw_cc_addresses.address2,'
238                                                . ' phpgw_cc_addresses.complement,'
239                                                . ' phpgw_cc_addresses.postal_code,'
240                                                . ' phpgw_cc_city.city_name,'
241                                                . ' phpgw_cc_state.state_name,'
242                                                . ' phpgw_cc_addresses.id_country'
243                                                ;
244
245                                $query .= ' from'
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 )'
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 )'
252                                                . ' left join phpgw_cc_state on ( phpgw_cc_addresses.id_state = phpgw_cc_state.id_state)'
253                                                ;
254
255                                $query .= ' where'
256                                                . " A.id_owner = {$this->owner}"
257                                                //. ' and phpgw_cc_connections.connection_is_default = true'
258                                                ;
259
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;
266
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                        }
273
274                        if ( $field == 'only_email' )
275                                $query .= 'and B.id_typeof_contact_connection = 1 ';
276
277                        $query .= ' order by A.names_ordered, C.connection_value';
278
279                        if (!$this->db->query($query))
280                        {
281                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
282                        }
283
284                        $return = array();
285
286                        while($this->db->next_record())
287                        {
288                                $return[] = $this->db->row();
289                        }
290
291                        if( ! count( $return ) )
292                                return $return;
293
294                        $all_contacts = array();
295                        foreach( $return as $i => $object )
296                        {
297                                if ( ! array_key_exists( $object[ 'id_contact' ], $all_contacts ) )
298                                        $all_contacts[ $object[ 'id_contact' ] ] = array(
299                                                'connection_value' => '',
300                                                'phone' => '',
301                                                'mobile' => '',
302                                                'names_ordered' => '',
303                                                'id_contact' => '',
304                                                'id_connection' => '',
305                                                'alias' => '',
306                                                'birthdate' => '',
307                                                'sex' => '',
308                                                'pgp_key' => '',
309                                                'notes' => '',
310                                                'web_page' => '',
311                                                'corporate_name' => '',
312                                                'job_title' => '',
313                                                'department' => '',                             
314                                                'main-mail' => '',
315                                                'aternative-mail' => '',
316                                                'business-phone' => '',
317                                                'business-address' => '',
318                                                'business-complement' => '',
319                                                'business-postal_code' => '',
320                                                'business-city_name' => '',
321                                                'business-state_name' => '',
322                                                'business-id_country' => '',
323                                                'business-fax' => '',
324                                                'business-pager' => '',
325                                                'business-mobile' => '',
326                                                'business-address-2' => '',
327                                                'home-phone' => '',
328                                                'home-address' => '',
329                                                'home-complement' => '',
330                                                'home-postal_code' => '',
331                                                'home-city_name' => '',
332                                                'home-state_name' => '',
333                                                'home-fax' => '',
334                                                'home-pager' => '',
335                                                'home-address-2' => ''
336                                               
337                                               
338                                        );
339
340                                switch( $object[ 'id_typeof_contact_connection' ] )
341                                {
342                                        case 1 :
343                                                $all_contacts[ $object[ 'id_contact' ] ][ 'connection_value' ] = $object[ 'connection_value' ];
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                                                }
353                                                break;
354                                        case 2 :
355                                                $all_contacts[ $object[ 'id_contact' ] ][ 'phone' ] = $object[ 'connection_value' ];
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' ];
366                                                                break;                                                         
367                                                        case 'fax' :
368                                                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-fax' ] = $object[ 'connection_value' ];
369                                                                break;
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;
382                                                }
383                                                break;
384                                }
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' ];
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' ];
398
399                                switch( $object[ 'id_typeof_contact_address' ] )
400                                {
401                                        case 1 :
402                                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-address' ]     = $object[ 'address1' ];
403                                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-address-2' ]   = $object[ 'address2' ];
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' ];
412                                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-address-2' ]   = $object[ 'address2' ];
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                                }
420                        }
421
422                        return array_values($all_contacts);
423                }
424
425                function verifyContact($email)
426                {
427                        $query = 'select A.names_ordered, C.id_connection from phpgw_cc_contact A,'.
428                        'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
429                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
430                        'and B.id_typeof_contact_connection = 1 and '.
431                        'A.id_owner ='.$this->owner.' and C.connection_value = \''.$email.'\'';
432                                               
433                        if (!$this->db->query($query))
434                        {
435                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
436                        }
437                         
438                        $return = false;
439                       
440                        while($this->db->next_record())
441                        {
442                                $row = $this->db->row();
443                                $return[] =  $row['names_ordered'];
444                                $return[] =  $row['id_connection'];
445                        }
446                       
447                        return $return;
448                }               
449               
450                function selectContactsByGroup($idGroup)
451                {
452                        $query = 'select C.id_connection, A.names_ordered, C.connection_value, A.id_contact from phpgw_cc_contact A,'.
453                        'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '.
454                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
455                        'and '.
456                        //'A.id_owner ='.$this->owner.' and'.
457                        ' D.id_connection = C.id_connection and D.id_group = '.$idGroup.
458                        ' order by A.names_ordered';
459                                               
460                        if (!$this->db->query($query))
461                        {
462                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
463                        }
464                         
465                        $return = false;
466                       
467                       
468                        while($this->db->next_record())
469                        {
470                                $return[] = $this->db->row();
471                        }
472                       
473                        return $return;
474                }
475               
476                function selectContactsByGroupAlias($alias)
477                {
478                        $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ".
479                        "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ".
480                        "A.id_contact = B.id_contact and B.id_connection = C.id_connection ".
481                        " and ".
482                        "A.id_owner =".$this->owner." and ".                   
483                        "D.id_group = E.id_group and ".
484                        "D.id_connection = C.id_connection and E.short_name = '".$alias.
485                        "' order by A.names_ordered";
486                                               
487                        if (!$this->db->query($query))
488                        {
489                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
490                        }
491                         
492                        $return = false;
493                       
494                       
495                        while($this->db->next_record())
496                        {
497                                $return[] = $this->db->row();
498                        }
499                       
500                        return $return;
501                }
502               
503                function insertContactsByGroup($idGroup, $contacts)
504                {                                                                       
505                       
506                        foreach($contacts as $index => $idConnection)
507                        {                       
508                                $query = "INSERT INTO phpgw_cc_contact_grps(id_group,id_connection) ".
509                                                "VALUES(".$idGroup.",".$idConnection.")";                       
510
511                                if (!$this->db->query($query))
512                                        exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);                     
513                        }
514                                                                                               
515                        return True;           
516                }
517               
518                function updateContactsByGroup($id_group, $contacts)
519                {
520                                               
521                        $query = 'select C.id_connection from phpgw_cc_contact A,'.
522                        'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '.
523                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
524                        ' and '.
525                        //'A.id_owner ='.$this->owner.' and D.id_connection = C.id_connection and D.id_group = '.$id_group.
526                        ' D.id_connection = C.id_connection and D.id_group = '.$id_group. //If I have the group ID, why ask about owner?
527                        ' order by A.names_ordered';
528                                               
529                        if (!$this->db->query($query))
530                        {
531                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
532                        }
533                         
534                        $return = false;
535                       
536                       
537                        while($this->db->next_record())
538                        {
539                                $return[] = $this->db->row();
540                                 
541                        }
542                                               
543                        $array_connections = array();
544                       
545                        if($return) {
546                                foreach($return as $index => $connection){                             
547                                        array_push($array_connections,$connection['id_connection']);
548                                }
549                        }
550                       
551                        if(!is_array($contacts))
552                                $contacts = array();
553                       
554                        if(!is_array($connections))
555                                $connections = array();                         
556                                                                       
557                        $connections_to_add     = array_diff($contacts, $array_connections);
558                        $connections_to_remove  = array_diff($array_connections,$contacts);
559                       
560                        if($connections_to_add){
561                                $this -> insertContactsByGroup($id_group, $connections_to_add); 
562                        }
563                       
564                        if($connections_to_remove){
565                                $this -> deleteContactsByGroup($id_group, $connections_to_remove);
566                        }
567                       
568                        return True;
569                }               
570               
571                function deleteContactsByGroup($id_group, $contacts = null)
572                {
573                       
574                        $query = "DELETE FROM phpgw_cc_contact_grps ";
575                       
576                        if($contacts) {                                         
577                                $index = 0;
578                               
579                                foreach($contacts as $a => $id_connection) {
580                                         
581                                        if($index++)
582                                                $query .= " OR";
583                                        else
584                                                $query .= " WHERE (";
585                                         
586                                        $query .= " id_connection = ".$id_connection;                                                                           
587                                }
588                                $query .= ") AND ";
589                        }       
590                        else
591                                $query.= " WHERE ";
592                       
593                        $query.= "id_group = ".$id_group;
594                       
595                       
596                        if (!$this->db->query($query))                 
597                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);                             
598                                                                       
599                        return True;           
600                }
601               
602                function add_user_by_name($id_group){
603                        $query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value, B.id_typeof_contact_connection'.
604                                 ' from phpgw_cc_contact A, phpgw_cc_contact_conns B, phpgw_cc_connections C'.
605                                         ' where A.id_contact = B.id_contact and B.id_connection = C.id_connection'.
606                                                ' and A.last_update = (select max(up.last_update) from phpgw_cc_contact up where up.id_owner ='.$this->owner.")".
607                                                ' and A.id_owner ='.$this->owner.' and C.connection_is_default = true'.
608                                         ' order by A.names_ordered,C.connection_value';
609                       
610                                               
611                        if (!$this->db->query($query)){
612                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
613                        }
614                         
615                        $return = array();
616                       
617                        $array_connections = array();
618                        while($this->db->next_record()){
619                                $return = $this->db->row();
620                                array_push($array_connections, $return['id_connection']);                               
621                        }                       
622                        $this -> insertContactsByGroup($id_group, $array_connections);
623                                                                       
624                }
625               
626        }
627?>
Note: See TracBrowser for help on using the repository browser.