source: trunk/expressoMail1_2/inc/class.db_functions.inc.php @ 154

Revision 154, 7.2 KB checked in by niltonneto, 16 years ago (diff)
  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2// DB Class Connection
3define('PHPGW_INCLUDE_ROOT','../');     
4define('PHPGW_API_INC','../phpgwapi/inc');     
5include_once(PHPGW_API_INC.'/class.db.inc.php');
6       
7class db_functions
8{       
9       
10        var $db;
11        var $user_id;
12       
13        function db_functions(){
14                $this->db = new db();           
15                $this->db->Halt_On_Error = 'no';
16                $this->db->connect(
17                                $_SESSION['phpgw_info']['expressomail']['server']['db_name'],
18                                $_SESSION['phpgw_info']['expressomail']['server']['db_host'],
19                                $_SESSION['phpgw_info']['expressomail']['server']['db_port'],
20                                $_SESSION['phpgw_info']['expressomail']['server']['db_user'],
21                                $_SESSION['phpgw_info']['expressomail']['server']['db_pass'],
22                                $_SESSION['phpgw_info']['expressomail']['server']['db_type']
23                );             
24                $this -> user_id = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];       
25        }
26
27        // BEGIN of functions.
28        function get_cc_contacts()
29        {                               
30                $result = array();
31                $stringDropDownContacts = '';
32                // Pesquisa no CC os nomes e email dos contatos.
33                $query = 'select A.names_ordered, C.connection_value from phpgw_cc_contact A,'.
34                'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
35        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
36        'and B.id_typeof_contact_connection = 1 and '.
37        'A.id_owner ='.$this -> user_id.' order by A.names_ordered';
38                               
39        if (!$this->db->query($query))
40                return null;
41                               
42               
43                while($this->db->next_record())
44                        $result[] = $this->db->row();
45
46                if (count($result) != 0)
47                {
48                        // Monta string                         
49                        foreach($result as $contact)
50                                $stringDropDownContacts = $stringDropDownContacts . $contact['names_ordered']. ';' . $contact['connection_value'] . ',';
51                        //Retira ultima virgula.
52                        $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1));
53                }
54                else
55                        return null;
56
57                return $stringDropDownContacts;
58        }
59       
60        function get_cc_groups()
61        {
62                // Pesquisa no CC os Grupos Pessoais.
63                $stringDropDownContacts = '';                   
64                $result = array();
65                $query = 'select title, short_name from phpgw_cc_groups where owner ='.$this -> user_id.' order by title';
66                // Executa a query
67                if (!$this->db->query($query))
68                return null;
69                // Retorna cada resultado               
70                while($this->db->next_record())
71                        $result[] = $this->db->row();
72                // Se houver grupos ....
73                if (count($result) != 0)
74                {       
75                        foreach($result as $group)
76                                $stringDropDownContacts .=  $group['title']. ';' . $group['short_name'] . ',';
77                        //Retira ultima virgula.
78                        $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1));
79                }
80                else
81                        return null;
82                       
83                return $stringDropDownContacts;
84        }
85       
86        function getContactsByGroupAlias($alias)
87        {
88               
89                $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ".
90                "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ".
91                "A.id_contact = B.id_contact and B.id_connection = C.id_connection ".
92                "and B.id_typeof_contact_connection = 1 and ".
93                "A.id_owner =".$this -> user_id." and ".                       
94                "D.id_group = E.id_group and ".
95                "D.id_connection = C.id_connection and E.short_name = '".$alias.
96                "' order by A.names_ordered";
97
98                if (!$this->db->query($query))
99                {
100                        exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
101                }
102
103                $return = false;
104
105                while($this->db->next_record())
106                {
107                        $return[] = $this->db->row();
108                }
109
110                return $return;
111        }
112
113        function getAddrs($array_addrs) {
114                $array_addrs_final = array();                           
115
116                for($i = 0; $i < count($array_addrs); $i++){
117                        $j = count($array_addrs_final);
118
119                        if(!strchr($array_addrs[$i],'@')
120                                        && strchr($array_addrs[$i],'<')
121                                         && strchr($array_addrs[$i],'>')) {             
122
123                                $alias = substr($array_addrs[$i], strpos($array_addrs[$i],'<'), strpos($array_addrs[$i],'>'));                         
124                                $alias = str_replace('<','', str_replace('>','',$alias));                                                                       
125                                $arrayContacts = $this -> getContactsByGroupAlias($alias);
126
127                                if($arrayContacts) {
128                                        foreach($arrayContacts as $index => $contact){
129                                                if($contact['names_ordered']) {
130                                                        $array_addrs_final[$j] = '"'.$contact['names_ordered'].'" <'.$contact['connection_value'].'>';
131                                                }
132                                                else
133                                                        $array_addrs_final[$j] = $contact['connection_value'];
134
135                                                $j++;
136                                        }
137                                }
138                        }
139                        else
140                                $array_addrs_final[$j++] = $array_addrs[$i];                                                   
141                }
142                return $array_addrs_final;
143        }
144
145        function get_dropdown_contacts(){
146               
147                $contacts = $this -> get_cc_contacts();
148                $groups = $this -> get_cc_groups();
149               
150                if(($contacts) && ($groups))
151                        $stringDropDownContacts = $contacts . ',' . $groups;
152                elseif ((!$contacts) && (!$groups))
153                        $stringDropDownContacts = '';
154                elseif (($contacts) && (!$groups))
155                        $stringDropDownContacts = $contacts;
156                elseif ((!$contacts) && ($groups))
157                        $stringDropDownContacts = $groups;
158                                       
159                return $stringDropDownContacts;
160        }
161       
162        function update_preferences($params){
163               
164                $aux = explode("##",$params['prefe_string']);
165                $new_prefe = array();
166               
167                foreach($aux as $key=>$tmp){
168                        if($key == 0){
169                                $new_prefe['max_email_per_page'] = $tmp;
170                        }
171                        if($key == 1){
172                                $new_prefe['save_deleted_msg'] = $tmp;
173                        }
174                        if($key == 2){
175                                $new_prefe['delete_trash_messages_after_n_days'] = $tmp;
176                        }
177                        if($key == 3){
178                                $new_prefe['delete_and_show_previous_message'] = $tmp;
179                        }
180                        if($key == 4){
181                                $new_prefe['alert_new_msg'] = $tmp;
182                        }
183                        if($key == 5){
184                                $new_prefe['mainscreen_showmail'] = $tmp;
185                        }
186                        if($key == 10){
187                                $new_prefe['signature'] = $tmp;
188                        }
189                        if($key == 7){
190                                $new_prefe['hide_folders'] = $tmp;
191                        }
192                        if($key == 6){
193                                $new_prefe['save_in_folder'] = $tmp;
194                        }
195                        if($key == 8){
196                                $new_prefe['line_height'] = $tmp;
197                        }
198                        if($key == 9){
199                                $new_prefe['font_size'] = $tmp;
200                        }
201                        if($key == 11){
202                                $new_prefe['use_shortcuts'] = $tmp;
203                        }
204                }
205               
206                $string_serial =  serialize($new_prefe);
207                $string_serial = get_magic_quotes_gpc() ? $string_serial : addslashes($string_serial);
208                $query = "update phpgw_preferences set preference_value = '".$string_serial."' where preference_app = 'expressoMail'".
209                                 " and preference_owner = '".$this->user_id."'";
210               
211                if (!$this->db->query($query))
212                return "Failed!";
213                else
214                        return "OK!";
215        }
216        function getUserByEmail($params){       
217                // Follow the referral
218                $email = $params['email'];
219                $query = 'select A.names_ordered, C.connection_name, C.connection_value, A.photo'.
220                                ' from phpgw_cc_contact A, phpgw_cc_contact_conns B, '.
221                                'phpgw_cc_connections C where A.id_contact = B.id_contact'.
222                                ' and B.id_connection = C.id_connection and A.id_contact ='.
223                                '(select A.id_contact from phpgw_cc_contact A, phpgw_cc_contact_conns B,'.
224                                'phpgw_cc_connections C where A.id_contact = B.id_contact'.
225                                ' and B.id_connection = C.id_connection and A.id_owner = '.$this -> user_id.
226                                ' and C.connection_value = \''.$email.'\') and '.
227                                'C.connection_is_default = true and B.id_typeof_contact_connection = 2';
228
229        if (!$this->db->query($query))
230                return null;
231
232
233                if($this->db->next_record()) {
234                        $result = $this->db->row();
235
236                        $obj =  array("cn" => $result['names_ordered'],
237                                          "email" => $email,
238                                          "type" => "personal",
239                                          "telefone" =>  $result['connection_value']);
240
241                        if($result['photo'])
242                                $_SESSION['phpgw_info']['expressomail']['contact_photo'] =  array($result['photo']);                           
243
244                        return $obj;
245                }
246                return $result;
247        }
248}
249?>
Note: See TracBrowser for help on using the repository browser.