source: branches/2.2/filemanager/inc/class.notifications.inc.php @ 3632

Revision 3632, 3.6 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1468 - Notificacao por email de uploads de arquivos enviados pelo modulo Filemanager

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        );
24       
25        public function notifications()
26        {
27                if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
28                {
29                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
30                }               
31                $this->db_name = $GLOBALS['phpgw_info']['server']['db_name'];
32                $this->db_host = $GLOBALS['phpgw_info']['server']['db_host'];
33                $this->db_port = $GLOBALS['phpgw_info']['server']['db_port'];
34                $this->db_user = $GLOBALS['phpgw_info']['server']['db_user'];
35                $this->db_pass = $GLOBALS['phpgw_info']['server']['db_pass'];
36                $this->db_type = $GLOBALS['phpgw_info']['server']['db_type'];
37                $this->connectDB();
38
39        }
40
41        private final function connectDB()
42        {
43                $this->db = new db();
44                $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type);         
45        }       
46       
47        public function AddEmail()
48        {       
49                $emailFrom      = $_GET['emailFrom'];
50                $emailTo        = $_GET['emailTo'];
51                $return         = "";
52               
53                if( $this->db )
54                {
55                        $query = "SELECT * FROM phpgw_filemanager_notification WHERE email_from = '".$emailFrom."';";
56
57                        if( $this->db->query($query) )
58                        {
59                                while( $this->db->next_record())
60                                        $result[] = $this->db->row();                                   
61                        }
62                                       
63                        if( count($result) == 0 )
64                        {
65                                $query  = "INSERT INTO phpgw_filemanager_notification(email_from,email_to) VALUES('".$emailFrom."', '".$emailTo."')";
66                                $return = $emailTo;
67                        }
68                        else
69                        {
70                                $email_to       = ( $result[0]['email_to'] ) ? $result[0]['email_to'].",".$emailTo : $emailTo ;
71                                $query          = "UPDATE phpgw_filemanager_notification SET email_to = '".$email_to."' WHERE email_from = '".$emailFrom."';";
72                               
73                                $sort = explode("," , $email_to);
74                                natsort($sort);
75                               
76                                $return         = implode(",", $sort );
77                        }
78                       
79                        if( !$this->db->query($query) )
80                        {
81                                $return = "False";
82                        }
83                }
84               
85                echo $return;
86        }
87       
88        public function DeleteEmail()
89        {
90                $emailFrom      = $_GET['emailFrom'];
91                $emailTo        = $_GET['emailTo'];
92                $return         = "True";
93               
94                if( $this->db )
95                {
96                        $query = "SELECT * FROM phpgw_filemanager_notification WHERE email_from = '".$emailFrom."';";
97
98                        if( $this->db->query($query) )
99                        {
100                                while( $this->db->next_record())
101                                        $result[] = $this->db->row();                                   
102                        }
103                       
104                        $email_to = explode( ",", $result[0]['email_to'] );
105                       
106                        for( $i = 0 ; $i < count($email_to); $i++ )
107                        {
108                                if($email_to[$i] == $emailTo)
109                                {
110                                        unset( $email_to[$i] );
111                                }
112                        }
113                       
114                        natsort( $email_to );
115                       
116                        $return = implode(",", $email_to );
117                        $query  = "UPDATE phpgw_filemanager_notification SET email_to = '".$return."' WHERE email_from = '".$emailFrom."';";
118                       
119
120                        if( !$this->db->query($query) )
121                                $return = "False";
122                        else
123                                $return = "True";
124                }
125               
126                echo $return;
127        }
128       
129        public function DeleteEmailUser()
130        {
131                $id     = $_GET['filemanagerId'];               
132                $return = "";
133               
134                if( $this->db )
135                {
136                        $query = "DELETE FROM phpgw_filemanager_notification WHERE filemanager_id = '".$id."';";
137                       
138                        if( !$this->db->query($query) )
139                                $return = "False";
140                        else
141                                $return = "True";
142                }
143               
144                echo $return;
145        }
146       
147        public function SearchEmail( $pData )
148        {
149                $query = "SELECT * FROM phpgw_filemanager_notification WHERE email_from like '%".$pData."%';";
150               
151                if( $this->db )
152                {
153                        if( $this->db->query($query) )
154                        {
155                                while( $this->db->next_record())
156                                        $result[] = $this->db->row();                                   
157                        }
158                }
159               
160                return $result;                         
161        }
162}
163
164?>
Note: See TracBrowser for help on using the repository browser.