1 | <?php |
---|
2 | define('PHPGW_API_INC','../../phpgwapi/inc'); |
---|
3 | include_once(PHPGW_API_INC.'/class.db.inc.php'); |
---|
4 | |
---|
5 | class 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 | if (!$this->db->query($query)) |
---|
33 | return false; |
---|
34 | |
---|
35 | while($this->db->next_record()) |
---|
36 | $result[] = $this->db->row(); |
---|
37 | return $result; |
---|
38 | } |
---|
39 | |
---|
40 | function changeEvent ($calId,$field,$value) { |
---|
41 | $query = ("UPDATE phpgw_cal SET ".$field."=".$value." WHERE cal_id = ".$calId.";"); |
---|
42 | |
---|
43 | if (!$this->db->query($query)) |
---|
44 | return "<false>DB out of service or internal error</false>"; |
---|
45 | |
---|
46 | return "<true ></true >"; |
---|
47 | } |
---|
48 | |
---|
49 | // Return the events of current Day |
---|
50 | function requestWeekCal ($dayTime) { |
---|
51 | // Performing SQL query |
---|
52 | $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)."))"; |
---|
53 | if (!$this->db->query($query)) |
---|
54 | return false; |
---|
55 | |
---|
56 | while($this->db->next_record()) |
---|
57 | $result[] = $this->db->row(); |
---|
58 | |
---|
59 | return $result; |
---|
60 | } |
---|
61 | |
---|
62 | function requestDetailsEvent($id) { |
---|
63 | // Performing SQL query |
---|
64 | $query = "SELECT title, description, datetime, edatetime, groups, location FROM phpgw_cal where (owner = '".$this->user_id."') and (cal_id = ".$id.")"; |
---|
65 | if (!$this->db->query($query)) |
---|
66 | return false; |
---|
67 | |
---|
68 | while($this->db->next_record()) |
---|
69 | $result[] = $this->db->row(); |
---|
70 | |
---|
71 | return $result; |
---|
72 | } |
---|
73 | |
---|
74 | // Return the events of current Day |
---|
75 | function requestMonthCal ($dayTime) { |
---|
76 | // Performing SQL query |
---|
77 | $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)."))"; |
---|
78 | if (!$this->db->query($query)) |
---|
79 | return false; |
---|
80 | |
---|
81 | while($this->db->next_record()) |
---|
82 | $result[] = $this->db->row(); |
---|
83 | |
---|
84 | return $result; |
---|
85 | } |
---|
86 | |
---|
87 | function insertEvent ($datetime, $edatetime, $title, $description, $location) |
---|
88 | { |
---|
89 | //Discover the event id |
---|
90 | $query = "SELECT max(cal_id) FROM phpgw_cal"; |
---|
91 | if (!$this->db->query($query)) |
---|
92 | return false; |
---|
93 | |
---|
94 | while($this->db->next_record()) |
---|
95 | $id = $this->db->row(); |
---|
96 | |
---|
97 | // Performing SQL insert query |
---|
98 | $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, null, null )"; |
---|
99 | |
---|
100 | if ($this->db->query($query)){ |
---|
101 | $query = "INSERT INTO phpgw_cal_user VALUES (".($id['max']+1).", ".$this->user_id.", 'A', 'u')"; |
---|
102 | if ($this->db->query($query)){ |
---|
103 | $return = "true "; |
---|
104 | $return .= ";".($id['max']+1); |
---|
105 | } else { |
---|
106 | $return = "false"; |
---|
107 | $return .= ";Query failed: " . pg_last_error(); |
---|
108 | } |
---|
109 | |
---|
110 | } |
---|
111 | else{ |
---|
112 | $return = "false"; |
---|
113 | $return .= ";Query failed: " . pg_last_error(); |
---|
114 | } |
---|
115 | |
---|
116 | return $return; |
---|
117 | |
---|
118 | } |
---|
119 | function removeEventById($id){ |
---|
120 | $query = "DELETE from phpgw_cal where cal_id = ".$id; |
---|
121 | |
---|
122 | if ($this->db->query($query)){ |
---|
123 | $query = "DELETE from phpgw_cal_user where cal_id = ".$id; |
---|
124 | if ($this->db->query($query)) |
---|
125 | $return = "true "; |
---|
126 | else |
---|
127 | { |
---|
128 | $return = "false"; |
---|
129 | $return .= ";Query failed: " . pg_last_error(); |
---|
130 | } |
---|
131 | } |
---|
132 | else{ |
---|
133 | $return = "false"; |
---|
134 | $return .= ";Query failed: " . pg_last_error(); |
---|
135 | } |
---|
136 | |
---|
137 | return $return; |
---|
138 | |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | ?> |
---|