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

Revision 420, 6.1 KB checked in by niltonneto, 16 years ago (diff)

Commit inicial da agenda com layout usando Ajax.

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                $description = isset ($_REQUEST["desc"]) ? $_REQUEST["desc"] : NULL;
26                if ($start == NULL || $end == NULL || $description == NULL)
27                        return "false;Empty field";
28                if (!eregi("^[a-zA-Z_.0-9-]*",$description))
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, $description, $description);
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                include_once("class.bocalendar.inc.php");
69                $obj = new bocalendar();
70
71                $fromBo = $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['description']."</title>";
88                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
89                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";       
90                                        $retorno .= "</calEvent>";
91                                }
92               
93                return $retorno;
94        }
95        function getViewWeek () {
96                $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()));
97                $dayViewTime -= date('N', time())*86400;
98                $retorno = "<today>".date('Ydm', $dayViewTime)."</today>";
99
100                $fromBo = $this->db_obj->requestWeekCal($dayViewTime);
101
102                for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5){
103                        if($i == intval($i))
104                                $retorno.= "<workday><timeid>".($i < 10 ? "0" : "").intval($i)."00</timeid><hour>".($i < 10 ? "0" : "").intval($i).":00</hour>";
105                        else
106                                $retorno.= "<workday><timeid>".($i < 10 ? "0" : "").intval($i)."30</timeid><hour>".($i < 10 ? "0" : "").intval($i).":30</hour>";
107                        $retorno .= "</workday>";
108                }
109                $currentWeekDay = date('w', mktime());
110
111                for($i = $this->workweekstarts; $i <= $this->workweekends; $i++){
112                        $retorno.= "<workweek><dayid>".date("Ydm", time() - (($currentWeekDay-$i)*60*60*24))."</dayid><dayofweek>".$this->daysofweek[$i]."</dayofweek></workweek>";
113                 }
114
115
116                // Printing results in XML
117                if (is_array($fromBo))
118                        foreach ($fromBo as $line) {
119                                if ($line['datetime'] > 0){
120                                        $retorno .= "<calEvent>";
121                                        $retorno .= "<id>".$line['cal_id']."</id>";
122                                        $retorno .= "<title>".$line['description']."</title>";
123                                        $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
124                                        $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
125                                        $retorno .= "</calEvent>";
126                                }
127                        }
128                return $retorno;
129        }
130        function getViewMonth () {
131                $todayTime = strtotime(date('Y-m-d', time()));
132                $retorno = "<today>".date('Ydm', time())."</today>";
133
134                $fromBo = $this->db_obj->requestMonthCal($todayTime);
135               
136                for ($i=1;$i<=date('t');$i+=7){
137                        $retorno.= "<workWeek>";
138                        $retorno.= "<workday><id>".date('Y').$i.date('m')."0000</id></workday>";
139                        $retorno.= "<workday><id>".date('Y').($i+1).date('m')."0000</id></workday>";
140                        $retorno.= "<workday><id>".date('Y').($i+2).date('m')."0000</id></workday>";
141                        $retorno.= "<workday><id>".date('Y').($i+3).date('m')."0000</id></workday>";
142                        $retorno.= "<workday><id>".date('Y').($i+4).date('m')."0000</id></workday>";
143                        $retorno.= "<workday><id>".date('Y').($i+5).date('m')."0000</id></workday>";
144                        $retorno.= "<workday><id>".(date('Y').$i+6).date('m')."0000</id></workday>";
145                        $retorno.= "</workWeek>";
146                }
147               
148                for($i = $this->workweekstarts; $i <= $this->workweekends; $i++){
149                        // Dayid is year+month+dayofMonth (currentDay-(dayofWeek+$i))
150                        $retorno.= "<dayofweek><dayname>".$this->daysofweek[$i]."</dayname></dayofweek>";
151                 }
152
153
154                // Printing results in XML
155                if (is_array($fromBo))
156                foreach ($fromBo as $line) {
157                        if ($line['datetime'] > 0){
158                                $retorno .= "<calEvent>";
159                                $retorno .= "<id>".$line['cal_id']."</id>";
160                                $retorno .= "<title>".$line['description']."</title>";
161                                $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>";
162                                $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>";
163                                $retorno .= "</calEvent>";
164                        }
165                }
166                return $retorno;
167        }
168
169};
170
171?>
Note: See TracBrowser for help on using the repository browser.