if (!@include_once("../../inc/site_config.php")) {
if (!@include_once("../inc/site_config.php"))
include_once("inc/site_config.php");
}
include "php/dbmanip.php";
include "php/tightInput.php";
include "php/jscriptphp.php";
if(strstr($_SERVER['PHP_SELF'],'/information'))include "php/logging.php";else include "php/aff-logging.php";
include "front-end.php";
$self = $_SERVER['PHP_SELF'];
$dbh = new mysql_db($DB_HOSTNAME, $DB_USERNAME, $DB_PASSWORD, $DBNAME);
//var_dump($DB_HOSTNAME,$DB_USERNAME,$DB_PASSWORD,$DBNAME);exit;
$sunbelt_crypt_key = $CC_CRYPT_KEY; # jjj FIXME - do we need this on this site??
$tInput = new tightenInput();
if($_POST)$_POST=$tInput->inputClean($_POST);
$lgh = new logg_($dbh,"affiliates");
$lgh->setFields("aff_id","login_username","login_password");
if($_GET['action']=="signout"){$lgh->logOut();redirect("index.php");exit;}
?>
function check_access($axs){
global $dbh;
$self = $_SERVER['REQUEST_URI'];
if($axs){
$perm_list = $dbh->getdata_table("select * from permissions where user_id = '$axs'");
if($perm_list)foreach($perm_list as $perm_file){if(strstr(strtolower($self),strtolower($perm_file->perm_file_name)))$wflag=1;}
}
if($wflag)return 1;
else return 0;
}
function get_listing_base() {
$listing_base = 2500;
return $listing_base;
}
// translate pid to listing number
function pid_to_listing($pid) {
if (preg_match('/^[0-9]+$/', $pid)) {
return ($pid + get_listing_base());
}
}
// translate listing number to pid
function listing_to_pid($listing_num) {
if (preg_match('/^[0-9]+$/', $listing_num)) {
return ($listing_num - get_listing_base());
}
}
function listing_name($pid, $include_title=false) {
global $dbh;
$listing_num = pid_to_listing($pid);
if (!$listing_num) {
return false;
}
$pd = $dbh->getdata_table(
"SELECT property_title
FROM property_data
WHERE pid = '$pid'"
);
if (!$pd) {
return false;
}
$listing_name = 'Listing #'.$listing_num;
if ($include_title) {
$listing_name .= ' ('.$pd[0]->property_title.')';
}
return $listing_name;
}
?>
function clocker($direction,$stamp){ //find the next or previous saturday by timestamp
if($direction=="backward"){
if(strtolower(date('D',$stamp))=="sat")$stamp-=86400;
//run the clock back to the previous saturday
do{
$stamp-=86400;
}while(strtolower(date('D',$stamp))!='sat');
}elseif($direction=="forward"){
if(strtolower(date('D',$stamp))=="sat")$stamp+=86400;
//run the clock forward to the next saturday
do{
$stamp+=86400;
}while(strtolower(date('D',$stamp))!='sat');
}
return $stamp;
}
function day_clocker($direction,$stamp,$amtofdays){
$total_additions = $amtofdays*86400;
if($direction=="backward"){
$stamp-=$total_additions;
}elseif($direction=="forward"){
$stamp+=$total_additions;
}
return $stamp;
}
function prebooked($date1,$date2,$pid,$cuid=NULL,$req_id=NULL){// determine if date is already booked
global $dbh;
if(floor(($date2-$date1)/strtotime("+1 day",0))!=1)$date1=strtotime("+1 day",$date1);
$date2=strtotime("-1 day",$date2); //allow a one day reservation
//DOES NOT WORK WITH 1 day reservations (*should work with 1 day reservatios now)
$query = "select * from booking_info where pid = '$pid' and ('$date1' between unix_timestamp(start_date) and unix_timestamp(end_date)||'$date2' between unix_timestamp(start_date) and unix_timestamp(end_date)||unix_timestamp(end_date) between '$date1' and '$date2') and flex_deal_res = 'none'";
//echo $query;
//old query // $query = "select * from booking_info where pid = '$pid' and ((unix_timestamp(start_date) between '$date1' and '$date2')||( unix_timestamp(end_date) between '$date1' and '$date2')||'$date2' between unix_timestamp(start_date) and unix_timestamp(end_date))";
if(!(already_held($date1,$date2,$pid,$req_id))){
$abooked=$dbh->getdata_table($query);
if($abooked){
foreach($abooked as $dcheck){
// var_dump($dcheck->cuid);
if($dcheck->cuid==$cuid){return 0;}
}
return 1;
}
else return 0;
}else return 1;
}
function preflex($date1,$date2,$pid,$cuid=NULL,$req_id=NULL){// determine if date is already booked flex dates reservation
global $dbh;
if(floor(($date2-$date1)/strtotime("+1 day",0))!=1)$date1=strtotime("+1 day",$date1);
$date2=strtotime("-1 day",$date2); //allow a one day reservation
//DOES NOT WORK WITH 1 day reservations (*should work with 1 day reservatios now)
$query = "select * from booking_info where pid = '$pid' and ('$date1' between unix_timestamp(start_date) and unix_timestamp(end_date)||'$date2' between unix_timestamp(start_date) and unix_timestamp(end_date)||unix_timestamp(end_date) between '$date1' and '$date2') and flex_deal_res != 'none'";
//echo $query;
//old query // $query = "select * from booking_info where pid = '$pid' and ((unix_timestamp(start_date) between '$date1' and '$date2')||( unix_timestamp(end_date) between '$date1' and '$date2')||'$date2' between unix_timestamp(start_date) and unix_timestamp(end_date))";
$abooked= $dbh->getdata_table($query);
if($abooked){
foreach($abooked as $dcheck){
if($dcheck->cuid==$cuid){return 0;}
}
return 1;
}
else return 0;
}
function already_held($date1,$date2,$pid,$req_id){
global $dbh;
//DOES NOT WORK WITH 1 day reservations (*should work with 1 day reservatios now)
$query = "select * from book_request_table where pid = '$pid' and (paid_hold='paid'|| paid_hold='held') and (('$date1' between unix_timestamp(STR_TO_DATE(beg_day, '%m/%d/%Y')) and unix_timestamp(STR_TO_DATE(end_day, '%m/%d/%Y')) )
||
('$date2' between unix_timestamp(STR_TO_DATE(beg_day, '%m/%d/%Y')) and unix_timestamp(STR_TO_DATE(end_day, '%m/%d/%Y')))
|| (unix_timestamp(STR_TO_DATE(end_day, '%m/%d/%Y')) between '$date1' and '$date2')
||(unix_timestamp(STR_TO_DATE(beg_day, '%m/%d/%Y')) between '$date1' and '$date2'))";
//old query // $query = "select * from booking_info where pid = '$pid' and ((unix_timestamp(start_date) between '$date1' and '$date2')||( unix_timestamp(end_date) between '$date1' and '$date2')||'$date2' between unix_timestamp(start_date) and unix_timestamp(end_date))";
$abooked=$dbh->getdata_table($query);
if($abooked){
foreach($abooked as $dcheck){
if($dcheck->req_id==$req_id){return 0;}
}
return 1;
}
return 0;
}
function isBooked($date1,$numofweeks,$pid,$days="no"){ //tstamp date
global $dbh;
$mydate = $date1;$myedate=$date2;
if($days=="no")$myedate = strtotime("+ $numofweeks weeks",$date1);//604800
else $myedate= strtotime("+ $numofweeks days",$date1);
return prebooked($mydate,$myedate,$pid);
// $yranddate_b = date("Y",$date1)."-".date("m-d",$date1);
// $yranddate_e = date("Y",$myedate)."-".date("m-d",$myedate);
//determine if the saturday is already booked
// $qry = "select start_date,end_date,cuid from booking_info where pid = '$pid' and confirmation_num is not NULL AND (unix_timestamp('$yranddate_b') between unix_timestamp(start_date) and unix_timestamp(end_date)) || (unix_timestamp('$yranddate_e') between unix_timestamp(start_date) and unix_timestamp(end_date))";
// echo $qry;
/* $getbookings = $dbh->getdata_table($qry);
if($getbookings){
foreach($getbookings as $get_bookings){
$sdate = strtotime(str_replace("-","/",$get_bookings->start_date));
$edate = strtotime(str_replace("-","/",$get_bookings->end_date));
while($sdate<$edate){
// echo date("m d Y",$sdate) ."-".date("m d Y",$mydate) . " ";
$mydate = $date1;
if($days=="no")$myedate = ($numofweeks*604800)+$date1;
else $myedate=($numofweeks*86400)+$date1;
while($mydate<$myedate){
if(date("M-d-Y",$mydate)==date("M-d-Y",$sdate)){$_SESSION['book_flag']=1;return 1;}
$mydate = strtotime("+1 day",$mydate);
}
$sdate = strtotime("+1 day",$sdate);
}
}
}
return 0;
*/
}
function dayDirection($tstamp){
$dayofweek = strtolower(date("D",$tstamp));
switch($dayofweek){
case 'sun':case 'mon':case'tue':
$direction = "backward";break;
case 'wed':case 'thu':case'fri':
$direction = "forward";break;
default:$direction="neutral";break;
}
return $direction;
}
function daystoweeks($daystotal){
$daystotal = floor($daystotal);
switch($daystotal){
case $daystotal>=0&&$daystotal<=10:
$amtweeks = 1;
break;
case $daystotal>=11&&$daystotal<=17:
$amtweeks = 2;
break;
case $daystotal>=18&&$daystotal<=24:
$amtweeks = 3;
break;
case $daystotal>=25&&$daystotal<=31:
$amtweeks = 4;
break;
case $daystotal>=32&&$daystotal<=38:
$amtweeks = 5;
break;
case $daystotal>=39&&$daystotal<=45:
$amtweeks = 6;
break;
case $daystotal>=46&&$daystotal<=52:
$amtweeks = 7;
break;
case $daystotal>52:
default:
$amtweeks=0;
break;
}
return $amtweeks;
}
//daysBetween($from_date,$to_date);
function daysBetween($start,$end){
$sdate = strtotime($start);
$edate = strtotime($end);
while($sdate <= $edate){
$sdate+=86400;
}
}
function get_premium($tstamp,$dayends,$propid,&$prem_title=NULL){
global $dbh;
// echo "select distinct * from property_premium_dates where pid = '$propid' and ('$tstamp' between unix_timestamp(date_from) and unix_timestamp(date_to) || '$dayends' between unix_timestamp(date_from) and unix_timestamp(date_to)|| unix_timestamp(date_from) between '$tstamp' and '$dayends')";
$premprices = $dbh->getdata_table("select distinct * from property_premium_dates where pid = '$propid' and ('$tstamp' between unix_timestamp(date_from) and unix_timestamp(date_to) || '$dayends' between unix_timestamp(date_from) and unix_timestamp(date_to)|| unix_timestamp(date_from) between '$tstamp' and '$dayends')");
if($premprices){
foreach($premprices as $pricesprem){
$fro = strtotime(str_replace("-","/",$pricesprem->date_from));
$toand = strtotime(str_replace("-","/",$pricesprem->date_to));
while($fro<=$toand){
$starter = $tstamp;$ender = $dayends;
while($starter<$ender){
if(date("m d y",$starter)==date("m d y",$fro)){
if($pricesprem->add_sub=="subtract"){$premprice-=$pricesprem->price_difference;$prem_title=$pricesprem->premium_name;}//." discount";}
else {$premprice+=$pricesprem->price_difference;$prem_title=$pricesprem->premium_name;}//." premium";}
break 2;
}
$starter=strtotime("+1 day",$starter);
}
$fro = strtotime("+1 day",$fro);
}
}
}
return $premprice;
}
function get_special($grand_total,$tstamp,$dayends,$propid){
global $dbh;
$special_start = date("Y-m-d",$tstamp);
$special_end = date("Y-m-d",$dayends);
$spquery = "select * from specials where pid = '$propid' and ((datesp='$special_start' and datespend='$special_end')||(unix_timestamp('$special_start') between unix_timestamp(datesp) and unix_timestamp(datespend) and unix_timestamp('$special_end') between unix_timestamp(datesp) and unix_timestamp(datespend)))";
$special_offers = $dbh->getdata_table($spquery);
if($special_offers){
//var_dump(get_premium($tstamp,$dayends,$propid));
if(get_premium($tstamp,$dayends,$propid))$sp_percentage = (double)($special_offers[0]->percentage)/2;
else $sp_percentage = $special_offers[0]->percentage;
$newtotal = $grand_total-($grand_total*$sp_percentage/100);
}
if($newtotal)return $newtotal;
else return 0;
}
function getadmin($pid){
global $dbh;
$adm = $dbh->getdata_table("select adminfee from property_data where pid = '$pid'");
if($adm){
if(is_numeric($adm[0]->adminfee)){
$admin_fee = $adm[0]->adminfee;
return $admin_fee;
}
}
return 0;
}
function getcleaning($pid){
global $dbh;
$cln = $dbh->getdata_table("select cleaning_fee from property_data where pid = '$pid'");
if($cln){
if(is_numeric($cln[0]->cleaning_fee)){
$clean_fee = $cln[0]->cleaning_fee;
return $clean_fee;
}
}
return 0;
}
function detpricing($tstamp,$dayends,$propid,$incl_discount=NULL,$dont_show_breakdown=NULL){
global $dbh,$au_user;
$which_pricing=$dbh->getdata_table("select * from property_data where pid = '$propid'");
$tstamp = strtotime(date("m/d/Y",$tstamp));
$dayends = strtotime(date("m/d/Y",$dayends));
$tstampplus = strtotime("+1 day",$tstamp);
$query = "select distinct * from property_season_dates sd left join season_prices sp on sd.pid = sp.pid where (unix_timestamp(from_date) between '$tstamp' and '$dayends' || unix_timestamp(to_date) between '$tstamp' and '$dayends' || '$tstamp' between unix_timestamp(from_date) and unix_timestamp(to_date) || '$dayends' between unix_timestamp(from_date) and unix_timestamp(to_date)) and sd.pid = '$propid'";
// $query = "select * from season_dates sd left join season_prices sp on sd.pid = sp.pid where ('$tstamp' between unix_timestamp(from_date) and unix_timestamp(to_date)|| '$dayends' between unix_timestamp(from_date) and unix_timestamp(to_date)) and sd.pid = '$propid'";
// echo $query;
// alert(($dayends-$tstamp)/strtotime("+1 day",0));
$lot = ceil((($dayends-$tstamp)/strtotime("+1 day",0)));
$amtofweeks = ceil(($dayends-$tstamp)/strtotime("+1 week",0));
if($lot>1&&what_day($dayends)=="sat"&&what_day($tstamp)=="sat")$perfect_week=1;
if($lot>1&&(what_day($dayends)=="sat"&&what_day($tstamp)!="sat")||(what_day($tstamp)=="sat"&&what_day($dayends)!="sat"))$rate_cap=1; //pricing cap initializer
if($lot>=7)$weeklytrip=1;else $weeklytrip=0;
$presult = $dbh->getdata_table($query);
if($presult){
foreach($presult as $tseasonp){
$pricerun = strtotime($tseasonp->from_date);$pricestop = strtotime($tseasonp->to_date);
while($pricerun<=$pricestop){
$trun = $tstamp;
while($trun < $dayends){
if(date("m d y",$trun)==date("m d y",$pricerun)){
$szn = strtolower($tseasonp->season);
if($which_pricing[0]->pr_model=="new"){
$divisor = get_divisor($trun,$propid);
if($rate_cap){if($rate_max<$tseasonp->$szn)$rate_max = (float)$tseasonp->$szn;}//what if we cross seasons which $rate is the cap rate?
if($perfect_week){$dailyprice = $tseasonp->$szn/7;}
else{
if($divisor)$dailyprice = $tseasonp->$szn / $divisor;
else{echo "Pricing Error: No Divisor Set"; return NULL;}
}
}else{
if($rate_cap){if($rate_max<$tseasonp->$szn)$rate_max = (float)$tseasonp->$szn;}//what if we cross seasons which $rate is the cap rate?
if($weeklytrip==0){
if(detweekday($trun)=="weekend")$dailyprice=$tseasonp->$szn/4;
else $dailyprice = $tseasonp->$szn/6;
}else $dailyprice = $tseasonp->$szn/7;
}
if($lot>=5){ //new addition for monthly percentage discounts
$reservation_day = abs(round((strtotime("12:00pm",$trun) - strtotime("12:00pm",$tstamp))/strtotime("+1 day",0)))+1;
if($perfect_week)$day_to_start_adding = 14;
else $day_to_start_adding = 5;
if($reservation_day>=$day_to_start_adding){
$gp = get_monthly_percentage_discount($propid,$trun);
if($reservation_day==$day_to_start_adding){$gp=5;} //on the 5th or 14th day add a 5 percent discount
if($gp > 0 && $reservation_day <= 28){
//conglomerate total discounted percentage for percentage drop from overall total below
$monthly_percentage_drop+=$gp;
//echo "$reservation_day: + $gp = $monthly_percentage_drop ";
//$gp=1;
//$incl_discount=NULL;
}
$gp=NULL;
}
}
$ptotal+=$dailyprice;//add the daily price in to the reservation total
$showthaprice.="$dailyprice - $szn - ".date("m d y",$trun). " " .detweekday($trun) . " ";
//echo "$dailyprice - $szn - ".date("m d y",$trun). " " .detweekday($trun) . " ";
//echo $incl_discount;
}
$trun = strtotime("+1 day",$trun);
}
$pricerun = strtotime("+1 day",$pricerun);
}
}
if($rate_cap)if($ptotal>$rate_max*$amtofweeks)$ptotal=$rate_max*$amtofweeks;
if($dont_show_breakdown==NULL){
echo "
";
echo $showthaprice;
echo "
";
}
$special_total = get_special($ptotal,$tstamp,$dayends,$propid); //this line is necessary and should be outside the following conditional
//var_dump($special_total);
$ptholder = $ptotal; //hold the calculated price for appropriate discounting when combining the
//discount overlay discount with the monthly percentage discount
if(isset($incl_discount)){
//if its a special offer, include the specials offers price
if($special_total)$ptotal=$special_total; //include either a special price total or a discount overlay special, not BOTH
else $discount=calc_discount($ptotal,$tstamp,$dayends,$propid);
if($discount)$ptotal = $discount;
}
//subtract the congolmerated monthly percentage drop for appropriate stays
if($monthly_percentage_drop)$ptotal = $ptotal - ($ptholder * ($monthly_percentage_drop/100));
//check for premiums, and add to or subtract from the grand total
//if this is a special offer, do not include premiums in the price
if(!$special_total)$premium_price = get_premium($tstamp,$dayends,$propid);
$adm = getadmin($propid);
$cln = getcleaning($propid);
$grandtotal = $ptotal + $premium_price + $adm + $cln;
//minimum reservation price is $300 as of now 6/15/2009
//minimum reservation price is $300 as of now 4/27/2010
if($grandtotal<500)$grandtotal=500;
}
if($au_user){
$agi = $dbh->getdata_table("select * from affiliates aff where aff.aff_id = '$au_user->me'");
if($agi){
$agi = $agi[0];
$agtype = $agi->discount_type;
if($agtype=="percentage"){
$upercentage = $agi->discount_amount;
$grandtotal = $grandtotal - ($grandtotal * ($upercentage / 100));
}
elseif($agtype=="flat"){
$flat_discount = $agi->discount_amount;
$grandtotal = $grandtotal - $flat_discount;
}
}
}
return $grandtotal;
}
function get_monthly_percentage_discount($pid,$atstamp){
global $dbh;
$tseason = whatSeason($atstamp,$pid);
$phrase = $tseason."_monthly_percent";
$apercent = $dbh->getdata_table("select $phrase from season_prices where pid = '$pid'");
if($apercent){
$apercent=$apercent[0];
$daily_discount = $apercent->$phrase;
}else return 0;
return $daily_discount;
}
function get_divisor($stamp,$pid){
global $dbh,$self;
$alldiv = $dbh->getdata_table("select * from pricing_divide where pid='$pid'");
$dayname=strtolower(date("D",$stamp));
return $alldiv[0]->$dayname;
}
function calc_discount($grandtotal,$tstamp,$dayends,$propid){
global $dbh;
$today = strtotime("noon",mktime());
$days = ceil(($dayends-$tstamp)/strtotime("+1 day",0));
$daily_rate = $grandtotal/$days;
// $trip_day = strtotime("noon",$tstamp);
// $weeks = ceil(($trip_day-$today)/604800);
//in order to get a discount overlay discount, the stay must be longer than or equivalent to the seasons length requirement
$sz = (int)get_tag_along_minimum($tstamp,$propid);
$dp = discount_percentage($tstamp,$dayends,$propid);
if($sz<=$days) return $grandtotal-($grandtotal*($dp/100)); //if the amount of days is greater than the season minimum return discounted_price
else return $grandtotal; //otherwise return the regular grand total
/* if($sz<=$days){ //USE THIS CODE IF YOU WANT TO RE-ENACT THE DISCOUNT PRICING PER DAY, AS OF NOW discount_percentage function handles this functionality
while($tstamp<$dayends){
$trip_day = strtotime("noon",$tstamp);
$weeks = ceil(($tstamp-$today)/strtotime("+1 week",0));
if($weeks<1&&$trip_day>=$today)$weeks=1;
if($weeks>=52)$weeks=52;
$discount_query = "select * from discount where week = '$weeks' && pid = '$propid'";
// echo $discount_query;
$find_discount = $dbh->getdata_table($discount_query);
$jseason = whatSeason($tstamp,$propid);
if(strtolower($jseason)=="mid"||strtolower($jseason)=="low"||strtolower($jseason)=="high")$dis_var = "lowmidhigh";
else $dis_var="peak";
if($find_discount){
$dpercent = $find_discount[0]->$dis_var;
$daily_discounted_price=$daily_rate-($daily_rate*$dp/100);
}else $daily_discounted_price=$daily_rate;
// echo date("M d Y",$tstamp)." = $daily_discounted_price - " .($daily_discounted_price+($daily_rate*$dpercent/100))." - $weeks weeks - $dpercent% ";
$price_total+=$daily_discounted_price;
// var_dump($daily_discounted_price);
// $discounted_total = ceil($grandtotal-($grandtotal*$dpercent/100));
$tstamp=strtotime("+1 day",$tstamp);
}
}else $price_total = $grand_total;
return $price_total;
*/
}
function discount_percentage($tstamp,$dayends,$propid){
global $dbh;
$today = strtotime("noon",mktime());
while($tstamp<$dayends){
$weeks = ceil(($tstamp-$today)/strtotime("+1 week",0));
if($weeks>52)$weeks=52;
if($oldweeks!=$weeks)$weeks_discount = $dbh->getdata_table($wk_d_query="select * from discount where week='$weeks' and pid = '$propid'");
//echo $wk_d_query;
$jseason = whatSeason($tstamp,$propid);
if(strtolower($jseason)=="mid"||strtolower($jseason)=="low"||strtolower($jseason)=="high")$dis_var = "lowmidhigh";
else $dis_var="peak";
$discount = $weeks_discount[0]->$dis_var;
if($lowest_discount&&$discount<$lowest_discount)$lowest_discount=$discount;
elseif(!$lowest_discount)$lowest_discount=$discount;
$oldweeks = $weeks;
// $adon.="week='$weeks'|| ";
$tstamp = strtotime("+1 day",$tstamp);
}
return $lowest_discount;
}
//calculte prices following determining dates
function detweekday($dtime){
$dayofweek = strtolower(date('D',$dtime));
switch($dayofweek){
case'sun':case 'sat':case 'fri':case'thu':
$determine = "weekend";break;
case 'mon':case 'tue':case'wed':
$determine = "weekday";break;
default:break;
}
return $determine;
}
function whatSeason($start_date,$property){
global $dbh;$pid=$property;
if(strstr($start_date,"/"))$start_date = strtotime($start_date);
// if(strstr($start_date,"/"))$start_date=strtotime("1:00am",$start_date);
$start_date=strtotime("midnight",$start_date);
// $query = "select * from season_dates sd left join season_prices sp on sd.pid = sp.pid where sd.pid = '$pid'"; WAY OLDER QUERY INCLUDING LONG MULTIPLE LOOPING
$query = "select distinct *,unix_timestamp(from_date),unix_timestamp(to_date) from property_season_dates sd where pid = '$pid' and ('$start_date' between unix_timestamp(from_date) and unix_timestamp(to_date))";
// echo "$query ";exit;
$sprices = $dbh->getdata_table($query);
if($sprices)return $sprices[0]->season;
else return 0;
}
function what_day($date1){
return strtolower(date('D',$date1));
}
function reservation_balance($cuid){
global $dbh;
$query = "select *, concat_ws(' ',b.first_name, b.last_name) as fullname from booking_info as b left join property_data as p on p.pid = b.pid where cuid='$cuid' order by b.dt desc";
$gettotal = $dbh->getdata_table($query);
$query_sum = "select * from payments where cuid = '$cuid' and additional_revenue = 'no'";
// echo $query_sum;
$paid_already = $dbh->getdata_table($query_sum);
if($paid_already)foreach($paid_already as $pa)if($pa->payment_credit=="payment")$dep_paid += $pa->amount;elseif($pa->payment_credit=="credit")$dep_paid-=$pa->amount;else echo "Error: No payment type defined";
$activity_totals = round($dep_paid,2);
$reservation_price = round((float)$gettotal[0]->price_paid,2);
$res_balance = $reservation_price-$activity_totals;
// var_dump($res_balance);
//if($res_balance<0.01)$res_balance=0; //floating point subtraction issues hack
return $res_balance;
}
function reservation_payments($cuid,$optouthomeowner=NULL,&$management_money=NULL){
global $dbh;
$query_sum = "select * from payments where additional_revenue = 'no' and cuid = '$cuid'";
$paid_already = $dbh->getdata_table($query_sum);
if($paid_already){
foreach($paid_already as $pa){
if($optouthomeowner){
if($pa->payment_credit=="payment")$dep_paid += $pa->amount;
if($pa->payment_credit=="payment"&&$pa->management_fee=="yes")$management_money += $pa->amount;
//elseif($pa->payment_credit=="credit")$dep_paid-=$pa->amount;
//else echo "Error: No payment type defined";
}else{
if($pa->payment_creator!="homeowner"){
if($pa->payment_credit=="payment")$dep_paid += $pa->amount;
if($pa->payment_credit=="payment"&&$pa->management_fee=="yes")$management_money += $pa->amount;
//elseif($pa->payment_credit=="credit")$dep_paid-=$pa->amount;
//else echo "Error: No payment type defined";
}
}
}
}
return $dep_paid;
}
function get_tag_along_minimum($requested_date,$pid){
global $dbh;
$szn = strtolower(whatSeason($requested_date,$pid));
$sznvar = "tag_".$szn;
$min_find = $dbh->getdata_table("select * from property_season_dates sd left join season_prices sp on sd.pid = sp.pid where sp.pid = '$pid'");
$night_min=$min_find[0]->$sznvar;
return $night_min;
}
/*
function detweeklypricing($tstamp,$dayends,$propid){
global $dbh;$pid = $propid;
// create a usable array of premium dates with corresponding prices
$premprices = $dbh->getdata_table("select * from property_premium_dates where pid = '$pid' and '$tstamp' between unix_timestamp(date_from) and unix_timestamp(date_to)");
if($premprices){
$xcount = 0;
$dset = 0;
foreach($premprices as $pricesprem){
$fro = strtotime(str_replace("-","/",$pricesprem->date_from));
$toand = strtotime(str_replace("-","/",$pricesprem->date_to));
while($toand>$fro){
$fromarr[$xcount][0] = date("m d y",$fro);
$fromarr[$xcount][1] = $pricesprem->price_difference;
$fromarr[$xcount][2] = $dset;
$xcount++;
$fro+=86400;
}
$dset++;
}
}
$yrmnth = date("Y-m",$tstamp);
if(!$sprices[0]->temp_id)$sprices = $dbh->getdata_table("select * from season_dates sd left join season_prices sp on sd.pid = sp.pid where (instr(from_date,'$yrmnth')||instr(to_date,'$yrmnth')) and sd.pid = '$pid'");
if($sprices){
foreach($sprices as $pricess){
$dstamp=$tstamp;$tends=$dayends;
while($dstamp<$tends){
$detpricing=strtotime(str_replace("-","/",$pricess->from_date));$detto=strtotime(str_replace("-","/",$pricess->to_date));
while($detpricing<=$detto){
if(date("m d y",$detpricing)==date("m d y",$dstamp)){
// echo date("m d y",$detpricing)." ";
$season = strtolower($pricess->season);
$daysprice = number_format(($pricess->$season/7),2);
//check for premium pricing
$trydate=date("m d y",$detpricing);
if($fromarr){
foreach($fromarr as $key=>$val){ //calculate more than one premium additional price if necessary
// if($val[0]==$trydate)echo "$trydate - ".$val[1]." - ".$val[2] ." - ". $fromarr[$atkey][2]." ";
if($val[0]==$trydate)if($val[2]!==$fromarr[$atkey][2]){$atkey=$key;$premium_additional+=$val[1];}
}
}
//show price per day (*debugging purposes)
$showthaprice .="Price for date $season: " . date("M d Y",$dstamp)." - $$daysprice ";
$conglomerate+=$daysprice;
}
//account for daylight savings time
if(date("m d y",strtotime('last sunday', strtotime('november 1st')))==date("m d y",$detpricing)){$detpricing+=90000;}
elseif(date("m d y",strtotime('2 sunday', strtotime('march 1st')))==date("m d y",$detpricing)){$detpricing+=82800;}
else $detpricing+=86400;
}
if(date("m d y",strtotime('last sunday', strtotime('november 1st')))==date("m d y",$dstamp)){$dstamp+=90000;}
elseif(date("m d y",strtotime('2 sunday', strtotime('march 1st')))==date("m d y",$dstamp)){$dstamp+=82800;}
else $dstamp+=86400;
}
}
$showthaprice.= "Premium additional price: $". $premium_additional." ";
$_SESSION['show_prem'] = $premium_additional;
$conglomerate+=$premium_additional;
return $conglomerate;
}
}*/
//echo "alternative date 1:$alt1 price: $alt1price alternative date2:$alt2 price: $alt2price ";
?>
function process_alternatives($gen){
foreach($gen as $gen =>$gen_alt){
$alt_start = $gen_alt['start_date'];$alt_end=$gen_alt['end_date'];
$tmp_portion[] = "$alt_start-$alt_end";
}
$alt_tmp = array_unique($tmp_portion);
foreach($alt_tmp as $skey=>$falter){
if(substr($falter,0,strpos($falter,"-"))==substr($falter,strpos($falter,"-")+1))continue;
$new_alter[$skey]['start_date'] = substr($falter,0,strpos($falter,"-"));
$new_alter[$skey]['end_date'] = substr($falter,strpos($falter,"-")+1);
}
return $new_alter;
}
function meets_minimum($start_date,$end_date,$pid,$allowable_min=NULL){
global $dbh;
$amt_days = ceil((strtotime($end_date)-strtotime($start_date))/strtotime("+1 day",0));
if($allowable_min){$min=$allowable_min;}
else $min = get_minimum($start_date,$pid);
// alert("amount: $amt_days - minimum:$min");
if($amt_days<$min)return 0;
else return 1;
}
function gap_fit($requested_start_date,$requested_end_date,$pid){ //function to factor in the nightly_minimum to a stay
global $dbh;
// $date1 = strtotime($requested_start_date);$date2 = strtotime($requested_end_date);
// $min_nights = ($date2-$date1)/strtotime("+1 day",0);$min_nights = 5;
// $alts = generate_alternative($date1,$date2,$pid,$min_nights);
return $alt;
}
function get_minimum($requested_date,$pid){
global $dbh;
$szn = strtolower(whatSeason($requested_date,$pid));
$sznvar = $szn."_min";
$min_find = $dbh->getdata_table("select * from season_dates sd left join season_prices sp on sd.pid = sp.pid where sp.pid = '$pid'");
$night_min=$min_find[0]->$sznvar;
return $night_min;
}
function trip_connected($date1,$date2,$pid){
global $dbh;
$date1 = strtotime("-2 days",strtotime($date1));$date2 = strtotime("+2 days",strtotime($date2));
//gap information is in the following two queries
$query = "select * from booking_info where pid = '$pid' and ((unix_timestamp(start_date) between '$date1' and '$date2')|| '$date2' between unix_timestamp(start_date) and unix_timestamp(end_date))";
$start_trip = $dbh->getdata_table($query);
$query = "select * from booking_info where pid = '$pid' and ((unix_timestamp(end_date) between '$date1' and '$date2')|| '$date2' between unix_timestamp(start_date) and unix_timestamp(end_date))";
$end_trip = $dbh->getdata_table($query);
if($start_trip||$end_trip)return 1;
else return 0;
}
function generate_alternative($date1,$date2,$pid,$min_nights){
global $dbh;
$min_nights = (int)$min_nights;
$tszn = strtolower(whatSeason(strtotime($date1),$pid));$tagszn = "tag_".$tszn;
$pinformation = $dbh->getdata_table("select * from season_prices where pid = '$pid'");
if($pinformation)$allowable_minimum = $pinformation[0]->$tagszn;
else $allowable_minimum = 2;
if($min_nights<$allowable_minimum)return 0;
$date1 = strtotime($date1);$date2 = strtotime($date2);
//gap information is in the following two queries
$query = "select * from booking_info where pid = '$pid' and ((unix_timestamp(start_date) between '$date1' and '$date2')|| '$date2' between unix_timestamp(start_date) and unix_timestamp(end_date))";
$start_trip = $dbh->getdata_table($query);
$query = "select * from booking_info where pid = '$pid' and ((unix_timestamp(end_date) between '$date1' and '$date2')|| '$date2' between unix_timestamp(start_date) and unix_timestamp(end_date))";
$end_trip = $dbh->getdata_table($query);
//create suitable
if($start_trip||$end_trip){
if($start_trip&&$end_trip)$date_out = $end_trip[0]->end_date;
elseif($start_trip)$date_out=$start_trip[0]->end_date;
else $date_out = $end_trip[0]->end_date;
$date_out_stamp = strtotime($date_out);
$alt_try_start = $date_out_stamp;
$alt_try_end = strtotime("+$min_nights days",$alt_try_start);
while(prebooked($alt_try_start,$alt_try_end,$pid)){
$reservation_end=prebooked($alt_try_start,$alt_try_end,$pid);
// echo "start:".date("m d Y",$alt_try_start)." - end:".date("m d Y",$alt_try_end)." ";
$alt_try_start = strtotime($reservation_end);
$alt_try_end = strtotime("+$min_nights days",$alt_try_start);
}
$alternate_one['start_date']=date("m/d/Y",$alt_try_start);
$alternate_one['end_date']=date("m/d/Y",$alt_try_end);
if(strtotime($alternate_one['start_date'])";
return $alternate_one;
}
function gap_finder($date1,$date2,$pid){ //function gap_finder($date1,$date2,$month,$year,$pid){
global $dbh;
//finds gaps and reports their start day and length of available time
$month = date("m-Y",strtotime("-1 months",strtotime($date1)));$d2month = date("m-Y",strtotime("+1 months",strtotime($date2)));
$date1 = strtotime("1-$month");$date2 = strtotime("1-$d2month");
$query = "select *,unix_timestamp(end_date) as sort_time from booking_info where pid = '$pid' and ((unix_timestamp(end_date) between '$date1' and '$date2')|| '$date2' between unix_timestamp(start_date) and unix_timestamp(end_date)||(unix_timestamp(start_date) between '$date1' and '$date2')|| '$date2' between unix_timestamp(start_date) and unix_timestamp(end_date)) order by sort_time asc";
// echo $query;
$end_trip = $dbh->getdata_table($query);
if($end_trip){
$x=2;
foreach($end_trip as $key=>$endval){
$gaps[$key]['start']=$endval->end_date;
if($x==2){$x--;continue;}
$gaps[$key-1]['end']=$endval->start_date;
}
//clean && remove duplicate start && end dates
foreach($gaps as $gkey=>$gval){
if($gval[start]==$gval[end])$gaps[$gkey]=NULL;
if($gval[start]&&!$gval[end])$gaps[$gkey][end]=date("Y-m-d",strtotime("+1 month",strtotime($gval[start])));
}
//subtract a day from the end date
// $gaps[$key-1]['end']=date("Y-m-d",strtotime("-1 day",strtotime($gaps[$key-1]['end'])));
}
return $gaps;
}
function display_out($datein,$dateout,$price,$pid){
global $dbh;
$prop_info = $dbh->getdata_table("select * from property_data where pid = '$pid'");
$prop_name = $prop_info[0]->property_title;
$admin_fee = $prop_info[0]->adminfee;
$cleaning_fee = $prop_info[0]->cleaning_fee;
$price_display = $price + $admin_fee;
$price_display = $price_display + $cleaning_fee;
//$price+=$admin_fee;
//$price+=$cleaning_fee;
$confdate_in = (date("m/d/Y",strtotime($datein)));
$confdate_out = (date("m/d/Y",strtotime($dateout)));
$premium_price = get_premium(strtotime($datein),strtotime($dateout),$pid,$prem_title);
$specials_price = get_special("5",strtotime($datein),strtotime($dateout),$pid);
$total_days = floor((strtotime($dateout)-strtotime($datein))/strtotime("+1 day",0));
$price_box= "
Option Available ($total_days Night Reservation)
Home
Check-in: $datein - 04:00 PM
Check-out: $dateout - 11:00 AM
";
echo "";
if($price)echo $price_box;
else echo "We do not currently allow bookings this far ahead in the future. Please contact our main office for more assistance. Thank you";
}
?> session_start();
define(SELF,"administer.php");
class affiliate{
var $dbh,$lgh;
var $me;
function show_affiliates(){
$mylevel = $this->my_level();
if($mylevel==1){
//$affs = $this->dbh->getdata_table($rq="select * from affiliates left join affiliate_types on affiliates.aff_type_id = affiliate_types.aff_type_id left join affiliate_group on affiliates.aff_group_id = affiliate_group.aff_group_id where affiliates.aff_type_id = '2' && affiliates.aff_id != '$this->me' order by affiliates.aff_id");
$affs = $this->dbh->getdata_table($rq="select * from affiliates left join affiliate_types on affiliates.aff_type_id = affiliate_types.aff_type_id left join affiliate_group on affiliates.aff_group_id = affiliate_group.aff_group_id order by affiliates.aff_id");
//var_dump($affs);exit;
foreach($affs as $afk=>$affiliated){
$eu=$affiliated->aff_id;
echo "
";
$referring_afil = $this->dbh->getdata_table("select * from affiliates a left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types aft on a.aff_type_id = aft.aff_type_id where a.aff_type_id = '3' and a.my_creator = '$affiliated->aff_id'");
if($referring_afil){
echo "
aff_id\" style=\"display:none;\" class=\"tabmein\">";
foreach($referring_afil as $rafindex=>$raffiliated){
$eu=$raffiliated->aff_id;
echo "
";
$sales_agent = $this->dbh->getdata_table("select * from affiliates a left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types aft on a.aff_type_id = aft.aff_type_id where a.aff_type_id = '4' and a.my_creator = '$raffiliated->aff_id'");
if($sales_agent){
echo "
aff_id\" style=\"display:none;\" class=\"tabmein\">";
foreach($sales_agent as $salindex=>$saleaffiliate){
$eu=$saleaffiliate->aff_id;
echo "
";
$referring_afil = $this->dbh->getdata_table("select * from affiliates a left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types aft on a.aff_type_id = aft.aff_type_id where a.aff_type_id = '4' and a.my_creator = '$affiliated->aff_id'");
if($referring_afil){
echo "
aff_id\" class=\"tabmein\" style=\"display:none;\">";
foreach($referring_afil as $rafindex=>$raffiliated){
$eu=$raffiliated->aff_id;
echo "
";
}
}
}
elseif($mylevel==3){
$referring_afil = $this->dbh->getdata_table($mq="select * from affiliates a left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types aft on a.aff_type_id = aft.aff_type_id where a.aff_type_id = '4' and a.my_creator = '$this->me'");
if($referring_afil){
echo "
";
foreach($referring_afil as $rafindex=>$raffiliated){
$eu = $raffiliated->aff_id;
echo "
";
}
}
}
/*function show_affiliates(){
$my_group = $this->my_group();
switch($mylevel=$this->my_level()){
case '1':
break;
case '2':
$addon = "a.aff_type_id >= '$mylevel' and a.aff_group_id = '$my_group'";
break;
case '3':
$addon = "(a.my_creator = '$this->me' || a.aff_id = '$this->me') and a.aff_group_id = '$my_group'";
break;
case '4':
$addon = "a.aff_id = '$this->me'";
break;
}
//$affils = $this->dbh->getdata_table($sq="select * from affiliates a left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types aft on a.aff_type_id = aft.aff_type_id".(($addon)?(" where $addon"):(""))." order by a.aff_group_id,a.aff_type_id");
$affils = $this->dbh->getdata_table($sq="select * from affiliates a left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types aft on a.aff_type_id = aft.aff_type_id where a.aff_type_id = '2' order by a.aff_group_id,a.aff_type_id");
//echo $sq;
if($affils){
echo "
";
echo "
Viewing Users: ".$affils[0]->aff_group_name ."
";
//echo "
Group
User
Email
Affiliate Type
Active
Total Sales
User Actions
Edit
Remove
";
foreach($affils as $afindex=>$affiliated){
echo "
";
$referring_afil = $this->dbh->getdata_table("select * from affiliates a left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types aft on a.aff_type_id = aft.aff_type_id where a.aff_type_id = '3' and a.my_creator = '$affiliated->aff_id'");
if($referring_afil){
echo "
aff_id\" style=\"display:none;\">";
foreach($referring_afil as $rafindex=>$raffiliated){
echo "
";
$sales_agent = $this->dbh->getdata_table("select * from affiliates a left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types aft on a.aff_type_id = aft.aff_type_id where a.aff_type_id = '4' and a.my_creator = '$raffiliated->aff_id'");
if($sales_agent){
echo "
aff_id\" style=\"display:none;\">";
foreach($sales_agent as $salindex=>$saleaffiliate){
echo "
";
}
function my_group(){
$umytype = $this->dbh->getdata_table("select aff_group_id from affiliates where aff_id = '$this->me'");
return $umytype[0]->aff_group_id;
}
function my_group_name(){
$umytype = $this->dbh->getdata_table($rq="select aff_group_name from affiliates left join affiliate_group on affiliates.aff_group_id = affiliate_group.aff_group_id where affiliates.aff_id = '$this->me'");
return $umytype[0]->aff_group_name;
}
function log_activity($the_action){
return $this->dbh->insert_update("insert into affiliate_log set aff_id = '$this->me',aff_action='$the_action',dt=now()");
}
function my_company(){
$mnm = $this->dbh->getdata_table("select company_name from affiliates where aff_id = '$this->me'");
if($mnm)return ucwords($mnm[0]->company_name);
else echo "Sorry, Invalid User Error";
return 0;
}
function my_name(){
$mnm = $this->dbh->getdata_table("select * from affiliates where aff_id = '$this->me'");
if($mnm)return ucwords($mnm[0]->login_username);
else echo "Sorry, Invalid User Error";
return 0;
}
function update_affiliate_numbers($uid){
$mc = $this->dbh->getdata_table("select * from affiliates where aff_id = '$uid'");
$mc = $mc[0]->my_creator;
$aff_group_num = $this->dbh->getdata_table("select * from affiliates where aff_id = '$mc' and aff_type_id = '3'");
if($aff_group_num){
$agn = $aff_group_num[0];
$this->dbh->insert_update("update affiliates set discount_type='$agn->discount_type',discount_amount='$agn->discount_amount',deposit_type='$agn->deposit_type',deposit_amount='$agn->deposit_amount' where aff_id = '$uid'");
}
}
function trickle_down_affiliate_numbers(){
$aff_users = $this->dbh->getdata_table("select * from affiliates where aff_group_id = '".$this->my_group()."' and aff_type_id = '4'");
foreach($aff_users as $ayu){
$this->update_affiliate_numbers($ayu->aff_id);
}
}
function add_pay_info($pyid){
$this->dbh->insert_update("insert into aff2com set aff_id = '$this->me', PID='$pyid'");
return 0;
}
function my_discount($who=NULL){
if(!$who)$who=$this->me;
$aff_group_discount = $this->dbh->getdata_table("select * from affiliates a where a.aff_id = '$who'");
return $aff_group_discount[0]->discount_amount;
}
function my_discount_type($who=NULL){
if(!$who)$who=$this->me;
$aff_group_discount = $this->dbh->getdata_table("select * from affiliates a where a.aff_id = '$who'");
return $aff_group_discount[0]->discount_type;
}
function my_deposit($who=NULL){
if(!$who)$who=$this->me;
$aff_group_discount = $this->dbh->getdata_table("select * from affiliates a where a.aff_id = '$who'");
return $aff_group_discount[0]->deposit_amount;
}
function my_deposit_type($who=NULL){
if(!$who)$who=$this->me;
$aff_group_discount = $this->dbh->getdata_table("select * from affiliates a where a.aff_id = '$who'");;
return $aff_group_discount[0]->deposit_type;
}
function my_deposit_amount($amt){
if($this->my_deposit_type()=="percentage")return round($amt * ($this->my_deposit() / 100),2);
if($this->my_deposit_type()=="flat")return round($this->my_deposit(),2);
}
function activity_view(){
switch($mylevel=$this->my_level()){
case '1':
$avq="select *,al.dt as dt from affiliate_log al left join affiliates a on al.aff_id = a.aff_id left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types at on a.aff_type_id = at.aff_type_id";
break;
case '2':
$avq="select *,al.dt as dt from affiliate_log al left join affiliates a on al.aff_id = a.aff_id left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types at on a.aff_type_id = at.aff_type_id where a.aff_group_id = '".$this->my_group()."' and a.aff_type_id <= '".$this->my_level()."'";
break;
case '3':
$avq="select *,al.dt as dt from affiliate_log al left join affiliates a on al.aff_id = a.aff_id left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types at on a.aff_type_id = at.aff_type_id where a.aff_group_id = '".$this->my_group()."' and a.aff_type_id < '".$this->my_level()."' and a.my_creator = '".$this->me."'";
break;
case '4':
$avq="select *,al.dt as dt from affiliate_log al left join affiliates a on al.aff_id = a.aff_id left join affiliate_group ag on a.aff_group_id = ag.aff_group_id left join affiliate_types at on a.aff_type_id = at.aff_type_id where a.aff_id = '".$this->me."'";
break;
}
$aclog = $this->dbh->getdata_table($avq);
//echo $avq;
if($aclog){
echo "