prefix . "cs_booking"; if($wpdb->get_var("show tables like '$table_name'") != $table_name) { $sql = "CREATE TABLE ".$table_name." ( `id` int(11) NOT NULL auto_increment, `remote_id` int(11) default '0', `property_id` int(11) default '0', `startdate` varchar(10) default '0000-00-00', `enddate` varchar(10) default '0000-00-00', `starttime` varchar(5) default '00:00', `endtime` varchar(5) default '00:00', `title` varchar(250) default NULL, `notes` text, `status` int(11) default '0', `rentername` varchar(50) default NULL, `renteremail` varchar(45) default NULL, `rentertel` varchar(30) default NULL, `renternotes` text, `depositamount` varchar(10) default '0', `fullamount` varchar(10) default '0', PRIMARY KEY (`id`), KEY `startdate` (`startdate`), KEY `enddate` (`enddate`), KEY `property_id` (`property_id`) );"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); } // properties? amr } /* * The uninstallation function */ function uninstall() { } function check_ajax() { if(!empty($_REQUEST['call']) and ($_REQUEST['call'] == 'ajax') ){ if(stristr($_GET["page"],'clearskys-bookings') && /* amr */ function_exists('current_user_can') && current_user_can('moderate_comments')) { $this->show_bookings_panel(); exit(); } else { switch($_REQUEST["action"]) { case "_csformsubmit": $html = $this->createform("ajax",$_REQUEST['pid']); $startat = strpos($html,""); $endat = strpos($html,""); if($startat && $endat) { $html = substr($html,$startat, ($endat + strlen(""))-$startat); } else { $html = ""; } echo $html; exit(); break; default: return; } } } else { return; } } function cs_bookings_menu() { /* amr*/ echo "

Bookings

"; } // Setup the menu page function add_admin_pages() { // Create the submenus $hookname = add_object_page('Bookings','Bookings','edit_published_posts',__FILE__,array(&$this,'show_bookings_panel')); //'tools.php?page=amr-clearskys-bookings/clearskys-bookings.php',array(&$this,'show_bookings_panel')); if(function_exists('add_submenu_page')) { // Add a submenu to the custom top-level menu: // add_submenu_page(__FILE__, "List Bookings","List Bookings", 6, 'list_bookings', array(&$this,'show_bookings_panel') ); // add_submenu_page(__FILE__, "List Bookings","List Bookings", 6, // 'tools.php?page=amr-clearskys-bookings/clearskys-bookings.php', array(&$this,'show_bookings_panel')); // add_submenu_page(__FILE__, "Add Booking", "Add Booking", 6, __FILE__, array(&$this,'handle_booking_form')); add_submenu_page(__FILE__, "Add Booking", "Add Booking", 'edit_published_posts', 'add_bookings', array(&$this,'handle_booking_form')); } /* amr add_menu_page('Manage Bookings', 'Bookings', 'Author', file, [function], [icon_url]); */ if (current_user_can('edit_published_posts') ) { if (current_user_can('manage_options') ) { // add_options_page(__('Booking options'), __('Bookings Config'), 8, __FILE__, array(&$this,'show_options_panel')); add_submenu_page (__FILE__,__('Booking options'), __('Settings'), 'manage_options', 'bookings_config', array(&$this,'show_options_panel')); } //amr add_management_page("Manage Bookings", "Bookings", 6, __FILE__, array(&$this,'show_bookings_panel')); //amr add_submenu_page("post-new.php", "Add Booking", "Add Booking", 6, __FILE__, array(&$this,'handle_booking_form')); } } function add_admin_header() { //amr $site_uri = get_option('home'); /* needs fixing - amr */ //amr $plugin_uri = WP_PLUGIN_URL.'/amr-clearskys-bookings/includes/'; /* amr */ //amr $plugin_uri = 'http://localhost/wptest/wp-content/plugins/clearskys/includes/'; if(!empty ($_GET["page"]) and (stristr($_GET["page"], 'bookings' ))) { echo ''; echo ''; echo ''; echo ''; echo ''; //echo ''; echo ''; } /* amr */ return; } function isquerystring($url) { return stristr($url,'?'); } /** * Function: show_options_panel * Description: displays and handles the options configuration panel. * It is designed to work on it's own (when no other related plugins are activated) * or to be displayed in a single panel with all related plugins. * */ function show_options_panel() { // Get current database settings $cs = get_option("clearskys_config"); if(!isset($cs["clearskys_propertyno"])) { $cs["clearskys_propertyno"] = '1'; $cs["clearskys_calendar_monthblock"] = '{monthblock}
'; $cs["clearskys_calendar_monthtitle"] = "{title}"; $cs["clearskys_calendar_weekheader"] = "SMTWTFS"; $cs["clearskys_calendar_datesblock"] = "{month}"; $cs["clearskys_calendar_weekrow"] = "{week}"; $cs["clearskys_calendar_bookeddate"] = "{day}"; $cs["clearskys_calendar_bookedstartdate"] = "{day}"; $cs["clearskys_calendar_bookedenddate"] = "{day}"; $cs["clearskys_calendar_availabledate"] = "{day}"; $cs["clearskys_calendar_afterevery_number"] = "0"; $cs["clearskys_calendar_afterevery"] = ""; } if(!isset($cs["clearskys_publicpath"])) { $cs["clearskys_publicpath"] = "/availability/feed"; $cs["clearskys_privatepath"] = "/availability/mysecretcode"; } if(!isset($cs["clearskys_publiclocale"])) { $cs["clearskys_publiclocale"] = "en_UK.UTF-8"; $cs["clearskys_adminlocale"] = "en_UK.UTF-8"; } if(!isset($cs["clearskys_endweek"])) { $cs["clearskys_endweek"] = 6; } update_option("clearskys_config",$cs); if(isset($_POST['submitted'])) { // Update clicked so write to the database here foreach ($_POST as $key => $value) { if(substr($key,0,9) == 'clearskys') { $cs[$key] = stripslashes($value); } } update_option("clearskys_config",$cs); echo '

