source: trunk/calendar_new/inc/class.bocalendar.inc.php @ 457

Revision 457, 4.1 KB checked in by niltonneto, 16 years ago (diff)

Alterações feitas por Alexandre Muller.
Melhorias e correção na versão AJAX da Agenda.
Email: 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                $query = ("SELECT * FROM phpgw_cal where (owner = '".$this->user_id."') and ((datetime > ".$dayTime." and datetime < ".($dayTime+86400).") or (edatetime > ".$dayTime." and edatetime < ".($dayTime+86400)."))");
32
33                if (!$this->db->query($query))
34                        return false;
35
36                while($this->db->next_record())
37                        $result[] = $this->db->row();
38
39                return $result;
40        }
41
42        function changeEvent ($calId,$field,$value) {
43                $query = ("UPDATE phpgw_cal SET ".$field."=".$value." WHERE cal_id = ".$calId.";");
44
45                if (!$this->db->query($query))
46                        return "<false>DB out of service or internal error</false>";
47
48                return "<true ></true >";
49        }
50
51        // Return the events of current Day
52        function requestWeekCal ($dayTime) {
53                // Performing SQL query
54                $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)."))";
55                if (!$this->db->query($query))
56                        return false;
57
58                while($this->db->next_record())
59                        $result[] = $this->db->row();
60
61                return $result;
62        }
63
64        function requestDetailsEvent($id) {
65                // Performing SQL query
66                $query = "SELECT title, description, datetime, edatetime, groups, location FROM phpgw_cal where (owner = '".$this->user_id."') and (cal_id = ".$id.")";
67                if (!$this->db->query($query))
68                        return false;
69
70                while($this->db->next_record())
71                        $result[] = $this->db->row();
72
73                return $result;
74        }
75
76        // Return the events of current Day
77        function requestMonthCal ($dayTime) {
78                // Performing SQL query
79                $query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where (owner = '".$this->user_id."') and ((datetime > ".$dayTime." and datetime < ".($dayTime+2592000).") or (edatetime > ".$dayTime." and edatetime < ".($dayTime+2592000)."))";
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        function insertEvent ($datetime, $edatetime, $title, $description)
90        {
91                //Discover the event id
92                $query = "SELECT max(cal_id) FROM phpgw_cal";
93                if (!$this->db->query($query))
94                        return false;
95
96                while($this->db->next_record())
97                        $id = $this->db->row();
98
99
100                // Performing SQL insert query
101                $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."', null, 0, null, null, null )";
102
103                if ($this->db->query($query)){
104                        $query = "INSERT INTO phpgw_cal_user VALUES (".($id['max']+1).", ".$this->user_id.", 'A', 'u')";
105                        if ($this->db->query($query)){
106                                $return = "true ";
107                                $return .= ";".($id['max']+1);
108                        } else {
109                                $return = "false";
110                                $return .= ";Query failed: " . pg_last_error();
111                        }
112
113                }
114                else{
115                        $return = "false";
116                        $return .= ";Query failed: " . pg_last_error();
117                }
118
119                return $return;
120
121        }
122        function removeEventById($id){
123                $query = "DELETE from phpgw_cal where cal_id = ".$id;
124
125                if ($this->db->query($query)){
126                        $query = "DELETE from phpgw_cal_user where cal_id = ".$id;
127                        if ($this->db->query($query))
128                                $return = "true ";
129                        else
130                        {
131                                $return = "false";
132                                $return .= ";Query failed: " . pg_last_error();
133                        }
134                }
135                else{
136                        $return = "false";
137                        $return .= ";Query failed: " . pg_last_error();
138                }
139
140                return $return;
141
142        }
143}
144
145?>
Note: See TracBrowser for help on using the repository browser.