"Pending",
"1" => "Deposit Paid",
"2" => "Fully Paid",
"3" => "Confirmed",
"9" => "Long Term"
);
function CSbooking($db, $table)
{
$this->db = $db;
$this->table = $table;
}
function setid($id)
{
$id = $this->xss_clean($id);
$this->id = $id;
}
function getid()
{
return $this->id;
}
function getfirstdate()
{
return $this->db->get_var('SELECT MIN(startdate) FROM ' . $this->table);
}
function getstartdates()
{
$sql = "SELECT LEFT(startdate,7) AS optval,
DATE_FORMAT(startdate,'%M %Y') AS optdesc,
CONCAT(LEFT(startdate,7),'-01') AS optstart,
COUNT(*) as optnum
FROM " . $this->table ."
GROUP BY optval, optdesc, optstart
ORDER BY optval DESC";
$result = $this->db->get_results($sql, ARRAY_A);
//$return = $this->db->get_var('SELECT MIN(startdate) FROM ' . $this->table);
return $result;
}
function getinitiallist($full = false)
{
if($full === True) {
$sql = "SELECT * ";
} else {
$sql = "SELECT id, property_id,
title,
startdate,
enddate,
status,
rentername,
renteremail,
rentertel ";
}
$sql .= "FROM " . $this->table . "
WHERE (startdate <= CURDATE() AND enddate >= CURDATE())
OR (MONTH(startdate) = MONTH(CURDATE()) AND YEAR(startdate) = YEAR(CURDATE()))
ORDER BY startdate DESC;";
$result = $this->db->get_results($sql, ARRAY_A);
return $result;
}
function getinitialfeedlist($full = false)
{
$sql = "SELECT * ";
$sql .= "FROM " . $this->table . "
WHERE (startdate <= CURDATE() AND enddate >= CURDATE())
OR (MONTH(startdate) = MONTH(CURDATE()) AND YEAR(startdate) = YEAR(CURDATE()))
ORDER BY startdate DESC;";
$result = $this->db->get_results($sql, ARRAY_A);
return $result;
}
function getfeedlist($val, $status = "", $month = "", $propertyid = "", $full = false) {
$val = $this->xss_clean($val);
$sql = "SELECT * ";
$sql .= "FROM " . $this->table . " ";
if($val != "" || $status != "" || $month != "" || $propertyid != "") {
$sql .= "WHERE id > 0 ";
}
if($val != "") {
$sql .= "AND (title LIKE '%" . $val . "%' OR
notes LIKE '%" . $val . "%' OR
rentername LIKE '%" . $val . "%' OR
renteremail LIKE '%" . $val . "%' OR
renternotes LIKE '%" . $val . "%') ";
}
if($status != "") {
$sql .= "AND status = '" . $status . "' ";
}
if($month != "") {
$sql .= "AND DATE_FORMAT(startdate,'%Y-%m') = '" . $month . "' ";
}
if($propertyid != "") {
$sql .= "AND property_id = " . $propertyid . " ";
}
$sql .= "ORDER BY startdate DESC;";
$result = $this->db->get_results($sql, ARRAY_A);
return $result;
}
function getsearchlist($val, $status = "", $month = "", $propertyid = "")
{
$val = $this->xss_clean($val);
$sql = "SELECT id, property_id,
title,
startdate,
enddate,
status,
rentername,
renteremail,
rentertel
FROM " . $this->table . " ";
if($val != "" || $status != "" || $month != "" || $propertyid != "") {
$sql .= "WHERE id > 0 ";
}
if($val != "") {
$sql .= "AND (title LIKE '%" . $val . "%' OR
notes LIKE '%" . $val . "%' OR
rentername LIKE '%" . $val . "%' OR
renteremail LIKE '%" . $val . "%' OR
renternotes LIKE '%" . $val . "%') ";
}
if($status != "") {
$sql .= "AND status = '" . $status . "' ";
}
if($month != "") {
$sql .= "AND DATE_FORMAT(startdate,'%Y-%m') = '" . $month . "' ";
}
if($propertyid != "") {
$sql .= "AND property_id = " . $propertyid . " ";
}
$sql .= "ORDER BY startdate DESC;";
$result = $this->db->get_results($sql, ARRAY_A);
return $result;
}
function oldgetsearchlist($val)
{
$val = $this->xss_clean($val);
$sql = "SELECT id, property_id,
title,
startdate,
enddate,
status
FROM " . $this->table . "
WHERE
title LIKE '%" . $val . "%' OR
notes LIKE '%" . $val . "%' OR
rentername LIKE '%" . $val . "%' OR
renteremail LIKE '%" . $val . "%' OR
renternotes LIKE '%" . $val . "%'
ORDER BY startdate DESC;";
$result = $this->db->get_results($sql, ARRAY_A);
return $result;
}
function getmonthlist($val)
{
$val = $this->xss_clean($val);
$sql = "SELECT id, property_id,
title,
startdate,
enddate,
status
FROM " . $this->table . "
WHERE DATE_FORMAT(startdate,'%Y-%m') = '" . $val . "'
ORDER BY startdate DESC;";
$result = $this->db->get_results($sql, ARRAY_A);
return $result;
}
function getstatuslist($val)
{
$val = $this->xss_clean($val);
$sql = "SELECT id, property_id,
title,
startdate,
enddate,
status
FROM " . $this->table . "
WHERE status = '" . $val . "'
ORDER BY startdate DESC;";
$result = $this->db->get_results($sql, ARRAY_A);
return $result;
}
function getpropertylist() {
$sql = "SELECT property_id FROM " . $this->table . " ";
$sql .= "GROUP BY property_id ORDER BY property_id";
$result = $this->db->get_results($sql, ARRAY_A);
return $result;
}
function getbooking($id = 0)
{
$lid = $id;
if($lid == 0)
{
$lid = $this->id;
}
$sql = "SELECT * FROM " . $this->table . " WHERE id = " . $lid . " LIMIT 0,1;";
$result = $this->db->get_results($sql, ARRAY_A);
if(!empty($result))
{
return $result[0];
} else {
return NULL;
}
}
function getbookings($id = 0, $num = 100, $showpending = False)
{
$lid = $id;
if($lid == 0)
{
$lid = $this->id;
}
$sql = "SELECT * FROM " . $this->table . " WHERE property_id = " . $lid;
if(!$showpending) $sql .= " AND status > 0";
$sql .= " ORDER BY id DESC LIMIT 0, $num;";
$result = $this->db->get_results($sql, ARRAY_A);
if(!is_null($result))
{
return $result;
} else {
return False;
}
}
function status($val = 0)
{
return $this->statusarray["$val"];
}
function statuslist()
{
return $this->statusarray;
}
function xss_clean($str, $charset = 'ISO-8859-1')
{
/*
* Remove Null Characters
*
* This prevents sandwiching null characters
* between ascii characters, like Java\0script.
*
*/
$str = preg_replace('/\0+/', '', $str);
$str = preg_replace('/(\\\\0)+/', '', $str);
/*
* Validate standard character entities
*
* Add a semicolon if missing. We do this to enable
* the conversion of entities to ASCII later.
*
*/
$str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str);
/*
* Validate UTF16 two byte encoding (x00)
*
* Just as above, adds a semicolon if missing.
*
*/
$str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str);
/*
* URL Decode
*
* Just in case stuff like this is submitted:
*
* Google
*
* Note: Normally urldecode() would be easier but it removes plus signs
*
*/
$str = preg_replace("/%u0([a-z0-9]{3})/i", "\\1;", $str);
$str = preg_replace("/%([a-z0-9]{2})/i", "\\1;", $str);
/*
* Convert character entities to ASCII
*
* This permits our tests below to work reliably.
* We only convert entities that are within tags since
* these are the ones that will pose security problems.
*
*/
if (preg_match_all("/<(.+?)>/si", $str, $matches))
{
for ($i = 0; $i < count($matches['0']); $i++)
{
$str = str_replace($matches['1'][$i],
$this->_html_entity_decode($matches['1'][$i], $charset),
$str);
}
}
/*
* Convert all tabs to spaces
*
* This prevents strings like this: ja vascript
* Note: we deal with spaces between characters later.
*
*/
$str = preg_replace("#\t+#", " ", $str);
/*
* Makes PHP tags safe
*
* Note: XML tags are inadvertently replaced too:
*
* '), array('<?php', '<?PHP', '<?', '?>'), $str);
/*
* Compact any exploded words
*
* This corrects words like: j a v a s c r i p t
* These words are compacted back to their correct state.
*
*/
$words = array('javascript', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window');
foreach ($words as $word)
{
$temp = '';
for ($i = 0; $i < strlen($word); $i++)
{
$temp .= substr($word, $i, 1)."\s*";
}
$temp = substr($temp, 0, -3);
$str = preg_replace('#'.$temp.'#s', $word, $str);
$str = preg_replace('#'.ucfirst($temp).'#s', ucfirst($word), $str);
}
/*
* Remove disallowed Javascript in links or img tags
*/
$str = preg_replace("#.*?#si", "", $str);
$str = preg_replace("##si", "", $str);
$str = preg_replace("#<(script|xss).*?\>#si", "", $str);
/*
* Remove JavaScript Event Handlers
*
* Note: This code is a little blunt. It removes
* the event handler and anything up to the closing >,
* but it's unlikely to be a problem.
*
*/
$str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str);
/*
* Sanitize naughty HTML elements
*
* If a tag containing any of the words in the list
* below is found, the tag gets converted to entities.
*
* So this: