source: sandbox/calendar/ajax_calendar/expressoCalendar/inc/class.uicalendar.inc.php @ 696

Revision 696, 9.7 KB checked in by niltonneto, 15 years ago (diff)

Implementação do desenvolvedor (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                if (isset ($_REQUEST["cat"]))
117                        $this->db_obj->cat_id = $_REQUEST["cat"];
118
119                $fromBo = $this->db_obj->requestDayCal($dayTime);
120
121                if (is_array($fromBo))
122                        foreach ($fromBo as $line){
123                                $retorno .= "<calevent>";
124                                $retorno .= "<id>".$line['cal_id']."</id>";
125                                $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
126                                $retorno .= "<description>".htmlspecialchars($line['description'])."</description>";
127                                $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
128                                $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
129                                $retorno .= "</calevent>";
130                        }
131                return $retorno;
132        }
133
134        function getViewWeek () {
135                $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()));
136                $dayViewTime -= (date('N', $dayViewTime)%7)*86400;
137                $retorno = "<today>".date('Ydm', $dayViewTime)."</today>";
138                if (isset ($_REQUEST["uid"]))
139                        $this->db_obj->user_id = $_REQUEST["uid"];
140
141                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5){
142                        if($i == intval($i))
143                                $retorno.= "<workday><timeid>".$this->normDec(intval($i))."00</timeid><hour>".$this->normDec(intval($i)).":00</hour>";
144                        else
145                                $retorno.= "<workday><timeid>".$this->normDec(intval($i))."30</timeid><hour>".$this->normDec(intval($i)).":30</hour>";
146                        $retorno .= "</workday>";
147                }
148                $currentWeekDay = date('w', $dayViewTime);
149
150                for($i = $this->workweekstarts; $i <= $this->workweekends; $i++){
151                        $retorno.= "<workweek><dayid>".date("Ydm", $dayViewTime - (($currentWeekDay-$i)*60*60*24))."</dayid><dayofweek>".$this->daysofweek[$i]."</dayofweek></workweek>";
152                }
153
154                return $retorno;
155        }
156        function getEventsWeek () {
157                $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()));
158                if (isset($_REQUEST["uid"]))
159                        $this->db_obj->user_id = $_REQUEST["uid"];
160                if (isset ($_REQUEST["cat"]))
161                        $this->db_obj->cat_id = $_REQUEST["cat"];
162
163                $dayViewTime -= (date('N', $dayViewTime)%7)*86400;
164                $retorno = "<today>".date('Ydm', $dayViewTime)."</today>";
165                if (isset ($_REQUEST["uid"]))
166                        $this->db_obj->user_id = $_REQUEST["uid"];
167
168
169                $fromBo = $this->db_obj->requestWeekCal($dayViewTime);
170
171
172                // Printing results in XML
173                if (is_array($fromBo))
174                        foreach ($fromBo as $line) {
175                                if ($line['datetime'] > 0){
176                                        $retorno .= "<calevent>";
177                                        $retorno .= "<id>".$line['cal_id']."</id>";
178                                        $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
179                                        $retorno .= "<description>".htmlspecialchars($line['description'])."</description>";
180                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
181                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
182                                        $retorno .= "</calevent>";
183                                }
184                        }
185                return $retorno;
186        }
187
188
189        function getDetails (){
190                $eventId = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
191                $fromBo = $this->db_obj->requestDetailsEvent($eventId);
192                foreach ($fromBo[0] as $field => $line) {
193                        $buff .= "<".$field.">".$line."</".$field.">";
194                }
195                return $buff;
196        }
197        function getEventsMonth () {
198                $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()));
199                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
200                if (isset($_REQUEST["uid"]))
201                        $this->db_obj->user_id = $_REQUEST["uid"];
202                if (isset ($_REQUEST["cat"]))
203                        $this->db_obj->cat_id = $_REQUEST["cat"];
204
205                $fromBo = $this->db_obj->requestMonthCal($todayTime);
206
207                // Printing results in XML
208                if (is_array($fromBo))
209                        foreach ($fromBo as $line) {
210                                if ($line['datetime'] > 0){
211                                        $retorno .= "<calevent>";
212                                        $retorno .= "<id>".$line['cal_id']."</id>";
213                                        $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
214                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
215                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
216                                        $retorno .= "</calevent>";
217                                }
218                        }
219                return $retorno;
220        }
221       
222        function getViewMonth () {
223                $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()));
224                if (isset ($_REQUEST["uid"]))
225                        $this->db_obj->user_id = $_REQUEST["uid"];
226
227                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
228                $retorno = "<today>".date('Ydm', $monthViewTime)."</today>";
229
230                for ($i=1;$i<=date('t',$monthViewTime);$i++){
231                        if (($i % 7) == 1)
232                                $retorno .= "<workWeek>";
233                        $retorno .= "<workday><id>".date('Y',$monthViewTime).$this->normDec($i).date('m',$monthViewTime)."0000</id></workday>";
234                        if (($i % 7) == 0)
235                                $retorno .= "</workWeek>";
236                }
237
238                if (($i % 7) <= 6 && ($i % 7) > 1)
239                        $retorno .= "</workWeek>";
240
241                $currentWeekDay = date('w', $monthViewTime);
242
243                for($i = ($this->workweekstarts+$currentWeekDay)-1; $i <= $this->workweekends+$currentWeekDay; $i++){
244                        // Dayid is year+month+dayofMonth (currentDay-(dayofWeek+$i))
245                        $retorno.= "<dayofweek><dayname>".$this->daysofweek[$i%7]."</dayname></dayofweek>";
246                 }
247
248                return $retorno;
249        }
250        function getViewYear () {
251                $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()));
252
253                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
254                $retorno = "<today>".date('Ydm', $monthViewTime)."</today>";
255
256                $fromBo = $this->db_obj->requestYearCal($todayTime);
257                // Printing results in XML
258                if (is_array($fromBo))
259                foreach ($fromBo as $line) {
260                        if ($line['datetime'] > 0){
261                                $retorno .= "<calevent>";
262                                $retorno .= "<id>".$line['cal_id']."</id>";
263                                $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
264                                $retorno .= "</calevent>";
265                        }
266                }
267                return $retorno;
268        }
269
270
271};
272
273?>
Note: See TracBrowser for help on using the repository browser.