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

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

* empty log message *

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