source: trunk/calendar_new/inc/class.uicalendar.inc.php @ 600

Revision 600, 8.0 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 = 0;
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 quickAdd () {
22                $start = isset ($_REQUEST["start"]) ? $_REQUEST["start"] : NULL;
23                $end = isset ($_REQUEST["end"]) ? $_REQUEST["end"] : NULL;
24                $title = isset ($_REQUEST["title"]) ? $_REQUEST["title"] : NULL;
25                $description = isset ($_REQUEST["desc"]) ? $_REQUEST["desc"] : NULL;
26
27                if ($start == NULL || $end == NULL || $title == NULL)
28                        return "false;Empty field";
29                if (!eregi("^[a-zA-Z_.0-9-]*",$title))
30                        return "false;Invalid char in description";
31                if (!eregi("^[0-9]*",$start))
32                        return "false;Wrong formed text";
33                if (!eregi("^[0-9]*",$end))
34                        return "false;Wrong formed text";
35
36                return $this->db_obj->insertEvent($start, $end, $title, $description);
37        }
38
39        function saveEvent () {
40                $start = isset ($_REQUEST["start"]) ? $_REQUEST["start"] : NULL;
41                $end = isset ($_REQUEST["end"]) ? $_REQUEST["end"] : NULL;
42                $title = isset ($_REQUEST["title"]) ? $_REQUEST["title"] : NULL;
43                $description = isset ($_REQUEST["desc"]) ? $_REQUEST["desc"] : NULL;
44                $location = isset ($_REQUEST["location"]) ? $_REQUEST["location"] : NULL;       
45
46                if ($start == NULL || $end == NULL || $title == NULL)
47                        return "false;Empty field";
48                if (!eregi("^[a-zA-Z_.0-9-]*",$title))
49                        return "false;Invalid char in description";
50                if (!eregi("^[0-9]*",$start))
51                        return "false;Wrong formed text";
52                if (!eregi("^[0-9]*",$end))
53                        return "false;Wrong formed text";
54
55                return $this->db_obj->insertEvent($start, $end, $title, $description, $location);
56        }
57
58
59
60        function changeEvent()
61        {
62                $calId = isset ($_REQUEST["cal_id"]) ? $_REQUEST["cal_id"] : NULL;
63                $field = isset ($_REQUEST["field"]) ? $_REQUEST["field"] : NULL;
64                $value = isset ($_REQUEST["value"]) ? $_REQUEST["value"] : NULL;
65                if ($calId == NULL || $field == NULL || $value == NULL)
66                        return false;
67                if (!eregi("^[a-zA-Z_.]*",$field))
68                        return "<false>Wrong formed text</false>";
69                if (!eregi("^[a-zA-Z_.0-9-]*",$value))
70                        return "<false>Wrong formed text</false>";
71                if (!eregi("^[0-9]*",$calId))
72                        return "<false>Wrong formed text</false>";
73
74                return $this->db_obj->changeEvent($calId, $field, $value);
75        }
76
77        function removeEvent () {
78                $id = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
79                if ($id == NULL)
80                        return "false;Internal Problem";
81
82                return $this->db_obj->removeEventById($id);
83
84        }
85
86        function getViewDay () {
87                $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()));
88
89                $retorno = "<today>".date('Ydm',$dayViewTime)."</today>";
90
91                $fromBo = $this->db_obj->requestDayCal($dayViewTime);
92
93
94                // Printing results in XML
95                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5)
96                {
97                        if($i == intval($i))
98                                $retorno.= "<workday><timeid>".($i < 10 ? "0" : "").intval($i)."00</timeid><hour>".($i < 10 ? "0" : "").intval($i).":00</hour>";
99                        else
100                                $retorno.= "<workday><timeid>".($i < 10 ? "0" : "").intval($i)."30</timeid><hour>".($i < 10 ? "0" : "").intval($i).":30</hour>";
101               
102                $retorno .= "</workday>";
103                }
104                        if (is_array($fromBo))
105                                foreach ($fromBo as $line){
106                                        $retorno .= "<calEvent>";
107                                        $retorno .= "<id>".$line['cal_id']."</id>";
108                                        $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
109                                        $retorno .= "<description>".htmlspecialchars($line['description'])."</description>";
110                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
111                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";       
112                                        $retorno .= "</calEvent>";
113                        }
114               
115                return $retorno;
116        }
117        function getViewWeek () {
118                $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()));
119                $dayViewTime -= date('N', time())*86400;
120                $retorno = "<today>".date('Ydm', $dayViewTime)."</today>";
121
122                $fromBo = $this->db_obj->requestWeekCal($dayViewTime);
123
124                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5){
125                        if($i == intval($i))
126                                $retorno.= "<workday><timeid>".($i < 10 ? "0" : "").intval($i)."00</timeid><hour>".($i < 10 ? "0" : "").intval($i).":00</hour>";
127                        else
128                                $retorno.= "<workday><timeid>".($i < 10 ? "0" : "").intval($i)."30</timeid><hour>".($i < 10 ? "0" : "").intval($i).":30</hour>";
129                        $retorno .= "</workday>";
130                }
131                $currentWeekDay = date('w', $dayViewTime);
132
133                for($i = $this->workweekstarts; $i <= $this->workweekends; $i++){
134                        $retorno.= "<workweek><dayid>".date("Ydm", $dayViewTime - (($currentWeekDay-$i)*60*60*24))."</dayid><dayofweek>".$this->daysofweek[$i]."</dayofweek></workweek>";
135                 }
136
137
138                // Printing results in XML
139                if (is_array($fromBo))
140                        foreach ($fromBo as $line) {
141                                if ($line['datetime'] > 0){
142                                        $retorno .= "<calEvent>";
143                                        $retorno .= "<id>".$line['cal_id']."</id>";
144                                        $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
145                                        $retorno .= "<description>".htmlspecialchars($line['description'])."</description>";
146                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
147                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
148                                        $retorno .= "</calEvent>";
149                                }
150                        }
151                return $retorno;
152        }
153
154        function getDetails (){
155                $eventId = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
156                $fromBo = $this->db_obj->requestDetailsEvent($eventId);
157                foreach ($fromBo[0] as $field => $line) {
158                        $buff .= "<".$field.">".$line."</".$field.">";
159                }
160                return $buff;
161        }
162
163        function getViewMonth () {
164                $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()));
165
166                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
167                $retorno = "<today>".date('Ydm', $monthViewTime)."</today>";
168
169                $fromBo = $this->db_obj->requestMonthCal($todayTime);
170
171                for ($i=1;$i<=date('t',$monthViewTime);$i++){
172                        if (($i % 7) == 1)
173                                $retorno .= "<workWeek>";
174                        $retorno .= "<workday><id>".date('Y',$monthViewTime).($i<10?"0":"").$i.date('m',$monthViewTime)."0000</id></workday>";
175                        if (($i % 7) == 0)
176                                $retorno .= "</workWeek>";
177                }
178                if (($i % 7) <= 6)
179                        $retorno .= "</workWeek>";
180
181                $currentWeekDay = date('w', $monthViewTime);
182
183                for($i = $this->workweekstarts+$currentWeekDay; $i <= $this->workweekends+$currentWeekDay; $i++){
184                        // Dayid is year+month+dayofMonth (currentDay-(dayofWeek+$i))
185                        $retorno.= "<dayofweek><dayname>".$this->daysofweek[$i%7]."</dayname></dayofweek>";
186                 }
187
188
189                // Printing results in XML
190                if (is_array($fromBo))
191                foreach ($fromBo as $line) {
192                        if ($line['datetime'] > 0){
193                                $retorno .= "<calEvent>";
194                                $retorno .= "<id>".$line['cal_id']."</id>";
195                                $retorno .= "<title>".htmlspecialchars($line['title'])."</title>";
196                                $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
197                                $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
198                                $retorno .= "</calEvent>";
199                        }
200                }
201                return $retorno;
202        }
203        function getViewYear () {
204                $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()));
205
206                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
207                $retorno = "<today>".date('Ydm', $monthViewTime)."</today>";
208
209                $fromBo = $this->db_obj->requestYearCal($todayTime);
210                // Printing results in XML
211                if (is_array($fromBo))
212                foreach ($fromBo as $line) {
213                        if ($line['datetime'] > 0){
214                                $retorno .= "<calEvent>";
215                                $retorno .= "<id>".$line['cal_id']."</id>";
216                                $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
217                                $retorno .= "</calEvent>";
218                        }
219                }
220                return $retorno;
221        }
222
223
224};
225
226?>
Note: See TracBrowser for help on using the repository browser.