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

Revision 492, 7.2 KB checked in by niltonneto, 16 years ago (diff)

Alterações no módulo calendar_new (em desenvolvimento).

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
17        var $public_functions = array(
18                        'quickAdd' => True,
19                        'getViewDay' => true
20                        );
21
22        function quickAdd () {
23                $start = isset ($_REQUEST["start"]) ? $_REQUEST["start"] : NULL;
24                $end = isset ($_REQUEST["end"]) ? $_REQUEST["end"] : NULL;
25                $title = isset ($_REQUEST["title"]) ? $_REQUEST["title"] : NULL;
26                $description = isset ($_REQUEST["desc"]) ? $_REQUEST["desc"] : NULL;
27
28                if ($start == NULL || $end == NULL || $title == NULL)
29                        return "false;Empty field";
30                if (!eregi("^[a-zA-Z_.0-9-]*",$title))
31                        return "false;Invalid char in description";
32                if (!eregi("^[0-9]*",$start))
33                        return "false;Wrong formed text";
34                if (!eregi("^[0-9]*",$end))
35                        return "false;Wrong formed text";
36
37                return $this->db_obj->insertEvent($start, $end, $title, $description);
38        }
39
40        function saveEvent () {
41                $start = isset ($_REQUEST["start"]) ? $_REQUEST["start"] : NULL;
42                $end = isset ($_REQUEST["end"]) ? $_REQUEST["end"] : NULL;
43                $title = isset ($_REQUEST["title"]) ? $_REQUEST["title"] : NULL;
44                $description = isset ($_REQUEST["desc"]) ? $_REQUEST["desc"] : NULL;
45                $location = isset ($_REQUEST["location"]) ? $_REQUEST["location"] : NULL;       
46
47                if ($start == NULL || $end == NULL || $title == NULL)
48                        return "false;Empty field";
49                if (!eregi("^[a-zA-Z_.0-9-]*",$title))
50                        return "false;Invalid char in description";
51                if (!eregi("^[0-9]*",$start))
52                        return "false;Wrong formed text";
53                if (!eregi("^[0-9]*",$end))
54                        return "false;Wrong formed text";
55
56                return $this->db_obj->insertEvent($start, $end, $title, $description, $location);
57        }
58
59
60
61        function changeEvent()
62        {
63                $calId = isset ($_REQUEST["cal_id"]) ? $_REQUEST["cal_id"] : NULL;
64                $field = isset ($_REQUEST["field"]) ? $_REQUEST["field"] : NULL;
65                $value = isset ($_REQUEST["value"]) ? $_REQUEST["value"] : NULL;
66                if ($calId == NULL || $field == NULL || $value == NULL)
67                        return false;
68                if (!eregi("^[a-zA-Z_.]*",$field))
69                        return "<false>Wrong formed text</false>";
70                if (!eregi("^[a-zA-Z_.0-9-]*",$value))
71                        return "<false>Wrong formed text</false>";
72                if (!eregi("^[0-9]*",$calId))
73                        return "<false>Wrong formed text</false>";
74
75                return $this->db_obj->changeEvent($calId, $field, $value);
76        }
77
78        function removeEvent () {
79                $id = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
80                if ($id == NULL)
81                        return "false;Internal Problem";
82
83                return $this->db_obj->removeEventById($id);
84
85        }
86
87        function getViewDay () {
88                $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()));
89
90                $retorno = "<today>".date('Ydm',$dayViewTime)."</today>";
91
92                $fromBo = $this->db_obj->requestDayCal($dayViewTime);
93
94
95                // Printing results in XML
96                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5){
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>".$line['title']."</title>";
109                                        $retorno .= "<description>".$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>".$line['title']."</title>";
145                                        $retorno .= "<description>".$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>".$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
204};
205
206?>
Note: See TracBrowser for help on using the repository browser.