daysofweek = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$this -> workweekstarts = 1;
$this -> workweekends = 6;
$this -> workdaystarts = 7;
$this -> workdayends = 20;
$this -> weekDate = array();
$this -> db_obj = new bocalendar();
}
var $public_functions = array(
'quickAdd' => True,
'getViewDay' => true
);
function normDec($value)
{
if ($value > 9)
return $value;
else
return "0".$value;
}
function quickAdd () {
$start = isset ($_REQUEST["start"]) ? $_REQUEST["start"] : NULL;
$end = isset ($_REQUEST["end"]) ? $_REQUEST["end"] : NULL;
$title = isset ($_REQUEST["title"]) ? $_REQUEST["title"] : NULL;
$description = isset ($_REQUEST["desc"]) ? $_REQUEST["desc"] : NULL;
if ($start == NULL || $end == NULL || $title == NULL)
return "false;Empty field";
if (!eregi("^[a-zA-Z_.0-9-]*",$title))
return "false;Invalid char in description";
if (!eregi("^[0-9]*",$start))
return "false;Wrong formed text";
if (!eregi("^[0-9]*",$end))
return "false;Wrong formed text";
return $this->db_obj->insertEvent($start, $end, $title, $description);
}
function saveEvent () {
$start = isset ($_REQUEST["start"]) ? $_REQUEST["start"] : NULL;
$end = isset ($_REQUEST["end"]) ? $_REQUEST["end"] : NULL;
$title = isset ($_REQUEST["title"]) ? $_REQUEST["title"] : NULL;
$description = isset ($_REQUEST["desc"]) ? $_REQUEST["desc"] : NULL;
$location = isset ($_REQUEST["location"]) ? $_REQUEST["location"] : NULL;
if ($start == NULL || $end == NULL || $title == NULL)
return "false;Empty field";
if (!eregi("^[a-zA-Z_.0-9-]*",$title))
return "false;Invalid char in description";
if (!eregi("^[0-9]*",$start))
return "false;Wrong formed text";
if (!eregi("^[0-9]*",$end))
return "false;Wrong formed text";
return $this->db_obj->insertEvent($start, $end, $title, $description, $location);
}
function changeEvent()
{
$calId = isset ($_REQUEST["cal_id"]) ? $_REQUEST["cal_id"] : NULL;
$field = isset ($_REQUEST["field"]) ? $_REQUEST["field"] : NULL;
$value = isset ($_REQUEST["value"]) ? $_REQUEST["value"] : NULL;
if ($calId == NULL || $field == NULL || $value == NULL)
return false;
if (!eregi("^[a-zA-Z_.]*",$field))
return "Wrong formed text";
if (!eregi("^[a-zA-Z_.0-9-]*",$value))
return "Wrong formed text";
if (!eregi("^[0-9]*",$calId))
return "Wrong formed text";
return $this->db_obj->changeEvent($calId, $field, $value);
}
function removeEvent () {
$id = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
if ($id == NULL)
return "false;Internal Problem";
return $this->db_obj->removeEventById($id);
}
function getViewDay () {
$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()));
if (isset ($_REQUEST["uid"]))
$this->db_obj->user_id = $_REQUEST["uid"];
$retorno = "".date('Ydm',$dayViewTime)."";
// Printing results in XML
for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5)
{
if($i == intval($i))
$retorno.= "".$this->normDec(intval($i))."00".$this->normDec(intval($i)).":00";
else
$retorno.= "".$this->normDec(intval($i))."30".$this->normDec(intval($i)).":30";
$retorno .= "";
}
return $retorno;
}
function getEventsDay () {
$dayTime = 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()));
if (isset ($_REQUEST["uid"]))
$this->db_obj->user_id = $_REQUEST["uid"];
if (isset ($_REQUEST["cat"]))
$this->db_obj->cat_id = $_REQUEST["cat"];
$fromBo = $this->db_obj->requestDayCal($dayTime);
if (is_array($fromBo))
foreach ($fromBo as $line){
$retorno .= "";
$retorno .= "".$line['cal_id']."";
$retorno .= "".htmlspecialchars($line['title'])."";
$retorno .= "".htmlspecialchars($line['description'])."";
$retorno .= "".($line['edatetime']*1000)."";
$retorno .= "".($line['datetime']*1000)."";
$retorno .= "";
}
return $retorno;
}
function getViewWeek () {
$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()));
$dayViewTime -= (date('N', $dayViewTime)%7)*86400;
$retorno = "".date('Ydm', $dayViewTime)."";
if (isset ($_REQUEST["uid"]))
$this->db_obj->user_id = $_REQUEST["uid"];
for($i = $this->workdaystarts; $i <= $this->workdayends; $i = $i + 0.5){
if($i == intval($i))
$retorno.= "".$this->normDec(intval($i))."00".$this->normDec(intval($i)).":00";
else
$retorno.= "".$this->normDec(intval($i))."30".$this->normDec(intval($i)).":30";
$retorno .= "";
}
$currentWeekDay = date('w', $dayViewTime);
for($i = $this->workweekstarts; $i <= $this->workweekends; $i++){
$retorno.= "".date("Ydm", $dayViewTime - (($currentWeekDay-$i)*60*60*24))."".$this->daysofweek[$i]."";
}
return $retorno;
}
function getEventsWeek () {
$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()));
if (isset($_REQUEST["uid"]))
$this->db_obj->user_id = $_REQUEST["uid"];
if (isset ($_REQUEST["cat"]))
$this->db_obj->cat_id = $_REQUEST["cat"];
$dayViewTime -= (date('N', $dayViewTime)%7)*86400;
$retorno = "".date('Ydm', $dayViewTime)."";
if (isset ($_REQUEST["uid"]))
$this->db_obj->user_id = $_REQUEST["uid"];
$fromBo = $this->db_obj->requestWeekCal($dayViewTime);
// Printing results in XML
if (is_array($fromBo))
foreach ($fromBo as $line) {
if ($line['datetime'] > 0){
$retorno .= "";
$retorno .= "".$line['cal_id']."";
$retorno .= "".htmlspecialchars($line['title'])."";
$retorno .= "".htmlspecialchars($line['description'])."";
$retorno .= "".($line['edatetime']*1000)."";
$retorno .= "".($line['datetime']*1000)."";
$retorno .= "";
}
}
return $retorno;
}
function getDetails (){
$eventId = isset ($_REQUEST["id"]) ? $_REQUEST["id"] : NULL;
$fromBo = $this->db_obj->requestDetailsEvent($eventId);
foreach ($fromBo[0] as $field => $line) {
$buff .= "<".$field.">".$line."".$field.">";
}
return $buff;
}
function getEventsMonth () {
$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()));
$todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
if (isset($_REQUEST["uid"]))
$this->db_obj->user_id = $_REQUEST["uid"];
if (isset ($_REQUEST["cat"]))
$this->db_obj->cat_id = $_REQUEST["cat"];
$fromBo = $this->db_obj->requestMonthCal($todayTime);
// Printing results in XML
if (is_array($fromBo))
foreach ($fromBo as $line) {
if ($line['datetime'] > 0){
$retorno .= "";
$retorno .= "".$line['cal_id']."";
$retorno .= "".htmlspecialchars($line['title'])."";
$retorno .= "".($line['edatetime']*1000)."";
$retorno .= "".($line['datetime']*1000)."";
$retorno .= "";
}
}
return $retorno;
}
function getViewMonth () {
$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()));
if (isset ($_REQUEST["uid"]))
$this->db_obj->user_id = $_REQUEST["uid"];
$todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
$retorno = "".date('Ydm', $monthViewTime)."";
for ($i=1;$i<=date('t',$monthViewTime);$i++){
if (($i % 7) == 1)
$retorno .= "";
$retorno .= "".date('Y',$monthViewTime).$this->normDec($i).date('m',$monthViewTime)."0000";
if (($i % 7) == 0)
$retorno .= "";
}
if (($i % 7) <= 6 && ($i % 7) > 1)
$retorno .= "";
$currentWeekDay = date('w', $monthViewTime);
for($i = ($this->workweekstarts+$currentWeekDay)-1; $i <= $this->workweekends+$currentWeekDay; $i++){
// Dayid is year+month+dayofMonth (currentDay-(dayofWeek+$i))
$retorno.= "".$this->daysofweek[$i%7]."";
}
return $retorno;
}
function getViewYear () {
$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()));
$todayTime = strtotime(date('Y-m', $monthViewTime)."-01");
$retorno = "".date('Ydm', $monthViewTime)."";
$fromBo = $this->db_obj->requestYearCal($todayTime);
// Printing results in XML
if (is_array($fromBo))
foreach ($fromBo as $line) {
if ($line['datetime'] > 0){
$retorno .= "";
$retorno .= "".$line['cal_id']."";
$retorno .= "".($line['datetime']*1000)."";
$retorno .= "";
}
}
return $retorno;
}
};
?>