cost_per_slot=get_option( 'eav_slot_price' ); $this->booking_frequency=get_option( 'eav_slot_duration' ); } function make_calendar($selected_date, $back, $forward, $day, $month, $year) { // convert day /month / year to 1 to 01... $day = sprintf("%02d", $day); $month = sprintf("%02d", $month); $year = sprintf("%02d", $year); // $day, $month and $year are the $_GET variables in the URL $this->day = $day; $this->month = $month; $this->year = $year; // $back and $forward are Unix Timestamps of the previous / next month, used to give the back arrow the correct month and year $this->selected_date = $selected_date; $this->back = $back; $this->back_month = date("m", $back); $this->back_year = date("Y", $back); // Minus one month back arrow $this->forward = $forward; $this->forward_month = date("m", $forward); $this->forward_year = date("Y", $forward); // Add one month forward arrow // Make the booking array $this->make_booking_array($year, $month); } function make_booking_array($year, $month, $j = 0) { // Get data from displayed user post......if current= displayed not shown..... global $wpdb; global $bp; $dispalyed_user_id=$bp->displayed_user->id; $current_date=$this->day . "-" . $this->month . "-" . $this->year ; $current_date_string='"'.$current_date.'"'; $query='SELECT * FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id where post_author='.$dispalyed_user_id.' AND post_type="eav_networks" AND post_status="schedule" AND wp_postmeta.meta_key="_date" AND meta_value='.$current_date_string; $results_shedule_post = $wpdb->get_results($query,ARRAY_A); $query2='SELECT * FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id where post_author='.$dispalyed_user_id.' AND post_type="eav_networks" AND post_status="booked" AND wp_postmeta.meta_key="_date" AND meta_value='.$current_date_string; $results_booked_post = $wpdb->get_results($query2,ARRAY_A); if(count($results_shedule_post)>0) { foreach($results_shedule_post as $results_shedule_posts) { $post_array[ ]='"'.$results_shedule_posts['ID'].'"'; } $in='('.implode(",", $post_array).')'; $query3='SELECT * FROM wp_postmeta where meta_key= "_slot_start" and post_id IN'.$in; $results_schedule_timeslots= $wpdb->get_results($query3,ARRAY_A); $this->timeslots=$results_schedule_timeslots; } $this->make_days_array($year, $month); } // Close function function make_days_array($year, $month) { // Calculate the number of days in the selected month $num_days_month = cal_days_in_month(CAL_GREGORIAN, $month, $year); // Make $this->days array containing the Day Number and Day Number in the selected month for ($i = 1; $i <= $num_days_month; $i++) { $i = sprintf("%02d", $i); // to make marks.... global $wpdb; global $bp; $dispalyed_user_id=$bp->displayed_user->id; $current_date=$i. "-" . $this->month . "-" . $this->year ; $current_date_string='"'.$current_date.'"'; $query='SELECT * FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id where post_author='.$dispalyed_user_id.' AND post_type="eav_networks" AND post_status="schedule" AND wp_postmeta.meta_key="_date" AND meta_value='.$current_date_string; $results_shedule_post = $wpdb->get_results($query,ARRAY_A); $query2='SELECT * FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id where post_author='.$dispalyed_user_id.' AND post_type="eav_networks" AND post_status="booked" AND wp_postmeta.meta_key="_date" AND meta_value='.$current_date_string; $results_booked_post = $wpdb->get_results($query2,ARRAY_A); if(count($results_shedule_post)>0) { $mark='green'; } elseif((count($results_shedule_post )==0) && ((count($results_booked_post)>0) )) { $mark='red'; } else { $mark="closed"; } // Work out the Day Name ( Monday, Tuesday... ) from the $month and $year variables....Timestamp to not change for region to region... $d = mktime(0, 0, 0, $month, $i, $year); // Create the array.....This array contains the clicked data day name as 1,2,3--- with dayname as mon, tue.. $this->days[] = array("daynumber" => $i, "dayname" => date("l", $d),"mark"=>$mark); } $this->make_blank_start($year, $month); $this->make_blank_end($year, $month); } // Close function function make_blank_start($year, $month) { /* Calendar months start on different days Therefore there are often blank 'unavailable' days at the beginning of the month which are showed as a grey block The code below creates the blank days at the beginning of the month */ // Get first record of the days array which will be the First Day in the month ( eg Wednesday ) and also for clicked.. $first_day = $this->days[0]['dayname']; $s = 0; // Loop through $day_order array ( Monday, Tuesday ... ) foreach($this->day_order as $i => $r) { // Compare the $first_day to the Day Order if($first_day == $r && $s == 0) { $s = 1; // Set flag to 1 stop further processing } elseif($s == 0) { $blank = array( "daynumber" => 'blank', "dayname" => 'blank', "mark"=>'unavailable' ); // Prepend elements to the beginning of the $day array...This makes days array as if moth starts from wed then it add mon , tue as daynumber and dayname as blank.... array_unshift($this->days, $blank); } } // Close foreach } // Close function function make_blank_end($year, $month) { /* Calendar months start on different days Therefore there are often blank 'unavailable' days at the end of the month which are showed as a grey block The code below creates the blank days at the end of the month */ // Add blank elements to end of array if required Same as above .Only for last blank. $pad_end = 7 - (count($this->days) % 7); if ($pad_end < 7) { $blank = array( "daynumber" => 'blank', "dayname" => 'blank', "mark"=>'unavailable' ); for ($i = 1; $i <= $pad_end; $i++) { array_push($this->days, $blank); } } // Close if $this->calendar_top(); } // Close function function calendar_top() { // This function creates the top of the table containg the date and the forward and back arrows echo "
| « | " . date("F, Y", $this->selected_date) . " | » | ||||
| " . substr($r, 0, 1) . " | "; break; case(2): echo "" . substr($r, 0, 3) . " | "; break; case(3): echo "" . $r . " | "; break; } // Close switch } // Close foreach echo "||||
|---|---|---|---|---|---|---|
| " . $r['daynumber'] . " | "; } // If the element is set as 'blank', insert blank day if($r['mark']=='unavailable') { echo "\r\n"; } // Now check the booking array $this->booking to see whether we have a booking on this day $current_day = $this->year . '-' . $this->month . '-' . sprintf("%02s", $r['daynumber']); if($r['mark']=='red') { echo "\r\n |
" . $r['daynumber'] . " | ";
} // Close if
if($r['mark']=='green') {
echo "\r\n
" . $r['daynumber'] . " | ";
}
// The modulus function below ($j % 7 == 0) adds a |||
| cells } } echo " | ||||||
The following slots are available on " . $this->day . "-" . $this->month . "-" . $this->year . "
| Start | End | Price | Book |
|---|---|---|---|
| " . $start['meta_value']. " | \r\n" . date("H:i:s", $finish_time) . " | \r\n" . $this->cost_currency_tag . number_format($this->cost_per_slot, 2) . " | \r\n