source: trunk/expressoCalendar/inc/class.uicalendar.inc.php @ 665

Revision 665, 9.5 KB checked in by niltonneto, 15 years ago (diff)

Alterações feitas pelo desenvolvedor, referente ao expressoCalendar (nova agenda).
Alexandre MUller => amuller@…

Line 
1<?php
2
3include_once("class.bocalendar.inc.php");
4
5class uicalendar
6{
7        function uicalendar() {
8                $this -> daysofweek     = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
9                $this -> workweekstarts = 1;
10                $this -> workweekends   = 6;
11                $this -> workdaystarts  = 7;
12                $this -> workdayends    = 20;
13                $this -> weekDate = array();
14                $this -> db_obj = new bocalendar();
15        }
16        var $public_functions = array(
17                        'quickAdd' => True,
18                        'getViewDay' => true
19                        );
20
21        function normDec($value)
22        {
23                if ($value > 9)
24                        return $value;
25                else
26                        return "0".$value;
27        }
28
29        function quickAdd () {
30                $start = isset ($_REQUEST["start"]) ? $_REQUEST["start"] : NULL;
31                $end = isset ($_REQUEST["end"]) ? $_REQUEST["end"] : NULL;
32                $title = isset ($_REQUEST["title"]) ? $_REQUEST["title"] : NULL;
33                $description = isset ($_REQUEST["desc"]) ? $_REQUEST["desc"] : NULL;
34
35                if ($start == NULL || $end == NULL || $title == NULL)
36                        return "false;Empty field";
37                if (!eregi("^[a-zA-Z_.0-9-]*",$title))
38                        return "false;Invalid char in description";
39                if (!eregi("^[0-9]*",$start))
40                        return "false;Wrong formed text";
41                if (!eregi("^[0-9]*",$end))
42                        return "false;Wrong formed text";
43
44                return $this->db_obj->insertEvent($start, $end, $title, $description);
45        }
46
47        function saveEvent () {
48                $start = isset ($_REQUEST["start"]) ? $_REQUEST["start"] : NULL;
49                $end = isset ($_REQUEST["end"]) ? $_REQUEST["end"] : NULL;
50                $title = isset ($_REQUEST["title"]) ? $_REQUEST["title"] : NULL;
51                $description = isset ($_REQUEST["desc"]) ? $_REQUEST["desc"] : NULL;
52                $location = isset ($_REQUEST["location"]) ? $_REQUEST["location"] : NULL;       
53
54                if ($start == NULL || $end == NULL || $title == NULL)
55                        return "false;Empty field";
56                if (!eregi("^[a-zA-Z_.0-9-]*",$title))
57                        return "false;Invalid char in description";
58                if (!eregi("^[0-9]*",$start))
59                        return "false;Wrong formed text";
60                if (!eregi("^[0-9]*",$end))
61                        return "false;Wrong formed text";
62
63                return $this->db_obj->insertEvent($start, $end, $title, $description, $location);
64        }
65
66
67
68        function changeEvent()
69        {
70                $calId = isset ($_REQUEST["cal_id"]) ? $_REQUEST["cal_id"] : NULL;
71                $field = isset ($_REQUEST["field"]) ? $_REQUEST["field"] : NULL;
72                $value = isset ($_REQUEST["value"]) ? $_REQUEST["value"] : NULL;
73                if ($calId == NULL || $field == NULL || $value == NULL)
74                        return false;
75                if (!eregi("^[a-zA-Z_.]*",$field))
76                        return "<false>Wrong formed text</false>";
77                if (!eregi("^[a-zA-Z_.0-9-]*",$value))
78                        return "<false>Wrong formed text</false>";
79                if (!eregi("^[0-9]*",$calId))
80                        return "<false>Wrong formed text</false>";
81
82                return $this->db_obj->changeEvent($calId, $field, $value);
83        }
84
85        function removeEvent () {
86                $id = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
87                if ($id == NULL)
88                        return "false;Internal Problem";
89
90                return $this->db_obj->removeEventById($id);
91
92        }
93
94        function getViewDay () {
95                $dayViewTime = isset ($_REQUEST["time"]) ?  strtotime(substr($_REQUEST["time"],0,4)."-".substr($_REQUEST["time"],6,2)."-".substr($_REQUEST["time"],4,2)) : strtotime(date('Y-m-d', time()));
96                if (isset ($_REQUEST["uid"]))
97                        $this->db_obj->user_id = $_REQUEST["uid"];
98
99                $retorno = "<today>".date('Ydm',$dayViewTime)."</today>";
100                // Printing results in XML
101                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5)
102                {
103                        if($i == intval($i))
104                                $retorno.= "<workday><timeid>".$this->normDec(intval($i))."00</timeid><hour>".$this->normDec(intval($i)).":00</hour>";
105                        else
106                                $retorno.= "<workday><timeid>".$this->normDec(intval($i))."30</timeid><hour>".$this->normDec(intval($i)).":30</hour>";
107               
108                $retorno .= "</workday>";
109                }       
110                return $retorno;
111        }
112        function getEventsDay () {
113                $dayTime = isset ($_REQUEST["time"]) ?  strtotime(substr($_REQUEST["time"],0,4)."-".substr($_REQUEST["time"],6,2)."-".substr($_REQUEST["time"],4,2)) : strtotime(date('Y-m-d', time()));
114                if (isset ($_REQUEST["uid"]))
115                        $this->db_obj->user_id = $_REQUEST["uid"];
116                $fromBo = $this->db_obj->requestDayCal($dayTime);
117
118                if (is_array($fromBo))
119                        foreach ($fromBo as $line){
120                                $retorno .= "<calevent>";
121                                $retorno .= "<id>".$line['cal_id']."</id>";
122                                $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
123                                $retorno .= "<description>".htmlspecialchars($line['description'])."</description>";
124                                $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
125                                $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
126                                $retorno .= "</calevent>";
127                        }
128                return $retorno;
129        }
130
131        function getViewWeek () {
132                $dayViewTime = isset ($_REQUEST["time"]) ?  strtotime(substr($_REQUEST["time"],0,4)."-".substr($_REQUEST["time"],6,2)."-".substr($_REQUEST["time"],4,2)) : strtotime(date('Y-m-d', time()));
133                $dayViewTime -= (date('N', $dayViewTime)%7)*86400;
134                $retorno = "<today>".date('Ydm', $dayViewTime)."</today>";
135                if (isset ($_REQUEST["uid"]))
136                        $this->db_obj->user_id = $_REQUEST["uid"];
137
138                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5){
139                        if($i == intval($i))
140                                $retorno.= "<workday><timeid>".$this->normDec(intval($i))."00</timeid><hour>".$this->normDec(intval($i)).":00</hour>";
141                        else
142                                $retorno.= "<workday><timeid>".$this->normDec(intval($i))."30</timeid><hour>".$this->normDec(intval($i)).":30</hour>";
143                        $retorno .= "</workday>";
144                }
145                $currentWeekDay = date('w', $dayViewTime);
146
147                for($i = $this->workweekstarts; $i <= $this->workweekends; $i++){
148                        $retorno.= "<workweek><dayid>".date("Ydm", $dayViewTime - (($currentWeekDay-$i)*60*60*24))."</dayid><dayofweek>".$this->daysofweek[$i]."</dayofweek></workweek>";
149                }
150
151                return $retorno;
152        }
153        function getEventsWeek () {
154                $dayViewTime = isset ($_REQUEST["time"]) ?  strtotime(substr($_REQUEST["time"],0,4)."-".substr($_REQUEST["time"],6,2)."-".substr($_REQUEST["time"],4,2)) : strtotime(date('Y-m-d', time()));
155                if (isset($_REQUEST["uid"]))
156                        $this->db_obj->user_id = $_REQUEST["uid"];
157
158                $dayViewTime -= (date('N', $dayViewTime)%7)*86400;
159                $retorno = "<today>".date('Ydm', $dayViewTime)."</today>";
160                if (isset ($_REQUEST["uid"]))
161                        $this->db_obj->user_id = $_REQUEST["uid"];
162
163
164                $fromBo = $this->db_obj->requestWeekCal($dayViewTime);
165
166
167                // Printing results in XML
168                if (is_array($fromBo))
169                        foreach ($fromBo as $line) {
170                                if ($line['datetime'] > 0){
171                                        $retorno .= "<calevent>";
172                                        $retorno .= "<id>".$line['cal_id']."</id>";
173                                        $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
174                                        $retorno .= "<description>".htmlspecialchars($line['description'])."</description>";
175                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
176                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
177                                        $retorno .= "</calevent>";
178                                }
179                        }
180                return $retorno;
181        }
182
183
184        function getDetails (){
185                $eventId = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
186                $fromBo = $this->db_obj->requestDetailsEvent($eventId);
187                foreach ($fromBo[0] as $field => $line) {
188                        $buff .= "<".$field.">".$line."</".$field.">";
189                }
190                return $buff;
191        }
192        function getEventsMonth () {
193                $monthViewTime = isset ($_REQUEST["time"]) ?  strtotime(substr($_REQUEST["time"],0,4)."-".substr($_REQUEST["time"],6,2)."-".substr($_REQUEST["time"],4,2)) : strtotime(date('Y-m-d', time()));
194                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
195                if (isset($_REQUEST["uid"]))
196                        $this->db_obj->user_id = $_REQUEST["uid"];
197
198                $fromBo = $this->db_obj->requestMonthCal($todayTime);
199
200                // Printing results in XML
201                if (is_array($fromBo))
202                        foreach ($fromBo as $line) {
203                                if ($line['datetime'] > 0){
204                                        $retorno .= "<calevent>";
205                                        $retorno .= "<id>".$line['cal_id']."</id>";
206                                        $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
207                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
208                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
209                                        $retorno .= "</calevent>";
210                                }
211                        }
212                return $retorno;
213        }
214       
215        function getViewMonth () {
216                $monthViewTime = isset ($_REQUEST["time"]) ?  strtotime(substr($_REQUEST["time"],0,4)."-".substr($_REQUEST["time"],6,2)."-".substr($_REQUEST["time"],4,2)) : strtotime(date('Y-m-d', time()));
217                if (isset ($_REQUEST["uid"]))
218                        $this->db_obj->user_id = $_REQUEST["uid"];
219
220                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
221                $retorno = "<today>".date('Ydm', $monthViewTime)."</today>";
222
223                for ($i=1;$i<=date('t',$monthViewTime);$i++){
224                        if (($i % 7) == 1)
225                                $retorno .= "<workWeek>";
226                        $retorno .= "<workday><id>".date('Y',$monthViewTime).$this->normDec($i).date('m',$monthViewTime)."0000</id></workday>";
227                        if (($i % 7) == 0)
228                                $retorno .= "</workWeek>";
229                }
230
231                if (($i % 7) <= 6 && ($i % 7) > 1)
232                        $retorno .= "</workWeek>";
233
234                $currentWeekDay = date('w', $monthViewTime);
235
236                for($i = $this->workweekstarts+$currentWeekDay; $i <= $this->workweekends+$currentWeekDay; $i++){
237                        // Dayid is year+month+dayofMonth (currentDay-(dayofWeek+$i))
238                        $retorno.= "<dayofweek><dayname>".$this->daysofweek[$i%7]."</dayname></dayofweek>";
239                 }
240
241                return $retorno;
242        }
243        function getViewYear () {
244                $monthViewTime = isset ($_REQUEST["time"]) ?  strtotime(substr($_REQUEST["time"],0,4)."-".substr($_REQUEST["time"],6,2)."-".substr($_REQUEST["time"],4,2)) : strtotime(date('Y-m-d', time()));
245
246                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
247                $retorno = "<today>".date('Ydm', $monthViewTime)."</today>";
248
249                $fromBo = $this->db_obj->requestYearCal($todayTime);
250                // Printing results in XML
251                if (is_array($fromBo))
252                foreach ($fromBo as $line) {
253                        if ($line['datetime'] > 0){
254                                $retorno .= "<calevent>";
255                                $retorno .= "<id>".$line['cal_id']."</id>";
256                                $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
257                                $retorno .= "</calevent>";
258                        }
259                }
260                return $retorno;
261        }
262
263
264};
265
266?>
Note: See TracBrowser for help on using the repository browser.