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

Revision 2, 8.8 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • 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                        $query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value from phpgw_cc_contact A,'.
115                        'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
116                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
117                        'and B.id_typeof_contact_connection = 1 and '.
118                        'A.id_owner ='.$this->owner.' order by A.names_ordered';
119                                               
120                        if (!$this->db->query($query))
121                        {
122                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
123                        }
124                         
125                        $return = false;
126                       
127                        while($this->db->next_record())
128                        {
129                                $return[] = $this->db->row();
130                        }
131                       
132                        return $return;
133                }               
134               
135                function verifyContact($email)
136                {
137                        $query = 'select A.names_ordered from phpgw_cc_contact A,'.
138                        'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
139                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
140                        'and B.id_typeof_contact_connection = 1 and '.
141                        'A.id_owner ='.$this->owner.' and C.connection_value = \''.$email.'\'';
142                                               
143                        if (!$this->db->query($query))
144                        {
145                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
146                        }
147                         
148                        $return = false;
149                       
150                        while($this->db->next_record())
151                        {
152                                $row = $this->db->row();
153                                $return[] =  $row['names_ordered'];
154                        }
155                       
156                        return $return;
157                }               
158               
159                function selectContactsByGroup($idGroup)
160                {
161                        $query = 'select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A,'.
162                        'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '.
163                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
164                        'and B.id_typeof_contact_connection = 1 and '.
165                        'A.id_owner ='.$this->owner.' and D.id_connection = C.id_connection and D.id_group = '.$idGroup.
166                        ' order by A.names_ordered';
167                                               
168                        if (!$this->db->query($query))
169                        {
170                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
171                        }
172                         
173                        $return = false;
174                       
175                       
176                        while($this->db->next_record())
177                        {
178                                $return[] = $this->db->row();
179                        }
180                       
181                        return $return;
182                }
183               
184                function selectContactsByGroupAlias($alias)
185                {
186                        $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ".
187                        "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ".
188                        "A.id_contact = B.id_contact and B.id_connection = C.id_connection ".
189                        "and B.id_typeof_contact_connection = 1 and ".
190                        "A.id_owner =".$this->owner." and ".                   
191                        "D.id_group = E.id_group and ".
192                        "D.id_connection = C.id_connection and E.short_name = '".$alias.
193                        "' order by A.names_ordered";
194                                               
195                        if (!$this->db->query($query))
196                        {
197                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
198                        }
199                         
200                        $return = false;
201                       
202                       
203                        while($this->db->next_record())
204                        {
205                                $return[] = $this->db->row();
206                        }
207                       
208                        return $return;
209                }
210               
211                function insertContactsByGroup($idGroup, $contacts)
212                {                                                                       
213                       
214                        foreach($contacts as $index => $idConnection)
215                        {                       
216                                $query = "INSERT INTO phpgw_cc_contact_grps(id_group,id_connection) ".
217                                                "VALUES(".$idGroup.",".$idConnection.")";                       
218
219                                if (!$this->db->query($query))
220                                        exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);                     
221                        }
222                                                                                               
223                        return True;           
224                }
225               
226                function updateContactsByGroup($id_group, $contacts)
227                {
228                                               
229                        $query = 'select C.id_connection from phpgw_cc_contact A,'.
230                        'phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D where '.
231                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
232                        'and B.id_typeof_contact_connection = 1 and '.
233                        'A.id_owner ='.$this->owner.' and D.id_connection = C.id_connection and D.id_group = '.$id_group.
234                        ' order by A.names_ordered';
235                                               
236                        if (!$this->db->query($query))
237                        {
238                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
239                        }
240                         
241                        $return = false;
242                       
243                       
244                        while($this->db->next_record())
245                        {
246                                $return[] = $this->db->row();
247                                 
248                        }
249                                               
250                        $array_connections = array();
251                       
252                        if($return) {
253                                foreach($return as $index => $connection){                             
254                                        array_push($array_connections,$connection['id_connection']);
255                                }
256                        }
257                       
258                        if(!is_array($contacts))
259                                $contacts = array();
260                       
261                        if(!is_array($connections))
262                                $connections = array();                         
263                                                                       
264                        $connections_to_add     = array_diff($contacts, $array_connections);
265                        $connections_to_remove  = array_diff($array_connections,$contacts);
266                       
267                        if($connections_to_add){
268                                $this -> insertContactsByGroup($id_group, $connections_to_add); 
269                        }
270                       
271                        if($connections_to_remove){
272                                $this -> deleteContactsByGroup($id_group, $connections_to_remove);
273                        }
274                       
275                        return True;
276                }               
277               
278                function deleteContactsByGroup($id_group, $contacts = null)
279                {
280                       
281                        $query = "DELETE FROM phpgw_cc_contact_grps ";
282                       
283                        if($contacts) {                                         
284                                $index = 0;
285                               
286                                foreach($contacts as $a => $id_connection) {
287                                         
288                                        if($index++)
289                                                $query .= " OR";
290                                        else
291                                                $query .= " WHERE (";
292                                         
293                                        $query .= " id_connection = ".$id_connection;                                                                           
294                                }
295                                $query .= ") AND ";
296                        }       
297                        else
298                                $query.= " WHERE ";
299                       
300                        $query.= "id_group = ".$id_group;
301                       
302                       
303                        if (!$this->db->query($query))                 
304                                exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);                             
305                                                                       
306                        return True;           
307                }
308        }
309?>
Note: See TracBrowser for help on using the repository browser.