source: trunk/filemanager/inc/class.notifications.inc.php @ 7712

Revision 7712, 4.8 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Revisao das Melhorias de performance no codigo do Expresso.

Line 
1<?php
2
3define('PHPGW_INCLUDE_ROOT','../');     
4define('PHPGW_API_INC','../phpgwapi/inc');
5require_once(PHPGW_API_INC . '/class.db.inc.php');
6
7class notifications
8{
9        private $db;
10        private $db_name;
11        private $db_host;
12        private $db_port;
13        private $db_user;
14        private $db_pass;
15        private $db_type;
16
17       
18        var $public_functions = array
19        (
20                'AddEmail'                      => True,
21                'DeleteEmail'           => True,
22                'DeleteEmailUser'       => True,
23                'EmailsToSend'          => True
24        );
25       
26        public function notifications()
27        {
28                $this->db_name = $GLOBALS['phpgw_info']['server']['db_name'];
29                $this->db_host = $GLOBALS['phpgw_info']['server']['db_host'];
30                $this->db_port = $GLOBALS['phpgw_info']['server']['db_port'];
31                $this->db_user = $GLOBALS['phpgw_info']['server']['db_user'];
32                $this->db_pass = $GLOBALS['phpgw_info']['server']['db_pass'];
33                $this->db_type = $GLOBALS['phpgw_info']['server']['db_type'];
34                $this->connectDB();
35
36        }
37
38        private final function connectDB()
39        {
40                $this->db = new db();
41                $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type);         
42        }       
43       
44        public function AddEmail()
45        {       
46                if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
47                {
48                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
49                }               
50               
51                $emailFrom      = $_GET['emailFrom'];
52                $emailTo        = $_GET['emailTo'];
53                $return         = "";
54               
55                if( $this->db )
56                {
57                        $query = "SELECT * FROM phpgw_filemanager_notification WHERE email_from = '".$emailFrom."';";
58
59                        if( $this->db->query($query) )
60                        {
61                                while( $this->db->next_record())
62                                        $result[] = $this->db->row();                                   
63                        }
64                                       
65                        if( count($result) == 0 )
66                        {
67                                $query  = "INSERT INTO phpgw_filemanager_notification(email_from,email_to) VALUES('".$emailFrom."', '".$emailTo."')";
68                                $return = $emailTo;
69                        }
70                        else
71                        {
72                                $email_to       = ( $result[0]['email_to'] ) ? $result[0]['email_to'].",".$emailTo : $emailTo ;
73                                $query          = "UPDATE phpgw_filemanager_notification SET email_to = '".$email_to."' WHERE email_from = '".$emailFrom."';";
74                               
75                                $sort = explode("," , $email_to);
76                                natsort($sort);
77                               
78                                $return         = implode(",", $sort );
79                        }
80                       
81                        if( !$this->db->query($query) )
82                        {
83                                $return = "False";
84                        }
85                }
86               
87                echo $return;
88        }
89       
90        public function DeleteEmail()
91        {
92                if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
93                {
94                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
95                }               
96
97                $emailFrom      = $_GET['emailFrom'];
98                $emailTo        = $_GET['emailTo'];
99                $return         = "True";
100               
101                if( $this->db )
102                {
103                        $query = "SELECT * FROM phpgw_filemanager_notification WHERE email_from = '".$emailFrom."';";
104
105                        if( $this->db->query($query) )
106                        {
107                                while( $this->db->next_record())
108                                        $result[] = $this->db->row();                                   
109                        }
110                       
111                        $email_to = explode( ",", $result[0]['email_to'] );
112
113                        for( $i = 0 ; $i < count($email_to); ++$i )
114                        {
115                                if($email_to[$i] == $emailTo)
116                                {
117                                        unset( $email_to[$i] );
118                                }
119                        }
120                       
121                        natsort( $email_to );
122                       
123                        $return = implode(",", $email_to );
124                        $query  = "UPDATE phpgw_filemanager_notification SET email_to = '".$return."' WHERE email_from = '".$emailFrom."';";
125                       
126
127                        if( !$this->db->query($query) )
128                                $return = "False";
129                        else
130                                $return = "True";
131                }
132               
133                echo $return;
134        }
135       
136        public function DeleteEmailUser()
137        {
138                if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
139                {
140                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
141                }               
142
143                $id     = $_GET['filemanagerId'];               
144                $return = "False";
145               
146                if( $this->db )
147                {
148                        $query = "DELETE FROM phpgw_filemanager_notification WHERE filemanager_id = '".$id."';";
149
150                        if( $this->db->query( $query ) )
151                                $return = "True";
152                }
153               
154                echo $return;
155        }
156       
157        public function EmailsToSend( $pEmail )
158        {
159                $query = "SELECT * FROM  phpgw_filemanager_notification WHERE email_from = '".$pEmail."'";
160               
161                if( $this->db )
162                {
163                        if( $this->db->query($query) )
164                        {
165                                while( $this->db->next_record())
166                                        $result[] = $this->db->row();                                   
167                        }
168                }
169
170                return $result[0]['email_to'];
171        }
172       
173        public function SearchId( $pData )
174        {
175                if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
176                {
177                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
178                }               
179
180                $query = "SELECT * FROM phpgw_filemanager_notification WHERE filemanager_id ='".$pData."';";
181               
182                if( $this->db )
183                {
184                        if( $this->db->query($query) )
185                        {
186                                while( $this->db->next_record())
187                                        $result[] = $this->db->row();                                   
188                        }
189                }
190               
191                return $result;
192        }
193       
194        public function SearchEmail( $pEmail, $pLimit, $pOffset )
195        {
196                if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
197                {
198                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
199                }               
200
201                $query = "SELECT * FROM phpgw_filemanager_notification WHERE email_from like '%".$pEmail."%' " .
202                                 "ORDER BY email_from OFFSET (".$pOffset."-1)*".$pLimit." LIMIT ".$pLimit.";";
203
204                if( $this->db )
205                {
206                        if( $this->db->query($query, __LINE__, __FILE__, $pOffset) )
207                        {
208                                while( $this->db->next_record())
209                                        $result[] = $this->db->row();                                   
210                        }
211                }
212               
213                return $result;                         
214        }
215}
216
217?>
Note: See TracBrowser for help on using the repository browser.