source: trunk/expressoCalendar/inc/class.bocalendar.inc.php @ 656

Revision 656, 4.9 KB checked in by niltonneto, 15 years ago (diff)

Implementações do desenvolvedor. amuller@…

Line 
1<?php
2define('PHPGW_API_INC','../../phpgwapi/inc');
3include_once(PHPGW_API_INC.'/class.db.inc.php');
4
5class bocalendar
6{
7        var $db;
8        function bocalendar()
9        {
10                $this->db = new db();           
11                $this->db->Halt_On_Error = 'no';
12                $this->db->connect(
13                        $_SESSION['calendar']['server']['db_name'],
14                        $_SESSION['calendar']['server']['db_host'],
15                        $_SESSION['calendar']['server']['db_port'],
16                        $_SESSION['calendar']['server']['db_user'],
17                        $_SESSION['calendar']['server']['db_pass'],
18                        $_SESSION['calendar']['server']['db_type']
19                );
20                $this -> user_id = $_SESSION['calendar']['user']['account_id'];
21        }
22
23
24        var $public_functions = array(
25                        'requestTodayCal' => True
26                        );
27
28
29        // Return the events of current Day
30        function requestDayCal ($dayTime) {
31                $day = getdate($dayTime);
32                $query = ("SELECT * FROM phpgw_cal where (owner = '".$this->user_id."') and ((datetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and datetime < ".(mktime(0,0,0,$day['mon'],($day['mday']+1),$day['year'])).") or (edatetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and edatetime < ".(mktime(0,0,0,$day['mon'],$day['mday']+1,$day['year']))."))");
33                if (!$this->db->query($query))
34                        return false;
35
36                while($this->db->next_record())
37                        $result[] = $this->db->row();
38                return $result;
39        }
40
41        function changeEvent ($calId,$field,$value) {
42                $query = ("UPDATE phpgw_cal SET ".$field."=".$value." WHERE cal_id = ".$calId.";");
43
44                if (!$this->db->query($query))
45                        return "<false>DB out of service or internal error</false>";
46
47                return "<true ></true >";
48        }
49
50        // Return the events of current Day
51        function requestWeekCal ($dayTime) {
52                // Performing SQL query
53                $query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where (owner = '".$this->user_id."') and ((datetime > ".$dayTime." and datetime < ".($dayTime+604800).") or (edatetime > ".$dayTime." and edatetime < ".($dayTime+604800)."))";
54                if (!$this->db->query($query))
55                        return false;
56
57                while($this->db->next_record())
58                        $result[] = $this->db->row();
59
60                return $result;
61        }
62
63        function requestDetailsEvent($id) {
64                // Performing SQL query
65                $query = "SELECT title, description, datetime, edatetime, groups, location FROM phpgw_cal where (owner = '".$this->user_id."') and (cal_id = ".$id.")";
66                if (!$this->db->query($query))
67                        return false;
68
69                while($this->db->next_record())
70                        $result[] = $this->db->row();
71
72                return $result;
73        }
74
75        // Return the events of current month
76        function requestMonthCal ($dayTime) {
77                // Performing SQL query
78                $day = getdate($dayTime);
79                $query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where (owner = '".$this->user_id."') and ((datetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and datetime < ".mktime(0,0,0,$day['mon']+1,$day['mday'],$day['year']).") or (edatetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and edatetime < ".mktime(0,0,0,$day['month']+1,$day['day'],$day['year'])."))";
80                if (!$this->db->query($query))
81                        return false;
82
83                while($this->db->next_record())
84                        $result[] = $this->db->row();
85
86                return $result;
87        }
88
89        // Return the events of current Year
90        function requestYearCal ($dayTime) {
91                // Performing SQL query
92                $query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where (owner = '".$this->user_id."') and ((datetime > ".$dayTime." and datetime < ".($dayTime+31104000).") or (edatetime > ".$dayTime." and edatetime < ".($dayTime+2592000)."))";
93                if (!$this->db->query($query))
94                        return false;
95
96                while($this->db->next_record())
97                        $result[] = $this->db->row();
98
99                return $result;
100        }
101
102        function insertEvent ($datetime, $edatetime, $title, $description, $location)
103        {
104                //Discover the event id
105                $query = "SELECT max(cal_id) FROM phpgw_cal";
106                if (!$this->db->query($query))
107                        return false;
108
109                while($this->db->next_record())
110                        $id = $this->db->row();
111
112                // Performing SQL insert query
113                $query = "INSERT INTO phpgw_cal VALUES (".($id['max']+1).", '".$_SESSION['calendar']['user']['email']."', ".$this->user_id.", null, null, ".$datetime.", ".time().",".$edatetime.", 2, 'E', 0, '".$title."', '".$description."', '".$location."', 0, null)";
114                if ($this->db->query($query)){
115                        $query = "INSERT INTO phpgw_cal_user VALUES (".($id['max']+1).", ".$this->user_id.", 'A', 'u')";
116                        if ($this->db->query($query)){
117                                $return = "true ";
118                                $return .= ";".($id['max']+1);
119                        } else {
120                                $return = "false";
121                                $return .= ";Query failed: " . pg_last_error();
122                        }
123
124                }
125                else{
126                        $return = "false";
127                        $return .= ";Query failed: " . pg_last_error();
128                }
129
130                return $return;
131
132        }
133        function removeEventById($id){
134                $query = "DELETE from phpgw_cal where cal_id = ".$id;
135
136                if ($this->db->query($query)){
137                        $query = "DELETE from phpgw_cal_user where cal_id = ".$id;
138                        if ($this->db->query($query))
139                                $return = "true ";
140                        else
141                        {
142                                $return = "false";
143                                $return .= ";Query failed: " . pg_last_error();
144                        }
145                }
146                else{
147                        $return = "false";
148                        $return .= ";Query failed: " . pg_last_error();
149                }
150
151                return $return;
152        }
153}
154
155?>
Note: See TracBrowser for help on using the repository browser.