forked from wp-plugins/wp-easy-booking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schd_sc.php
137 lines (125 loc) · 3.72 KB
/
schd_sc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
class schd_calendar {
function __construct($loc_id = '', $no_of_month = ''){
if(!$loc_id)
return;
if($no_of_month == '')
$no_of_month = 1;
global $wpdb;
?>
<div id="sc_cal"></div>
<div id="sd_list" style="margin-top:10px;"></div>
<?php
$book_till = get_option('bool_open_till');
if($book_till == ''){
$book_till = 30;
} else {
$book_till = $book_till * 30;
}
$schds = $wpdb->get_results( "SELECT `schd_day` FROM ".$wpdb->prefix."booking_location_schedule WHERE loc_id='".$loc_id."' GROUP BY `schd_day` ORDER BY schd_id" );
if(is_array($schds)){
foreach($schds as $key => $value){
$next = date("Y-m-d",strtotime( "next ".$value->schd_day ));
$a_days[] = str_pad($next,12,'"',STR_PAD_BOTH);
$loop = 0;
while( $loop <= $book_till ){
$loop = $loop+7;
$next_str = strtotime($next . " +7 day");
$next = date("Y-m-d",$next_str);
$a_days[] = str_pad($next,12,'"',STR_PAD_BOTH);
}
}
}
if(is_array($a_days))
$a_days = implode(',',$a_days);
?>
<script>
var disabledDays = [<?php echo $a_days;?>];
jQuery(function(){
jQuery( "#sc_cal" ).datepicker({
dateFormat: "yy-mm-dd",
numberOfMonths: <?php echo $no_of_month;?>,
onSelect: function(date) {
jQuery.ajax({
type: "POST",
beforeSend: function(){
jQuery('#sd_list').html('<center>loading..</center>');
},
data: { option: "getSchdInfo", date: date, loc_id: <?php echo $loc_id;?> }
})
.done(function( data ) {
jQuery('#sd_list').html(data);
});
},
beforeShowDay: function(date) {
var y = date.getFullYear().toString();
var m = (date.getMonth() + 1).toString();
var d = date.getDate().toString();
if(m.length == 1){ m = '0' + m; }
if(d.length == 1){ d = '0' + d; }
var currDate = y+'-'+m+'-'+d;
if(jQuery.inArray(currDate,disabledDays) != -1) {
return [true, "ui-highlight"];
} else {
return [false, ""];
}
}
});
});
</script>
<?php
}
}
function schd_booking_calendar_shortcode( $atts ) {
global $post;
extract( shortcode_atts( array(
'no_of_month' => ''
), $atts ) );
ob_start();
new schd_calendar($post->ID, $no_of_month);
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
add_shortcode( 'schd_calendar', 'schd_booking_calendar_shortcode' );
function schd_booking_form_shortcode( $atts ) {
global $post;
extract( shortcode_atts( array(
'title' => '',
), $atts ) );
ob_start();
if($title){
echo '<h2>'.$title.'</h2>';
}
$gc = new booking_general_class;
$gc->schd_booking_form();
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
add_shortcode( 'schd_booking_form', 'schd_booking_form_shortcode' );
function schd_booking_locations_shortcode( $atts ) {
global $post;
extract( shortcode_atts( array(
'show' => '10',
), $atts ) );
ob_start();
$args = array( 'posts_per_page' => $show, 'post_type' => 'booking_address' );
$locations = get_posts( $args );
if(is_array($locations)){
echo '<ul class="add-lists columns-2">';
foreach ( $locations as $loc ) { ?>
<li>
<h3><a href="<?php echo get_permalink($loc->ID);?>"><?php echo $loc->post_title;?></a></h3>
<p><?php echo nl2br(get_post_meta($loc->ID,'booking_address',true));?></p>
<p><a href="<?php echo get_permalink($loc->ID);?>"><?php _e('Book Now','wpb');?></a></p>
</li>
<?php }
echo '</ul>';
}
wp_reset_postdata();
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
add_shortcode( 'schd_booking_locations', 'schd_booking_locations_shortcode' );