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

Revision 632, 8.1 KB checked in by niltonneto, 15 years ago (diff)

Modulo calendar_new renomeado para expressoCalendar

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