slot_starting_time =get_option( 'eav_slot_start','09:00:00'); $this->slot_end_time =get_option( 'eav_slot_end' ,'21:00:00'); $this->slot_frequency=get_option( 'eav_slot_duration' , '60' ); } 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; // convert day /month / year to 1 to 01... // $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_days_array($year, $month); } function make_slot_scheduled_array(){ global $wpdb; global $bp; $dispalyed_user_id=get_current_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); 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_schedulded=$results_schedule_timeslots; } } function make_slot_booked_array(){ global $wpdb; global $bp; $dispalyed_user_id=get_current_user_id(); $current_date=$this->day . "-" . $this->month . "-" . $this->year ; $current_date_string='"'.$current_date.'"'; $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_booked_post)>0) { foreach($results_booked_post as $results_booked_posts) { $posted_array[ ]='"'.$results_booked_posts['ID'].'"'; } $iner='('.implode(",", $posted_array).')'; $query3='SELECT * FROM wp_postmeta where meta_key= "_slot_start" and post_id IN'.$iner; $results_booked_timeslots= $wpdb->get_results($query3,ARRAY_A); $this->timeslot_booked=$results_booked_timeslots; } } 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 create_time_range($start, $end, $interval = '30 mins', $format = '12') { $startTime = strtotime($start); $endTime = strtotime($end); $returnTimeFormat = ($format == '12')?'g:i:s A':'G:i:s'; $current = time(); $addTime = strtotime('+'.$interval, $current); $diff = $addTime - $current; $times = array(); while ($startTime < $endTime) { $times[] = date($returnTimeFormat, $startTime); $startTime += $diff; } $times[] = date($returnTimeFormat, $startTime); return $times; } 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 "
"; /* Make the table header with the appropriate day of the week using the $day_format variable as user defined above Definition: 1: Show First digit, eg: "M" 2: Show First 3 letters, eg: "Mon" 3: Full Day, eg: "Monday" */ foreach($this->day_order as $r) { switch($this->day_format) { case(1): echo ""; break; case(2): echo ""; break; case(3): echo ""; break; } // Close switch } // Close foreach echo ""; $this->make_cells(); } // Close function function make_cells($table = '') { echo ""; foreach($this->days as $i => $r) { // Loop through the date array $j = $i + 1; $tag = 0; // If the the current day is found in the day_closed array, bookings are not allowed on this day if($r['mark']=='closed') { echo "\r\n"; } // 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"; } // Close if if($r['mark']=='green') { echo "\r\n"; } // The modulus function below ($j % 7 == 0) adds a tag to every seventh cell + 1; if($j % 7 == 0 && $i >1) { echo "\r\n\r\n"; // Use modulus to give us a after every seven
« " . date("F, Y", $this->selected_date) . " »

" . substr($r, 0, 1) . "" . substr($r, 0, 3) . "" . $r . "

" . $r['daynumber'] . "

" . $r['daynumber'] . "

" . $r['daynumber'] . "

cells } } echo "
"; $this->make_settings(); $this->makeslots(); } // Close function function make_settings(){ $user_id=get_current_user_id(); $email=get_user_meta($user_id,'eav_user_email',true); $paypal_signature=get_user_meta($user_id,'eav_user_paypal_sign' ,true); $paypal_username=get_user_meta($user_id,'eav_user_paypal_username' ,true); $paypal_password=get_user_meta($user_id,'eav_user_paypal_paswd' ,true); echo"
Email: Paypal Username : Paypal Password : Paypal Signature : ". wp_nonce_field( 'saving_settings', 'saving_settings_nounce' ) ."
"; } function makeslots(){ echo "

Shedule the Slots

Schedule the slots for date " . $this->day . "-" . $this->month . "-" . $this->year . "

"; $current_date=$this->day . "-" . $this->month . "-" . $this->year ; $user_id = get_current_user_id(); $this->make_slot_scheduled_array(); $this->make_slot_booked_array(); $slots_schedulde=$this->timeslots_schedulded; $slots_booked=$this->timeslot_booked; $slots= $this->create_time_range($this->slot_starting_time, $this->slot_end_time,$this->slot_frequency.'mins','24'); foreach($slots as $slot) { $tag=0; $finish_time = strtotime($slot) + $this->slot_frequency * 60; echo ''; foreach($slots_schedulde as $slots_schedulded) { if($slot==$slots_schedulded['meta_value']){ $tag=1; echo''; echo''; echo''; echo''; } echo'
Start End Schedule Status
'.$slot.' '.date("H:i:s", $finish_time).'

'; echo'schedulded';} } foreach($slots_booked as $slots_bookeded) { if($slot==$slots_bookeded['meta_value']){ $tag=1; echo'

'; echo'booked'; } } if($tag==0) { echo'

'; echo'Not schedulded Yet'; } echo'

'; } } // Close Class ?>