source: trunk/contactcenter/inc/class.so_group.inc.php @ 284

Revision 284, 8.8 KB checked in by rafaelraymundo, 16 years ago (diff)

Vide Trac - #197, #166, #198, #199

  1. Correção de problema na leitura do arquivo configuração.
  2. Permissão do click2dial também no contactcenter.
  3. Visualização de matricula, e nro celular no resultado da pesquisa(se estiverem populados)
  4. Adicionada a leitura a Catálogos Externos
  • 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 WHERE owner = '.$this->owner;
29                       
30                        if($id != '')
31                                $query .= ' AND id_group ='.$id;
32                       
33                        $query .= ' ORDER BY title';
34                       
35                        if (!$this->db->query($query))
36                        {
37                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
38                        }
39                         
40                        $return = false;
41                       
42                        while($this->db->next_record())
43                        {
44                                $return[] = $this->db->row();
45                        }
46       
47                       
48                        return $return;
49                }
50
51                function remove_accents($string) {
52                        return strtr($string,
53                        "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ",
54                        "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy");
55                }
56               
57                function insert($data)
58                {
59                       
60                        $shortName = $this -> remove_accents(strtolower(str_replace(" ","", $data['title'])));                 
61                       
62                        $query = "INSERT INTO phpgw_cc_groups(title, owner,short_name) ".
63                                        "VALUES('".$data['title']."',".$this->owner.",'".$shortName."')";                       
64                                                                               
65                        if (!$this->db->query($query))
66                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);                             
67                                               
68                        $objSequence = $this->db->query("SELECT last_value FROM seq_phpgw_cc_groups");                 
69                        $id = $objSequence -> fields['last_value'];
70                        $this -> updateContactsByGroup($id, $data['contact_in_list']);
71
72                        return $id;             
73                }
74               
75                function update($data)
76                {
77                        $shortName = $this -> remove_accents(strtolower(str_replace(" ","", $data['title'])));
78                                               
79                        $query = "UPDATE phpgw_cc_groups SET title = '".$data['title']."',short_name = '".$shortName."' WHERE id_group = ".$data['id_group'];
80                       
81                        if (!$this->db->query($query))                 
82                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);                             
83                       
84                        $this -> updateContactsByGroup($data['id_group'], $data['contact_in_list']);           
85                                                                       
86                        return True;           
87                }
88               
89                function delete($data)
90                {
91                        $query = "DELETE FROM phpgw_cc_groups WHERE id_group = ".$data['id_group'];                     
92                                                                               
93                        if (!$this->db->query($query))                 
94                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);                             
95                                                                       
96                        $this -> deleteContactsByGroup($data['id_group'], $data['contact_in_list']);
97                                               
98                        return True;           
99                }               
100               
101                function deleteContactFromGroups($id)
102                {
103                        $query = "DELETE FROM phpgw_cc_contact_grps WHERE id_connection = ".$id;                       
104                                                                               
105                        if (!$this->db->query($query))                 
106                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);                             
107                                                                       
108                        return True;           
109                }
110               
111               
112                function selectAllContacts()
113                {
114                                               
115                        $query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value , B.id_typeof_contact_connection from phpgw_cc_contact A,'.
116                        'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
117                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection and '.
118                        'C.connection_is_default = true and B.id_typeof_contact_connection = 1 and '.
119                        'A.id_owner ='.$this->owner.' order by A.names_ordered';
120
121                                       
122                        if (!$this->db->query($query))
123                        {
124                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
125                        }
126                         
127                        $return = false;
128                       
129                        while($this->db->next_record())
130                        {
131                                $return[] = $this->db->row();
132                        }
133                       
134                        return $return;
135                }               
136               
137                function verifyContact($email)
138                {
139                        $query = 'select A.names_ordered from phpgw_cc_contact A,'.
140                        'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
141                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
142                        'and B.id_typeof_contact_connection = 1 and '.
143                        'A.id_owner ='.$this->owner.' and C.connection_value = \''.$email.'\'';
144                                               
145                        if (!$this->db->query($query))
146                        {
147                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
148                        }
149                         
150                        $return = false;
151                       
152                        while($this->db->next_record())
153                        {
154                                $row = $this->db->row();
155                                $return[] =  $row['names_ordered'];
156                        }
157                       
158                        return $return;
159                }               
160               
161                function selectContactsByGroup($idGroup)
162                {
163                        $query = 'select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A,'.
164                        'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '.
165                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
166                        'and B.id_typeof_contact_connection = 1 and '.
167                        'A.id_owner ='.$this->owner.' and D.id_connection = C.id_connection and D.id_group = '.$idGroup.
168                        ' order by A.names_ordered';
169                                               
170                        if (!$this->db->query($query))
171                        {
172                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
173                        }
174                         
175                        $return = false;
176                       
177                       
178                        while($this->db->next_record())
179                        {
180                                $return[] = $this->db->row();
181                        }
182                       
183                        return $return;
184                }
185               
186                function selectContactsByGroupAlias($alias)
187                {
188                        $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ".
189                        "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ".
190                        "A.id_contact = B.id_contact and B.id_connection = C.id_connection ".
191                        "and B.id_typeof_contact_connection = 1 and ".
192                        "A.id_owner =".$this->owner." and ".                   
193                        "D.id_group = E.id_group and ".
194                        "D.id_connection = C.id_connection and E.short_name = '".$alias.
195                        "' order by A.names_ordered";
196                                               
197                        if (!$this->db->query($query))
198                        {
199                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
200                        }
201                         
202                        $return = false;
203                       
204                       
205                        while($this->db->next_record())
206                        {
207                                $return[] = $this->db->row();
208                        }
209                       
210                        return $return;
211                }
212               
213                function insertContactsByGroup($idGroup, $contacts)
214                {                                                                       
215                       
216                        foreach($contacts as $index => $idConnection)
217                        {                       
218                                $query = "INSERT INTO phpgw_cc_contact_grps(id_group,id_connection) ".
219                                                "VALUES(".$idGroup.",".$idConnection.")";                       
220
221                                if (!$this->db->query($query))
222                                        exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);                     
223                        }
224                                                                                               
225                        return True;           
226                }
227               
228                function updateContactsByGroup($id_group, $contacts)
229                {
230                                               
231                        $query = 'select C.id_connection from phpgw_cc_contact A,'.
232                        'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '.
233                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
234                        'and B.id_typeof_contact_connection = 1 and '.
235                        'A.id_owner ='.$this->owner.' and D.id_connection = C.id_connection and D.id_group = '.$id_group.
236                        ' order by A.names_ordered';
237                                               
238                        if (!$this->db->query($query))
239                        {
240                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
241                        }
242                         
243                        $return = false;
244                       
245                       
246                        while($this->db->next_record())
247                        {
248                                $return[] = $this->db->row();
249                                 
250                        }
251                                               
252                        $array_connections = array();
253                       
254                        if($return) {
255                                foreach($return as $index => $connection){                             
256                                        array_push($array_connections,$connection['id_connection']);
257                                }
258                        }
259                       
260                        if(!is_array($contacts))
261                                $contacts = array();
262                       
263                        if(!is_array($connections))
264                                $connections = array();                         
265                                                                       
266                        $connections_to_add     = array_diff($contacts, $array_connections);
267                        $connections_to_remove  = array_diff($array_connections,$contacts);
268                       
269                        if($connections_to_add){
270                                $this -> insertContactsByGroup($id_group, $connections_to_add); 
271                        }
272                       
273                        if($connections_to_remove){
274                                $this -> deleteContactsByGroup($id_group, $connections_to_remove);
275                        }
276                       
277                        return True;
278                }               
279               
280                function deleteContactsByGroup($id_group, $contacts = null)
281                {
282                       
283                        $query = "DELETE FROM phpgw_cc_contact_grps ";
284                       
285                        if($contacts) {                                         
286                                $index = 0;
287                               
288                                foreach($contacts as $a => $id_connection) {
289                                         
290                                        if($index++)
291                                                $query .= " OR";
292                                        else
293                                                $query .= " WHERE (";
294                                         
295                                        $query .= " id_connection = ".$id_connection;                                                                           
296                                }
297                                $query .= ") AND ";
298                        }       
299                        else
300                                $query.= " WHERE ";
301                       
302                        $query.= "id_group = ".$id_group;
303                       
304                       
305                        if (!$this->db->query($query))                 
306                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);                             
307                                                                       
308                        return True;           
309                }
310        }
311?>
Note: See TracBrowser for help on using the repository browser.