[420] | 1 | <?php |
---|
| 2 | |
---|
| 3 | include_once("class.bocalendar.inc.php"); |
---|
| 4 | |
---|
| 5 | class 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 | } |
---|
[429] | 109 | $currentWeekDay = date('w', $dayViewTime); |
---|
[420] | 110 | |
---|
| 111 | for($i = $this->workweekstarts; $i <= $this->workweekends; $i++){ |
---|
[429] | 112 | $retorno.= "<workweek><dayid>".date("Ydm", $dayViewTime - (($currentWeekDay-$i)*60*60*24))."</dayid><dayofweek>".$this->daysofweek[$i]."</dayofweek></workweek>"; |
---|
[420] | 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 () { |
---|
[437] | 131 | $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())); |
---|
[420] | 132 | |
---|
[437] | 133 | $todayTime = strtotime(date('Y-m', $monthViewTime)."-01"); |
---|
| 134 | $retorno = "<today>".date('Ydm', $monthViewTime)."</today>"; |
---|
| 135 | |
---|
[420] | 136 | $fromBo = $this->db_obj->requestMonthCal($todayTime); |
---|
[437] | 137 | |
---|
| 138 | for ($i=1;$i<=date('t',$monthViewTime);$i++){ |
---|
| 139 | if (($i % 7) == 1) |
---|
| 140 | $retorno .= "<workWeek>"; |
---|
| 141 | $retorno .= "<workday><id>".date('Y',$monthViewTime).($i<10?"0":"").$i.date('m',$monthViewTime)."0000</id></workday>"; |
---|
| 142 | if (($i % 7) == 0) |
---|
| 143 | $retorno .= "</workWeek>"; |
---|
[420] | 144 | } |
---|
[437] | 145 | if (($i % 7) <= 6) |
---|
| 146 | $retorno .= "</workWeek>"; |
---|
| 147 | |
---|
| 148 | $currentWeekDay = date('w', $monthViewTime); |
---|
| 149 | |
---|
| 150 | for($i = $this->workweekstarts+$currentWeekDay; $i <= $this->workweekends+$currentWeekDay; $i++){ |
---|
[420] | 151 | // Dayid is year+month+dayofMonth (currentDay-(dayofWeek+$i)) |
---|
[437] | 152 | $retorno.= "<dayofweek><dayname>".$this->daysofweek[$i%7]."</dayname></dayofweek>"; |
---|
[420] | 153 | } |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | // Printing results in XML |
---|
| 157 | if (is_array($fromBo)) |
---|
| 158 | foreach ($fromBo as $line) { |
---|
| 159 | if ($line['datetime'] > 0){ |
---|
| 160 | $retorno .= "<calEvent>"; |
---|
| 161 | $retorno .= "<id>".$line['cal_id']."</id>"; |
---|
| 162 | $retorno .= "<title>".$line['description']."</title>"; |
---|
| 163 | $retorno .= "<edatetime>".($line['edatetime']*1000)."</edatetime>"; |
---|
| 164 | $retorno .= "<datetime>".($line['datetime']*1000)."</datetime>"; |
---|
| 165 | $retorno .= "</calEvent>"; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | return $retorno; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | }; |
---|
| 172 | |
---|
| 173 | ?> |
---|