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

Revision 420, 3.7 KB checked in by niltonneto, 16 years ago (diff)

Commit inicial da agenda com layout usando Ajax.

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        // Return the events of current Day
65        function requestMonthCal ($dayTime) {
66                // Performing SQL query
67                $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)."))";
68                if (!$this->db->query($query))
69                        return false;
70
71                while($this->db->next_record())
72                        $result[] = $this->db->row();
73
74                return $result;
75        }
76
77        function insertEvent ($datetime, $edatetime, $title, $description)
78        {
79                //Discover the event id
80                $query = "SELECT max(cal_id) FROM phpgw_cal";
81                if (!$this->db->query($query))
82                        return false;
83
84                while($this->db->next_record())
85                        $id = $this->db->row();
86
87
88                // Performing SQL insert query
89                $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 )";
90
91                if ($this->db->query($query)){
92                        $query = "INSERT INTO phpgw_cal_user VALUES (".($id['max']+1).", ".$this->user_id.", 'A', 'u')";
93                        if ($this->db->query($query)){
94                                $return = "true ";
95                                $return .= ";".($id['max']+1);
96                        } else {
97                                $return = "false";
98                                $return .= ";Query failed: " . pg_last_error();
99                        }
100
101                }
102                else{
103                        $return = "false";
104                        $return .= ";Query failed: " . pg_last_error();
105                }
106
107                return $return;
108
109        }
110        function removeEventById($id){
111                $query = "DELETE from phpgw_cal where cal_id = ".$id;
112
113                if ($this->db->query($query)){
114                        $query = "DELETE from phpgw_cal_user where cal_id = ".$id;
115                        if ($this->db->query($query))
116                                $return = "true ";
117                        else
118                        {
119                                $return = "false";
120                                $return .= ";Query failed: " . pg_last_error();
121                        }
122                }
123                else{
124                        $return = "false";
125                        $return .= ";Query failed: " . pg_last_error();
126                }
127
128                return $return;
129
130        }
131}
132
133?>
Note: See TracBrowser for help on using the repository browser.