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 | $this -> cat_id = 0; |
---|
22 | } |
---|
23 | |
---|
24 | |
---|
25 | var $public_functions = array( |
---|
26 | 'requestTodayCal' => True |
---|
27 | ); |
---|
28 | |
---|
29 | |
---|
30 | // Return the events of current Day |
---|
31 | function requestDayCal ($dayTime) { |
---|
32 | $day = getdate($dayTime); |
---|
33 | $query = ("SELECT * FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")."(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']))."))"); |
---|
34 | if (!$this->db->query($query)) |
---|
35 | return false; |
---|
36 | |
---|
37 | while($this->db->next_record()) |
---|
38 | $result[] = $this->db->row(); |
---|
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 ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")." (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 month |
---|
77 | function requestMonthCal ($dayTime) { |
---|
78 | // Performing SQL query |
---|
79 | $day = getdate($dayTime); |
---|
80 | $query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")." (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']).")) order by datetime"; |
---|
81 | if (!$this->db->query($query)) |
---|
82 | return false; |
---|
83 | |
---|
84 | while($this->db->next_record()) |
---|
85 | $result[] = $this->db->row(); |
---|
86 | |
---|
87 | return $result; |
---|
88 | } |
---|
89 | |
---|
90 | // Return the events of current Year |
---|
91 | function requestYearCal ($dayTime) { |
---|
92 | // Performing SQL query |
---|
93 | $query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")." (owner = '".$this->user_id."') and ((datetime > ".$dayTime." and datetime < ".($dayTime+31104000).") or (edatetime > ".$dayTime." and edatetime < ".($dayTime+2592000)."))"; |
---|
94 | if (!$this->db->query($query)) |
---|
95 | return false; |
---|
96 | |
---|
97 | while($this->db->next_record()) |
---|
98 | $result[] = $this->db->row(); |
---|
99 | |
---|
100 | return $result; |
---|
101 | } |
---|
102 | |
---|
103 | function insertEvent ($datetime, $edatetime, $title, $description, $location) |
---|
104 | { |
---|
105 | // Performing SQL insert query |
---|
106 | //FIXME LOCK the table sequence is desirable |
---|
107 | $query = "INSERT INTO phpgw_cal VALUES (default, '".$_SESSION['calendar']['user']['email']."', ".$this->user_id.", null, null, ".$datetime.", ".time().",".$edatetime.", default, 'E', default, '".$title."', '".$description."', '".$location."', default, default)"; |
---|
108 | if ($this->db->query($query)){ |
---|
109 | $query = "INSERT INTO phpgw_cal_user VALUES (currval('seq_phpgw_cal'::regclass), ".$this->user_id.", 'A', 'u')"; |
---|
110 | if ($this->db->query($query)){ |
---|
111 | $return = "true "; |
---|
112 | $return .= ";".($id['max']+1); |
---|
113 | } else { |
---|
114 | $return = "false"; |
---|
115 | $return .= ";Query failed: " . pg_last_error(); |
---|
116 | } |
---|
117 | |
---|
118 | } |
---|
119 | else{ |
---|
120 | $return = "false"; |
---|
121 | $return .= ";Query failed: " . pg_last_error(); |
---|
122 | } |
---|
123 | |
---|
124 | return $return; |
---|
125 | |
---|
126 | } |
---|
127 | function removeEventById($id){ |
---|
128 | $query = "DELETE from phpgw_cal where cal_id = ".$id; |
---|
129 | |
---|
130 | if ($this->db->query($query)){ |
---|
131 | $query = "DELETE from phpgw_cal_user where cal_id = ".$id; |
---|
132 | if ($this->db->query($query)) |
---|
133 | $return = "true "; |
---|
134 | else |
---|
135 | { |
---|
136 | $return = "false"; |
---|
137 | $return .= ";Query failed: " . pg_last_error(); |
---|
138 | } |
---|
139 | } |
---|
140 | else{ |
---|
141 | $return = "false"; |
---|
142 | $return .= ";Query failed: " . pg_last_error(); |
---|
143 | } |
---|
144 | |
---|
145 | return $return; |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|
149 | ?> |
---|