Settings saved.

'; } //for($n = 0;$n < count($cs);$n++) { // $cs[$n] = htmlspecialchars($cs[$n], ENT_QUOTES); //} ?>

Booking options

Use shortcode [property-availability-calendar months=6 property=1] to show a property availability calendar

'; echo '

Create page with shortcode

'; echo '

Styling of booked days:

Add css like td.booked {background-color: #EEE;} to highlight the booked cells

'; ?>

Calendar Options

Use the settings below to modify the layout and style of each month in your calendar.

Month Block:
Month Title:
Week Header:
Dates Block:
Week Row:
Booked Date:
First Booked Date:
Last Booked Date:
Available Date:
Use the code below:

Booking Options

If you are synchronising your bookings with a Clearskys.net server, then enter the assigned number of your property below. To find out the number of your property, login to your account at Clearskys.net and make a note of the number next to your property details on the left hand of your property list.

If you are not synchronising, then leave the Property ID set to 1.

Property ID number: " size="5" style="width: 5em; " />
*/?>

Calendar Feeds

Use the settings below to setup the URLs that you want use for your Calendar feeds. The public feed outputs basic information about the bookings and can be made available to your website users. You should make the private feed URL as un-guessable as possible as it outputs full information for the booking.

Please ensure there are no trailing slashes in your Feed URL

Public calendar path: " size="25" style="width: 20em; " /> isquerystring($cs["clearskys_publicpath"])) { echo "&property=" . $cs["clearskys_propertyno"] . "&feed=ical"; } else { echo "/" . $cs["clearskys_propertyno"] . "?feed=ical"; } echo "' title='Subscribe to iCal feed'>"; echo "iCal feed"; //amr . get_option('siteurl') . "/wp-content/plugins/clearskys/includes/images/date22x22.png' alt='iCal feed' width='22' height='22' style='vertical-align: bottom;' />"; echo " isquerystring($cs["clearskys_publicpath"])) { echo "&property=" . $cs["clearskys_propertyno"] . "&feed=RSS"; } else { echo "/" . $cs["clearskys_propertyno"] . "?feed=RSS"; } echo "' title='Subscribe to RSS feed'>"; echo "RSS feed"; //amr . get_option('siteurl') . "/wp-content/plugins/clearskys/includes/images/feed-icon16x16.png' alt='RSS feed' width='16' height='16' style='vertical-align: text-top;' />"; echo ""; } ?>
Private calendar path: " size="25" style="width: 20em; " /> isquerystring($cs["clearskys_privatepath"])) { echo "&property=" . $cs["clearskys_propertyno"] . "&feed=ical"; } else { echo "/" . $cs["clearskys_propertyno"] . "?feed=ical"; } echo "' title='Subscribe to iCal feed'>"; echo "iCal feed"; echo " isquerystring($cs["clearskys_privatepath"])) { echo "&property=" . $cs["clearskys_propertyno"] . "&feed=RSS"; } else { echo "/" . $cs["clearskys_propertyno"] . "?feed=RSS"; } echo "' title='Subscribe to RSS feed'>"; echo "RSS feed"; echo ""; } ?>

Language Options

Use the settings below to change the output language of the booking dates. Note: This currently only changes the language of the date information, the interface will still be in the current language.

Public Locale:
Admin Locale:

Start of Week

