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

Revision 573, 7.9 KB checked in by niltonneto, 15 years ago (diff)

Impĺementações feitas pelo desenvolvedor. (Alexandre Muller

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