db = new db();
$this->db->Halt_On_Error = 'no';
$this->db->connect(
$_SESSION['calendar']['server']['db_name'],
$_SESSION['calendar']['server']['db_host'],
$_SESSION['calendar']['server']['db_port'],
$_SESSION['calendar']['server']['db_user'],
$_SESSION['calendar']['server']['db_pass'],
$_SESSION['calendar']['server']['db_type']
);
$this -> user_id = $_SESSION['calendar']['user']['account_id'];
$this -> cat_id = 0;
}
var $public_functions = array(
'requestTodayCal' => True
);
// Return the events of current Day
function requestDayCal ($dayTime) {
$day = getdate($dayTime);
$query = ("SELECT * FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")."(owner = '".$this->user_id."') and ((datetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and datetime < ".(mktime(0,0,0,$day['mon'],($day['mday']+1),$day['year'])).") or (edatetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and edatetime < ".(mktime(0,0,0,$day['mon'],$day['mday']+1,$day['year']))."))");
if (!$this->db->query($query))
return false;
while($this->db->next_record())
$result[] = $this->db->row();
return $result;
}
function changeEvent ($calId,$field,$value) {
$query = ("UPDATE phpgw_cal SET ".$field."=".$value." WHERE cal_id = ".$calId.";");
if (!$this->db->query($query))
return "DB out of service or internal error";
return "";
}
// Return the events of current Day
function requestWeekCal ($dayTime) {
// Performing SQL query
$query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")." (owner = '".$this->user_id."') and ((datetime > ".$dayTime." and datetime < ".($dayTime+604800).") or (edatetime > ".$dayTime." and edatetime < ".($dayTime+604800)."))";
if (!$this->db->query($query))
return false;
while($this->db->next_record())
$result[] = $this->db->row();
return $result;
}
function requestDetailsEvent($id) {
// Performing SQL query
$query = "SELECT title, description, datetime, edatetime, groups, location FROM phpgw_cal where (owner = '".$this->user_id."') and (cal_id = ".$id.")";
if (!$this->db->query($query))
return false;
while($this->db->next_record())
$result[] = $this->db->row();
return $result;
}
// Return the events of current month
function requestMonthCal ($dayTime) {
// Performing SQL query
$day = getdate($dayTime);
$query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")." (owner = '".$this->user_id."') and ((datetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and datetime < ".mktime(0,0,0,$day['mon']+1,$day['mday'],$day['year']).") or (edatetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and edatetime < ".mktime(0,0,0,$day['month']+1,$day['day'],$day['year'])."))";
if (!$this->db->query($query))
return false;
while($this->db->next_record())
$result[] = $this->db->row();
return $result;
}
// Return the events of current Year
function requestYearCal ($dayTime) {
// Performing SQL query
$query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")." (owner = '".$this->user_id."') and ((datetime > ".$dayTime." and datetime < ".($dayTime+31104000).") or (edatetime > ".$dayTime." and edatetime < ".($dayTime+2592000)."))";
if (!$this->db->query($query))
return false;
while($this->db->next_record())
$result[] = $this->db->row();
return $result;
}
function insertEvent ($datetime, $edatetime, $title, $description, $location)
{
//Discover the event id
$query = "SELECT max(cal_id) FROM phpgw_cal";
if (!$this->db->query($query))
return false;
while($this->db->next_record())
$id = $this->db->row();
// Performing SQL insert query
$query = "INSERT INTO phpgw_cal VALUES (".($id['max']+1).", '".$_SESSION['calendar']['user']['email']."', ".$this->user_id.", null, null, ".$datetime.", ".time().",".$edatetime.", 2, 'E', 0, '".$title."', '".$description."', '".$location."', 0, null)";
if ($this->db->query($query)){
$query = "INSERT INTO phpgw_cal_user VALUES (".($id['max']+1).", ".$this->user_id.", 'A', 'u')";
if ($this->db->query($query)){
$return = "true ";
$return .= ";".($id['max']+1);
} else {
$return = "false";
$return .= ";Query failed: " . pg_last_error();
}
}
else{
$return = "false";
$return .= ";Query failed: " . pg_last_error();
}
return $return;
}
function removeEventById($id){
$query = "DELETE from phpgw_cal where cal_id = ".$id;
if ($this->db->query($query)){
$query = "DELETE from phpgw_cal_user where cal_id = ".$id;
if ($this->db->query($query))
$return = "true ";
else
{
$return = "false";
$return .= ";Query failed: " . pg_last_error();
}
}
else{
$return = "false";
$return .= ";Query failed: " . pg_last_error();
}
return $return;
}
}
?>