Set the starting day of the week below. Make sure that you also modify the Week Header setting above so that the labels match the days.

Start day:

show_panel(); break; case "ajaxsearch": $this->show_booking_results(); break; case "delete": // Shows the delete booking panel //$this->delete_booking($_POST['booking_ID']); break; case "ajaxdelete": $this->ajaxdelete_booking(); break; case "edit": $this->handle_booking_form(); break; case "update": $this->handle_booking_form(); break; default: // Shows the default booking list panel $this->show_panel(); break; } } else $this->show_panel(); } function show_booking_results() { // Get current database settings global $wpdb; global $amr_props; $cs = get_option("clearskys_config"); $tblbooking = $wpdb->prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); $site_uri = get_option('siteurl'); $plugin_uri = WPCPLUGINURL .'/includes/'; /* amr */ setlocale(LC_ALL,$cs["clearskys_adminlocale"]); if (!empty ($_REQUEST["property_id"])) $propertyid = $_REQUEST["property_id"]; else $propertyid = 1; $spropertyid = $propertyid; if (!isset($_REQUEST['action']) or ( $_REQUEST['action'] == "")) { $rows = $booking->getinitiallist(); $nomsg = "There are no bookings taking place this month... Search to see further."; $backlist = "&baction="; $stype = "initial"; } else { $nomsg = "You do not currently have any bookings with this criteria..."; $rows = array(); if ($propertyid) { $spropertyid = $booking->xss_clean($propertyid); if (isset($_REQUEST["sstatus"])) $sstatus = $booking->xss_clean($_REQUEST["sstatus"]); else $sstatus = ''; if (isset($_REQUEST["m"])) { $smonth = $booking->xss_clean($_REQUEST["m"]); } else $smonth = ''; if (isset($_REQUEST["s"])) $stext = $booking->xss_clean($_REQUEST["s"]); else $stext = ''; $backlist = "&propertyid=" . $spropertyid . "&sstatus=" . $sstatus . "&m=" . $smonth . "&s=" . $stext . "&baction=search"; $rows = $booking->getsearchlist($stext, $sstatus, $smonth, $spropertyid); } } if (empty($sstatus)) $sstatus= ''; if (empty($smonth)) $smonth= '';; if (empty($stext)) $stext = ''; if (empty($stype)) $stype = ''; ?>
Search results (NB re-search to see all)( add new booking) isquerystring($cs["clearskys_privatepath"])) { echo "&property=" . $spropertyid . "&feed=RSS"; } else { echo "/" . $spropertyid . "?feed=RSS"; } echo "&sstatus=" . $sstatus; echo "&m=" . $smonth; echo "&s=" . $stext; echo "&type=" . $stype; echo "' title='Subscribe to RSS feed'>"; echo 'RSS feed'; echo ""; echo "isquerystring($cs["clearskys_privatepath"])) { echo "&property=" . $spropertyid . "&feed=ical"; } else { echo "/" . $spropertyid . "?feed=ical"; } if($sstatus != "") echo "&sstatus=" . $sstatus; if($smonth != "") echo "&m=" . $smonth; if($stext != "") echo "&s=" . $stext; if($stype != "") echo "&type=" . $stype; echo "' title='Subscribe to iCal feed'>"; /* amr*/ echo "iCal feed"; echo ""; } ?>
prefix); } $rowclass = ' alternate'; foreach($rows as $row) { if ($rowclass === ' alternate') {$rowclass = '';} else {$rowclass = ' alternate';} echo "
"; echo "
"; $today = strtotime($row['startdate']); echo "" . ucfirst(strftime("%b",$today)) . ""; echo "" . date("d",$today) . ""; echo "" . date("Y",$today) . ""; echo "
"; echo "
"; $today = strtotime($row['enddate']); echo "" . ucfirst(strftime("%b",$today)) . ""; echo "" . date("d",$today) . ""; echo "" . date("Y",$today) . ""; echo "
"; echo "" . $row['title'] . ""; echo "Property: "; if(isset($csproperty)) { $ref = $csproperty->getrefforproperty($row['property_id']); echo ($ref) ? $ref[0]['reference'] : $row['property_id']; } else { echo $amr_props[$row['property_id']]; /* amr */ } echo " (" . $booking->status($row['status']); echo ")"; echo ""; echo ""; if($row['renteremail'] != "") echo ""; if($row['rentername'] != "") { echo $row['rentername']; } else { echo "No Renter name"; } if($row['renteremail'] != "") echo ""; echo " ("; echo ($row['rentertel'] != "") ? $row['rentertel'] : "No Telephone"; echo ")"; echo ""; // Edit and delete menu echo ""; /*amr */ echo ""; echo "edit"; echo " | "; echo ""; echo "delete"; echo ""; echo "
"; echo "
"; } } } /** * Function: show_panel * Description: Handles the main booking management functionality * including the listing and searches * */ function show_panel($msg = "") { // Get current database settings global $wpdb; global $amr_props; //$amr_props = amr_get_properties(); //amr wtf $pageheading = "Booking management"; $cs = get_option("clearskys_config"); $tblbooking = $wpdb->prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); $site_uri = get_option('siteurl'); /* amr */ $plugin_uri = WPCPLUGINURL .'/includes/'; setlocale(LC_ALL,$cs["clearskys_adminlocale"]); if (!empty ($_REQUEST['propertyid'])) $propertyid = $_REQUEST['propertyid']; else $propertyid = ''; if (empty($amr_props)) { create_properties_notice(); die(); } if($msg != "") { echo '

' . $msg . '

'; } ?>

show_booking_results(); ?>
Search bookings Processing...
prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); do_action("clearskys_booking_pre_delete",$_GET['bookingid']); echo $booking->delete($_GET['bookingid']); do_action("clearskys_booking_post_delete",$_GET['bookingid']); } function delete_booking($id) { // Get current database settings global $wpdb; $cs = get_option("clearskys_config"); $tblbooking = $wpdb->prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); $booking->setid($id); $siteurl = get_option('siteurl'); do_action("clearskys_booking_predelete", $id); $result = $booking->delete($id); do_action("clearskys_booking_postdelete", $id); if($result == "") { // Add Ok $this->show_panel("Booking deleted."); } else { echo $result; // Error show form again with msg $this->show_panel("Error: Could not delete booking."); } } function update_booking($id) { // Get current database settings global $wpdb; $cs = get_option("clearskys_config"); $tblbooking = $wpdb->prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); $booking->setid($id); $siteurl = get_option('siteurl'); // Get the entered details $data = array( 'id' => $id, 'property_id' => $_POST['property_id'], 'title' => $_POST['bookingtitle'], 'startdate' => $_POST['startmonth'] . '-' . $_POST['startday'], 'enddate' => $_POST['endmonth'] . '-' . $_POST['endday'], 'status' => $_POST['status'], 'notes' => $_POST['notes'], 'rentername' => $_POST['rentername'], 'renteremail' => $_POST['renteremail'], 'rentertel' => $_POST['rentertel'], 'renternotes' => $_POST['renternotes'], 'depositamount' => $_POST['depositcurrency'] . $_POST['depositamount'], 'fullamount' => $_POST['fullcurrency'] . $_POST['fullamount'], 'starttime' => $_POST['starthour'] . ':' . $_POST['startmin'], 'endtime' => $_POST['endhour'] . ':' . $_POST['endmin'] ); $result = $booking->update($data); do_action("clearskys_booking_update", $data); if($result == "") { // Add Ok //wp_redirect("edit.php?page=clearskys/clearskys-bookings.php"); //exit(); $this->show_panel("Booking details updated."); } else { // Error show form again with msg $data = $data + array("id" => $id); $this->show_edit_panel($id, $result, $data); } } function add_booking() { // Get current database settings global $wpdb; $cs = get_option("clearskys_config"); $tblbooking = $wpdb->prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); $siteurl = get_option('siteurl'); // Get the entered details $data = array( 'property_id' => $_POST['property_id'], 'title' => $_POST['bookingtitle'], 'startdate' => $_POST['startmonth'] . '-' . $_POST['startday'], 'enddate' => $_POST['endmonth'] . '-' . $_POST['endday'], 'status' => $_POST['status'], 'notes' => $_POST['notes'], 'rentername' => $_POST['rentername'], 'renteremail' => $_POST['renteremail'], 'rentertel' => $_POST['rentertel'], 'renternotes' => $_POST['renternotes'], 'depositamount' => $_POST['depositcurrency'] . $_POST['depositamount'], 'fullamount' => $_POST['fullcurrency'] . $_POST['fullamount'], 'starttime' => $_POST['starthour'] . ':' . $_POST['startmin'], 'endtime' => $_POST['endhour'] . ':' . $_POST['endmin'] ); $data = apply_filters('clearskys_booking_add_data', $data); $result = $booking->add($data); do_action("clearskys_booking_post_add", $data); if($result == "") { // Add Ok $this->show_add_panel("Booking added successfully. View bookings."); } else { // Error show form again with msg $this->show_add_panel($result, $data); //echo $result; } } function handle_booking_form() { if(isset($_POST["action"])) { // add or update so process form switch($_POST["action"]) { case "add": $this->add_booking(); break; case "update": $this->update_booking($_POST['id']); break; default: $this->show_panel(); break; } } else { if(isset($_GET["bookingid"])) { // edit so grab id and display form $this->show_edit_panel($_GET["bookingid"]); } else { // add so display blank form $this->show_add_panel(); } } } function show_add_panel($msg = "", $error = False) { // Get current database settings global $wpdb; $cs = get_option("clearskys_config"); $tblbooking = $wpdb->prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); $siteurl = get_option('siteurl'); if($msg != "") { echo '

' . $msg . '

'; } if($error) { $row = $error; } else { $row = array( 'id'=> 1, 'title'=>'', 'property_id'=>'1', 'rentername'=>'', 'renteremail'=>'', 'rentertel'=>'' , 'startdate' => date('Y-m-d'), 'enddate' => date('Y-m-d'), 'depositamount' => '0', 'fullamount' => '0', 'status' => '', 'renternotes' => '', 'notes' => '' ); } //print_r($row); ?>

Add New Booking

add_booking_form($row, $booking, $cs); ?>
prefix); } ?>
Booking Details
getpropertyreferencelist(true,3); if($prows) { ?>





 
 


 
 



 


 



Guest Details







prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); $id = $booking->xss_clean($id); $booking->setid($id); $siteurl = get_option('siteurl'); setlocale(LC_ALL,$cs["clearskys_adminlocale"]); if($msg != "") { echo '

' . $msg . '

'; } if($error) { $row = $error; } else { $row = $booking->getbooking(); } ?>

Edit Booking

edit_booking_form($row, $booking, $cs); ?>
Booking Details
getpropertyreferencelist(true,3); if($prows) { ?>





 
 


 
 



 


 



Guest Details







« Return to booking list

* * * * * * * * * * */ global $wpdb; if (empty($matches)) $matches = array('months'=>6, 'property'=>1); $tblbooking = $wpdb->prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); $cs = get_option('clearskys_config'); $propertyid = False; //amr $matches = array(); // Get an array of all the clearskys comment tags //amr preg_match_all("", $content, $matches); $content = ''; if(count($matches) > 1) { //amr for($n=0; $n$number) { switch($n) { case "months": // get months by removing the brackets //amr $number = preg_replace("[\(|\)]","",$matches[2][$n]); $thedate = strtotime(date("Y-m-01")); $month = ""; if(is_numeric($number)) { $monthcount = 0; for($z=1; $z<=$number; $z++) { // add a month to the output $month .= $this->buildmonth(date("Y", $thedate),date("m",$thedate),$propertyid); $thedate = strtotime("+1 month", $thedate); $monthcount++; if($monthcount == $cs["clearskys_calendar_afterevery_number"]) { $month .= $cs["clearskys_calendar_afterevery"]; $monthcount = 0; } } } $content .= $month; break; case "property": // set property id to build the calendar for // by removing the brackets //amr $number = preg_replace("[\(|\)]","",$matches[2][$n]); if(is_numeric($number)) { $propertyid = $number; } //amr $content = str_replace('<' . $matches[0][$n] . '>',"",$content); break; case "propertyfromattr": //amr $attr = preg_replace("[\(|\)]","",$matches[2][$n]); if($number != "") { $propertyid = $booking->xss_clean($number); if(!is_numeric($propertyid)) { $propertyid = False; } } //amr $content = str_replace('<' . $matches[0][$n] . '>',"",$content); break; case "propertyfromuri": //amr $number = preg_replace("[\(|\)]","",$matches[2][$n]); if(is_numeric($number)) { $uri = $_SERVER['REQUEST_URI']; $urisplit = explode("/",$uri); if(count($urisplit) > $number && is_numeric($urisplit[$number])) { $propertyid = $urisplit[$number]; } else { $propertyid = False; } } //amr $content = str_replace('<' . $matches[0][$n] . '>',"",$content); break; case "feedlink": //amr $format = preg_replace("[\(|\)]","",$matches[2][$n]); $format = $number; if(strtolower($format) == 'rss' || strtolower($format) == 'ical') { $link = "isquerystring($cs["clearskys_publicpath"])) { $link .= "&property=" . $useprop . "&feed=" . strtolower($format); } else { $link .= "/" . $useprop . "?feed=" . strtolower($format); } if(strtolower($format) == 'rss') { $link .= "' title='Subscribe to RSS feed'>"; $link .= "RSS feed"; } else { $link .= "' title='Subscribe to iCal feed'>"; $link .= "iCal feed"; } $link .= ""; $content = $link; } break; case "feedjscriptlink": //amr $format = preg_replace("[\(|\)]","",$matches[2][$n]); $format=$number; if(strtolower($format) == 'rss' || strtolower($format) == 'ical') { $link = "isquerystring($cs["clearskys_publicpath"])) { $useurl .= "&property=" . $useprop . "&feed=" . strtolower($format); } else { $useurl .= "/" . $useprop . "?feed=" . strtolower($format); } $link .= $useurl; if(strtolower($format) == 'rss') { $link .= "' title='Subscribe to RSS feed'"; $link .= " onclick='prompt(\"To subscribe to this feed, cut and paste the URL below into your Feed Reader when asked for subscribe details\",\"$useurl\"); return false;'"; $link .= ">"; /* amr*/ $link .= "RSS feed"; } else { $link .= "' title='Subscribe to iCal feed'"; $link .= " onclick='prompt(\"To subscribe to this feed, cut and paste the URL below into your Calendar application when asked for subscribe details\",\"$useurl\"); return false;'"; $link .= ">"; $link .= "iCal feed"; } $link .= ""; //amr $content = str_replace('<' . $matches[0][$n] . '>',$link,$content); $content .= $link; } break; case "feedurl": // $format = preg_replace("[\(|\)]","",$matches[2][$n]); $format = $number; if(strtolower($format) == 'rss' || strtolower($format) == 'ical') { $useurl = get_option('siteurl') . $cs["clearskys_publicpath"]; if($propertyid) { $useprop = $propertyid; } else { $useprop = $cs["clearskys_propertyno"]; } // if($this->isquerystring($cs["clearskys_publicpath"])) { $useurl .= "&property=" . $useprop . "&feed=" . strtolower($format); // } else { // $useurl .= "/" . $useprop . "?feed=" . strtolower($format); // } $link = $useurl; //amr $content = str_replace('<' . $matches[0][$n] . '>',$link,$content); $content .= $link; } break; } } } return $content; } function process_feed() { if(!isset($_GET['feed'])) { // not a feed url so return return; } $path = $_SERVER['REQUEST_URI']; $feed = $_GET['feed']; $cs = get_option('clearskys_config'); $siteurl = get_option('siteurl'); $class = ""; if(isset($_GET['property'])) { // query string feed url $path = "?" . $_SERVER['QUERY_STRING']; if(stristr($path, $cs['clearskys_privatepath'])) { $class= "Private"; } elseif(stristr($path, $cs['clearskys_publicpath'])) { $class= "Public"; } $property = $_GET['property']; } elseif(isset($_GET['propertyid'])) { $path = "?" . $_SERVER['QUERY_STRING']; if(stristr($path, $cs['clearskys_privatepath'])) { $class= "Private"; } elseif(stristr($path, $cs['clearskys_publicpath'])) { $class= "Public"; } $property = $_GET['propertyid']; } else { // URI string feed url // first strip off the query string part of it $qstring = "?" . $_SERVER['QUERY_STRING']; $path = str_replace($qstring,"",$path); if(stristr($path, $cs['clearskys_privatepath'])) { $class= "Private"; } elseif(stristr($path, $cs['clearskys_publicpath'])) { $class= "Public"; } // get the last segment in the uri $urisplit = explode("/",$path); if(count($urisplit) > 0 && is_numeric($urisplit[count($urisplit)-1])) { $property = $urisplit[count($urisplit)-1]; } else { $property = False; } } if($class == "") { return; } elseif($class=="Public") { echo $this->createpublicfeed($feed,$class,$property); exit(); } elseif($class=="Private") { echo $this->createprivatefeed($feed,$class,$property); exit(); } } function createpublicfeed($type,$class,$property = 0) { global $wpdb; $cs = get_option("clearskys_config"); $tblbooking = $wpdb->prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); $booking->setid($property); $feed = ""; // check for property plugin if(class_exists('CSproperty')) { $csproperty = new CSproperty($wpdb,$wpdb->prefix); } switch(strtolower($type)) { case "ical": // send ical headers header("Content-Type: text/Calendar"); header("Content-Disposition: inline; filename=basic.ics"); ob_start(); echo "BEGIN:VCALENDAR\r\n"; echo "VERSION:2.0\r\nPRODID:-//Clearskys.net//Availability Calendar//EN\r\n"; echo "X-WR-CALNAME:Availability Calendar for property "; if(isset($csproperty)) { $ref = $csproperty->getrefforproperty($property); echo $ref[0]["reference"]; echo "\r\n"; } else { echo "$property\r\n"; } $row = $booking->getbookings($property); if($row) { for($n=0; $ngetrefforproperty($property); $title .= $ref[0]["reference"]; } else { $title .= "$property"; } header('Content-type: text/xml; charset='.get_option('blog_charset'), true); ob_start(); echo ''; ?> > <?php echo $title; ?> http://blog.clearskys.net/plugins/availability-plugin/ getbookings($property); //$row = false; if($row) { for($n=0; $n\r\n"; echo "Booking: " . ucwords(strftime("%a %e %B %Y",$sdate)) . " to " . ucwords(strftime("%a %e %B %Y",$edate)) . "\r\n"; echo ""; echo bloginfo_rss('url'); echo "\r\n\r\n"; echo "" . date('D, d M Y H:i:s +0000',$sdate) . ""; echo ""; echo $row[$n]['id'] . "-" . $row[$n]['property_id']; echo "\r\n"; echo "\r\n"; echo "\r\n"; } } ?> prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); $booking->setid($property); $feed = ""; if (!empty($_GET["sstatus"])) $sstatus = $booking->xss_clean($_GET["sstatus"]); if (!empty($_GET["m"])) $smonth = $booking->xss_clean($_GET["m"]); if (!empty($_GET["s"])) $stext = $booking->xss_clean($_GET["s"]); if (!empty($_GET["type"])) $stype = $booking->xss_clean($_GET["type"]); if($stype == "") { $row = $booking->getfeedlist($stext, $sstatus, $smonth, $property, True); } else { $row = $booking->getinitialfeedlist(True); } // check for property plugin if(class_exists('CSproperty')) { $csproperty = new CSproperty($wpdb,$wpdb->prefix); } switch(strtolower($type)) { case "ical": // send ical headers header("Content-Type: text/Calendar"); header("Content-Disposition: inline; filename=basic.ics"); ob_start(); echo "BEGIN:VCALENDAR\r\n"; echo "VERSION:2.0\r\nPRODID:-//Clearskys.net//Availability Calendar//EN\r\n"; echo "X-WR-CALNAME:Availability Calendar for property "; if(isset($csproperty) && $property != "") { $ref = $csproperty->getrefforproperty($property); echo $ref[0]["reference"]; echo "\r\n"; } else { echo "$property\r\n"; } if($row) { for($n=0; $ngetrefforproperty($row[$n]['property_id']); $desc .= "Property: " . $ref[0]["reference"]; $desc .= "\\n"; } else { $desc .= "Property: " . $row[$n]['property_id'] . "\\n"; } $desc .= "Arrival Time: " . $row[$n]['starttime'] . "\\n"; $desc .= "Departure Time: " . $row[$n]['endtime'] . "\\n"; $desc .= "Status: " . $booking->status($row[$n]['status']) . "\\n"; $desc .= "Deposit Amount: " . $row[$n]['depositamount'] . "\\n"; $desc .= "Full Amount: " . $row[$n]['fullamount'] . "\\n"; $desc .= "Notes: " . $row[$n]['notes'] . "\\n\\n"; $desc .= "Guest Name: " . $row[$n]['rentername'] . "\\n"; $desc .= "Guest Email: " . $row[$n]['renteremail'] . "\\n"; $desc .= "Guest Tel: " . $row[$n]['rentertel'] . "\\n"; $desc .= "Guest Notes: " . $row[$n]['renternotes']; $desc = str_replace("\r\n","\\n",$desc); echo $desc . "\r\n"; $sdate = strtotime($row[$n]['startdate']); $edate = strtotime($row[$n]['enddate']); $edate = strtotime("+1 day", $edate); echo "DTSTART;VALUE=DATE:" . date("Y",$sdate) . date("m",$sdate). date("d",$sdate) . "\r\n"; echo "DTEND;VALUE=DATE:" . date("Y",$edate) . date("m",$edate). date("d",$edate) . "\r\n"; echo "END:VEVENT\r\n"; } } echo "END:VCALENDAR\r\n"; $feed = ob_get_contents(); ob_end_clean(); break; case "rss": // send xml headers setlocale(LC_ALL,$cs["clearskys_publiclocale"]); $title = "Availability Calendar for property "; if(isset($csproperty) && $property != "") { $ref = $csproperty->getrefforproperty($property); $title .= $ref[0]["reference"]; } else { $title .= "$property"; } header('Content-type: text/xml; charset='.get_option('blog_charset'), true); ob_start(); echo ''; ?> > <?php echo $title; ?> http://blog.clearskys.net/plugins/availability-plugin/ getbookings($property); //$row = false; if($row) { for($n=0; $n\r\n"; echo "" . $row[$n]['title'] . ": " . ucwords(strftime("%a %e %B %Y",$sdate)) . " to " . ucwords(strftime("%a %e %B %Y",$edate)) . "\r\n"; echo ""; echo bloginfo_rss('url'); echo "\r\n\r\n"; echo "" . date('D, d M Y H:i:s +0000',$sdate) . ""; echo ""; echo $row[$n]['id'] . "-" . $row[$n]['property_id']; echo "\r\n"; echo "Title: " . $row[$n]['title'] . "
"; if(isset($csproperty) && $row[$n]['property_id'] != 0) { $ref = $csproperty->getrefforproperty($row[$n]['property_id']); $desc .= "Property: " . $ref[0]["reference"]; $desc .= "
"; } else { $desc .= "Property: " . $row[$n]['property_id'] . "
"; } $desc .= "Arrival Date: " . ucwords(strftime("%a %e %B %Y",$sdate)) . "
"; $desc .= "Departure Date: " . ucwords(strftime("%a %e %B %Y",$edate)) . "
"; $desc .= "Arrival Time: " . $row[$n]['starttime'] . "
"; $desc .= "Departure Time: " . $row[$n]['endtime'] . "
"; $desc .= "Status: " . $booking->status($row[$n]['status']) . "
"; $desc .= "Deposit Amount: " . $row[$n]['depositamount'] . "
"; $desc .= "Full Amount: " . $row[$n]['fullamount'] . "
"; $desc .= "Notes: " . $row[$n]['notes'] . "

"; $desc .= "Guest Name: " . $row[$n]['rentername'] . "
"; $desc .= "Guest Email: " . $row[$n]['renteremail'] . "
"; $desc .= "Guest Tel: " . $row[$n]['rentertel'] . "
"; $desc .= "Guest Notes: " . $row[$n]['renternotes']; $desc = str_replace("\r\n","
",$desc); echo $desc; echo "]]>
\r\n"; echo "\r\n"; } } ?>
prefix . "cs_booking"; $booking = new CSbooking($wpdb,$tblbooking); if(!$propertyno) { $propertyno = $cs["clearskys_propertyno"]; } $master = $booking->getmontharray($year,$mon,$propertyno,True); $startofmonth = strtotime("$year-$mon-01"); $daysinmonth = date("t", $startofmonth); $week = array(); $month = array(); // set up start of week day if($cs['clearskys_endweek'] == 0) { $startweek = 1; } else { $startweek = 0; } $arrayday = 0; // first week fill initial blanks if((date("w",$startofmonth) - $startweek) < 0) { $sweek = 6; } else { $sweek = (date("w",$startofmonth) - $startweek); } for($n = $arrayday; $n < $sweek; $n++) { $week[$n] = str_replace('{day}',' ',stripslashes($cs['clearskys_calendar_availabledate'])); } $arrayday = $n; $m = 0; // build the weeks for the days of the month for($n=1; $n<=$daysinmonth; $n++) { $today = strtotime($year . "-" . $mon. "-" . str_pad($n,2,"00",STR_PAD_LEFT)); $yesterday = strtotime("-1 day", $today); $tomorrow = strtotime("+1 day", $today); if(isset($master[date("Ymd",$today)])) { //$cs["clearskys_calendar_bookedstartdate"] = "{day}"; //$cs["clearskys_calendar_bookedenddate"] = "{day}"; if(!isset($master[date("Ymd",$yesterday)]) && isset($cs["clearskys_calendar_bookedstartdate"])) { $dayhtml = stripslashes($cs['clearskys_calendar_bookedstartdate']); } elseif(!isset($master[date("Ymd",$tomorrow)]) && isset($cs["clearskys_calendar_bookedenddate"])) { $dayhtml = stripslashes($cs['clearskys_calendar_bookedenddate']); } else { $dayhtml = stripslashes($cs['clearskys_calendar_bookeddate']); } if(isset($master[date("Ymd",$today)]['status'])) { $dayhtml = str_replace("{status}",$master[date("Ymd",$today)]['status'],$dayhtml); } else { $dayhtml = str_replace("{status}","booked",$dayhtml); } } else { $dayhtml = stripslashes($cs['clearskys_calendar_availabledate']); } switch($arrayday) { case 6: // end of week so build week for this month $week[$arrayday] = str_replace('{day}',$n,$dayhtml); $month = $month + array("$m" => $week); $m++; $arrayday = 0; break; default: // other days $week[$arrayday++] = str_replace('{day}',$n,$dayhtml); break; } } // last week fill in the end blanks of the last row if($arrayday <= 6 && $arrayday != 0) { for($n = $arrayday; $n <= 6; $n++) { $week[$n] = str_replace('{day}',' ',stripslashes($cs['clearskys_calendar_availabledate'])); } // Add last week to the month $month = $month + array("$m" => $week); } // Format each week $amonth = ""; for($n=0; $n date("Y")) $dateclasses .= " nextyear"; if($mon == date("m")) $dateclasses .= " thismonth"; $amonth = str_replace("{monthclass}",ltrim($dateclasses),$amonth); $amonth = str_replace("{property}",$propertyno,$amonth); // and return return $amonth; } } $CSbook =new CSbook(); ?>