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

Revision 464, 6.5 KB checked in by niltonneto, 16 years ago (diff)

Alterações feitas por Alexandre Muller.
Melhorias e correção na versão AJAX da Agenda.
Email: 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
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 changeEvent()
41        {
42                $calId = isset ($_REQUEST["cal_id"]) ? $_REQUEST["cal_id"] : NULL;
43                $field = isset ($_REQUEST["field"]) ? $_REQUEST["field"] : NULL;
44                $value = isset ($_REQUEST["value"]) ? $_REQUEST["value"] : NULL;
45                if ($calId == NULL || $field == NULL || $value == NULL)
46                        return false;
47                if (!eregi("^[a-zA-Z_.]*",$field))
48                        return "<false>Wrong formed text</false>";
49                if (!eregi("^[a-zA-Z_.0-9-]*",$value))
50                        return "<false>Wrong formed text</false>";
51                if (!eregi("^[0-9]*",$calId))
52                        return "<false>Wrong formed text</false>";
53
54                return $this->db_obj->changeEvent($calId, $field, $value);
55        }
56
57        function removeEvent () {
58                $id = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
59                if ($id == NULL)
60                        return "false;Internal Problem";
61
62                return $this->db_obj->removeEventById($id);
63
64        }
65
66        function getViewDay () {
67                $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()));
68
69                $retorno = "<today>".date('Ydm',$dayViewTime)."</today>";
70
71                $fromBo = $this->db_obj->requestDayCal($dayViewTime);
72
73
74                // Printing results in XML
75                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5){
76                        if($i == intval($i))
77                                $retorno.= "<workday><timeid>".($i < 10 ? "0" : "").intval($i)."00</timeid><hour>".($i < 10 ? "0" : "").intval($i).":00</hour>";
78                        else
79                                $retorno.= "<workday><timeid>".($i < 10 ? "0" : "").intval($i)."30</timeid><hour>".($i < 10 ? "0" : "").intval($i).":30</hour>";
80               
81                $retorno .= "</workday>";
82                }
83                        if (is_array($fromBo))
84                                foreach ($fromBo as $line){
85                                        $retorno .= "<calEvent>";
86                                        $retorno .= "<id>".$line['cal_id']."</id>";
87                                        $retorno .= "<title>".$line['title']."</title>";
88                                        $retorno .= "<description>".$line['description']."</description>";
89                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
90                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";       
91                                        $retorno .= "</calEvent>";
92                        }
93               
94                return $retorno;
95        }
96        function getViewWeek () {
97                $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()));
98                $dayViewTime -= date('N', time())*86400;
99                $retorno = "<today>".date('Ydm', $dayViewTime)."</today>";
100
101                $fromBo = $this->db_obj->requestWeekCal($dayViewTime);
102
103                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5){
104                        if($i == intval($i))
105                                $retorno.= "<workday><timeid>".($i < 10 ? "0" : "").intval($i)."00</timeid><hour>".($i < 10 ? "0" : "").intval($i).":00</hour>";
106                        else
107                                $retorno.= "<workday><timeid>".($i < 10 ? "0" : "").intval($i)."30</timeid><hour>".($i < 10 ? "0" : "").intval($i).":30</hour>";
108                        $retorno .= "</workday>";
109                }
110                $currentWeekDay = date('w', $dayViewTime);
111
112                for($i = $this->workweekstarts; $i <= $this->workweekends; $i++){
113                        $retorno.= "<workweek><dayid>".date("Ydm", $dayViewTime - (($currentWeekDay-$i)*60*60*24))."</dayid><dayofweek>".$this->daysofweek[$i]."</dayofweek></workweek>";
114                 }
115
116
117                // Printing results in XML
118                if (is_array($fromBo))
119                        foreach ($fromBo as $line) {
120                                if ($line['datetime'] > 0){
121                                        $retorno .= "<calEvent>";
122                                        $retorno .= "<id>".$line['cal_id']."</id>";
123                                        $retorno .= "<title>".$line['title']."</title>";
124                                        $retorno .= "<description>".$line['description']."</description>";
125                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
126                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
127                                        $retorno .= "</calEvent>";
128                                }
129                        }
130                return $retorno;
131        }
132
133        function getDetails (){
134                $eventId = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
135                $fromBo = $this->db_obj->requestDetailsEvent($eventId);
136                foreach ($fromBo[0] as $field => $line) {
137                        $buff .= "<".$field.">".$line."</".$field.">";
138                }
139                return $buff;
140        }
141
142        function getViewMonth () {
143                $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()));
144
145                $todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
146                $retorno = "<today>".date('Ydm', $monthViewTime)."</today>";
147
148                $fromBo = $this->db_obj->requestMonthCal($todayTime);
149
150                for ($i=1;$i<=date('t',$monthViewTime);$i++){
151                        if (($i % 7) == 1)
152                                $retorno .= "<workWeek>";
153                        $retorno .= "<workday><id>".date('Y',$monthViewTime).($i<10?"0":"").$i.date('m',$monthViewTime)."0000</id></workday>";
154                        if (($i % 7) == 0)
155                                $retorno .= "</workWeek>";
156                }
157                if (($i % 7) <= 6)
158                        $retorno .= "</workWeek>";
159
160                $currentWeekDay = date('w', $monthViewTime);
161
162                for($i = $this->workweekstarts+$currentWeekDay; $i <= $this->workweekends+$currentWeekDay; $i++){
163                        // Dayid is year+month+dayofMonth (currentDay-(dayofWeek+$i))
164                        $retorno.= "<dayofweek><dayname>".$this->daysofweek[$i%7]."</dayname></dayofweek>";
165                 }
166
167
168                // Printing results in XML
169                if (is_array($fromBo))
170                foreach ($fromBo as $line) {
171                        if ($line['datetime'] > 0){
172                                $retorno .= "<calEvent>";
173                                $retorno .= "<id>".$line['cal_id']."</id>";
174                                $retorno .= "<title>".$line['title']."</title>";
175                                $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
176                                $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
177                                $retorno .= "</calEvent>";
178                        }
179                }
180                return $retorno;
181        }
182
183};
184
185?>
Note: See TracBrowser for help on using the repository browser.