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

Revision 656, 8.3 KB checked in by niltonneto, 15 years ago (diff)

Implementações 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
101                $fromBo = $this->db_obj->requestDayCal($dayViewTime);
102                // Printing results in XML
103                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5)
104                {
105                        if($i == intval($i))
106                                $retorno.= "<workday><timeid>".$this->normDec(intval($i))."00</timeid><hour>".$this->normDec(intval($i)).":00</hour>";
107                        else
108                                $retorno.= "<workday><timeid>".$this->normDec(intval($i))."30</timeid><hour>".$this->normDec(intval($i)).":30</hour>";
109               
110                $retorno .= "</workday>";
111                }
112                        if (is_array($fromBo))
113                                foreach ($fromBo as $line){
114                                        $retorno .= "<calEvent>";
115                                        $retorno .= "<id>".$line['cal_id']."</id>";
116                                        $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
117                                        $retorno .= "<description>".htmlspecialchars($line['description'])."</description>";
118                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
119                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";       
120                                        $retorno .= "</calEvent>";
121                        }
122               
123                return $retorno;
124        }
125        function getViewWeek () {
126                $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()));
127                $dayViewTime -= (date('N', $dayViewTime)%7)*86400;
128                $retorno = "<today>".date('Ydm', $dayViewTime)."</today>";
129                if (isset ($_REQUEST["uid"]))
130                        $this->db_obj->user_id = $_REQUEST["uid"];
131
132
133                $fromBo = $this->db_obj->requestWeekCal($dayViewTime);
134
135                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5){
136                        if($i == intval($i))
137                                $retorno.= "<workday><timeid>".$this->normDec(intval($i))."00</timeid><hour>".$this->normDec(intval($i)).":00</hour>";
138                        else
139                                $retorno.= "<workday><timeid>".$this->normDec(intval($i))."30</timeid><hour>".$this->normDec(intval($i)).":30</hour>";
140                        $retorno .= "</workday>";
141                }
142                $currentWeekDay = date('w', $dayViewTime);
143
144                for($i = $this->workweekstarts; $i <= $this->workweekends; $i++){
145                        $retorno.= "<workweek><dayid>".date("Ydm", $dayViewTime - (($currentWeekDay-$i)*60*60*24))."</dayid><dayofweek>".$this->daysofweek[$i]."</dayofweek></workweek>";
146                }
147
148
149                // Printing results in XML
150                if (is_array($fromBo))
151                        foreach ($fromBo as $line) {
152                                if ($line['datetime'] > 0){
153                                        $retorno .= "<calEvent>";
154                                        $retorno .= "<id>".$line['cal_id']."</id>";
155                                        $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
156                                        $retorno .= "<description>".htmlspecialchars($line['description'])."</description>";
157                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
158                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
159                                        $retorno .= "</calEvent>";
160                                }
161                        }
162                return $retorno;
163        }
164
165        function getDetails (){
166                $eventId = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
167                $fromBo = $this->db_obj->requestDetailsEvent($eventId);
168                foreach ($fromBo[0] as $field => $line) {
169                        $buff .= "<".$field.">".$line."</".$field.">";
170                }
171                return $buff;
172        }
173
174        function getViewMonth () {
175                $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()));
176                if (isset ($_REQUEST["uid"]))
177                        $this->db_obj->user_id = $_REQUEST["uid"];
178
179                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
180                $retorno = "<today>".date('Ydm', $monthViewTime)."</today>";
181                $fromBo = $this->db_obj->requestMonthCal($todayTime);
182
183                for ($i=1;$i<=date('t',$monthViewTime);$i++){
184                        if (($i % 7) == 1)
185                                $retorno .= "<workWeek>";
186                        $retorno .= "<workday><id>".date('Y',$monthViewTime).$this->normDec($i).date('m',$monthViewTime)."0000</id></workday>";
187                        if (($i % 7) == 0)
188                                $retorno .= "</workWeek>";
189                }
190
191                if (($i % 7) <= 6 && ($i % 7) > 1)
192                        $retorno .= "</workWeek>";
193
194                $currentWeekDay = date('w', $monthViewTime);
195
196                for($i = $this->workweekstarts+$currentWeekDay; $i <= $this->workweekends+$currentWeekDay; $i++){
197                        // Dayid is year+month+dayofMonth (currentDay-(dayofWeek+$i))
198                        $retorno.= "<dayofweek><dayname>".$this->daysofweek[$i%7]."</dayname></dayofweek>";
199                 }
200
201
202                // Printing results in XML
203                if (is_array($fromBo))
204                foreach ($fromBo as $line) {
205                        if ($line['datetime'] > 0){
206                                $retorno .= "<calEvent>";
207                                $retorno .= "<id>".$line['cal_id']."</id>";
208                                $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
209                                $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
210                                $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
211                                $retorno .= "</calEvent>";
212                        }
213                }
214                return $retorno;
215        }
216        function getViewYear () {
217                $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()));
218
219                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
220                $retorno = "<today>".date('Ydm', $monthViewTime)."</today>";
221
222                $fromBo = $this->db_obj->requestYearCal($todayTime);
223                // Printing results in XML
224                if (is_array($fromBo))
225                foreach ($fromBo as $line) {
226                        if ($line['datetime'] > 0){
227                                $retorno .= "<calEvent>";
228                                $retorno .= "<id>".$line['cal_id']."</id>";
229                                $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
230                                $retorno .= "</calEvent>";
231                        }
232                }
233                return $retorno;
234        }
235
236
237};
238
239?>
Note: See TracBrowser for help on using the repository browser.