source: trunk/expressoCalendar/inc/class.db_functions.inc.php @ 632

Revision 632, 7.2 KB checked in by niltonneto, 15 years ago (diff)

Modulo calendar_new renomeado para expressoCalendar

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