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

Revision 7673, 4.9 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

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            $email_to_count = count($email_to);
114                        for( $i = 0 ; $i < $email_to_count; ++$i )
115                        {
116                                if($email_to[$i] == $emailTo)
117                                {
118                                        unset( $email_to[$i] );
119                                }
120                        }
121                       
122                        natsort( $email_to );
123                       
124                        $return = implode(",", $email_to );
125                        $query  = "UPDATE phpgw_filemanager_notification SET email_to = '".$return."' WHERE email_from = '".$emailFrom."';";
126                       
127
128                        if( !$this->db->query($query) )
129                                $return = "False";
130                        else
131                                $return = "True";
132                }
133               
134                echo $return;
135        }
136       
137        public function DeleteEmailUser()
138        {
139                if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
140                {
141                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
142                }               
143
144                $id     = $_GET['filemanagerId'];               
145                $return = "False";
146               
147                if( $this->db )
148                {
149                        $query = "DELETE FROM phpgw_filemanager_notification WHERE filemanager_id = '".$id."';";
150
151                        if( $this->db->query( $query ) )
152                                $return = "True";
153                }
154               
155                echo $return;
156        }
157       
158        public function EmailsToSend( $pEmail )
159        {
160                $query = "SELECT * FROM  phpgw_filemanager_notification WHERE email_from = '".$pEmail."'";
161               
162                if( $this->db )
163                {
164                        if( $this->db->query($query) )
165                        {
166                                while( $this->db->next_record())
167                                        $result[] = $this->db->row();                                   
168                        }
169                }
170
171                return $result[0]['email_to'];
172        }
173       
174        public function SearchId( $pData )
175        {
176                if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
177                {
178                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
179                }               
180
181                $query = "SELECT * FROM phpgw_filemanager_notification WHERE filemanager_id ='".$pData."';";
182               
183                if( $this->db )
184                {
185                        if( $this->db->query($query) )
186                        {
187                                while( $this->db->next_record())
188                                        $result[] = $this->db->row();                                   
189                        }
190                }
191               
192                return $result;
193        }
194       
195        public function SearchEmail( $pEmail, $pLimit, $pOffset )
196        {
197                if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
198                {
199                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
200                }               
201
202                $query = "SELECT * FROM phpgw_filemanager_notification WHERE email_from like '%".$pEmail."%' " .
203                                 "ORDER BY email_from OFFSET (".$pOffset."-1)*".$pLimit." LIMIT ".$pLimit.";";
204
205                if( $this->db )
206                {
207                        if( $this->db->query($query, __LINE__, __FILE__, $pOffset) )
208                        {
209                                while( $this->db->next_record())
210                                        $result[] = $this->db->row();                                   
211                        }
212                }
213               
214                return $result;                         
215        }
216}
217
218?>
Note: See TracBrowser for help on using the repository browser.