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

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