预订日历小工具,以防止最后一分钟预订

时间:2015-01-27 06:15:36

标签: javascript php jquery jquery-ui

我想修改我的预订日历小部件,以防止人们在最后一刻预订。我想以这样的方式预订,只允许提前至少3天预订。代码如下所示(我的猜测是它与datepicker有关,但我可能错了):

class Calendar_widget extends WP_Widget {

    function Calendar_widget(){
        parent::__construct( 'calendar_widget', 'Calendar Widget' );
    }

    function do_with_time_stamp_something(&$arrayOfTimeStamps, $timeStamp){
// var_dump($timeStamp);
    if(!empty($timeStamp)){
        $date_link = date( "F.j.Y", $timeStamp );
        array_push($arrayOfTimeStamps, array(
        get_site_url()."/event_category/event/?date=".$date_link,
        date( "m/d/Y", $timeStamp )
    ));
    }

}

    function widget($args, $instance) {
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);

$i=0;
global $wpdb;
$data   =   array();



$wpdb->query("
        SELECT $wpdb->postmeta.`meta_value`
        FROM $wpdb->postmeta

    INNER JOIN $wpdb->posts
    ON $wpdb->postmeta.post_id=$wpdb->posts.ID

    WHERE (`meta_key` = '".SHORTNAME."_event_date'
    OR `meta_key` = '".SHORTNAME."_multiple_weeks_array'
    OR `meta_key` = '".SHORTNAME."_multiple_weeks_array_1') and $wpdb->posts.post_status = 'publish' and $wpdb->posts.post_type = 'event'
");

foreach($wpdb->last_result as $v){

    $meta_value = maybe_unserialize($v->meta_value);

    if(is_array($meta_value)){
        foreach ($meta_value as $timeStamp) {
            // do_with_time_stamp_something($data, $timeStamp);
            if(!empty($timeStamp)){
        $date_link = date( "F.j.Y", $timeStamp );
        array_push($data, array(
        get_site_url()."/event_category/event/?date=".$date_link,
        date( "m/d/Y", $timeStamp )
    ));
    }
        }
    } else {
        // var_dump($meta_value);
        if(!empty($meta_value)){
            // var_dump($meta_value);
            $timeStamp = strtotime($meta_value);
            $date_link = date( "F.j.Y", $timeStamp );
            array_push($data, false);
        }
        // do_with_time_stamp_something($data, $meta_value);
        if(!empty($timeStamp)){

        $date_link = date( "F.j.Y", $timeStamp );
        array_push($data, array(
        get_site_url()."/event_category/event/?date=".$date_link,
        date( "m/d/Y", $timeStamp )
    ));
    }   
    }
}

?>
<?php 
if(isset($_GET['date'])){
    // var_dump($_GET['date']);die;
    $date = $_GET['date'];
    $a = strtotime( $date );
    $final = date( "m/d/Y", $a );
    // echo '---';
    // var_dump($final);die;
} else {
    $final = '';
}
?>
<div class="block_datepicker">
<div id="datepicker" class="calendar">
    <script>
        jQuery(document).ready(function($){
            var events = [
                <?php foreach ($data as $value){ ?>
                    { Title: '<?php echo"$value[0]"; ?>', Date: new Date('<?php echo"$value[1]"; ?>') },
                <?php } ?>
            ];

            $("#datepicker").datepicker({
                defaultDate: new Date ('<?php echo $final; ?>'),
                beforeShowDay: function(date) {
                    var result = [true, '', null];
                    var matching = $.grep(events, function(event) {
                        return event.Date.valueOf() === date.valueOf();
                    });
                    // console.log(matching);
                    if (matching.length) {
                        result = [true, 'highlight', null];
                    }
                    return result;
                },
                onSelect: function(dateText) {
                    var calendar = dateText;
                    $('.about_event[eventdata!="'+calendar+'"]').parents('.events').hide();
                    // $('.about_event[eventdata=="03/28/2014"]').css('display', 'none');
                    // $('.about_event').each(function(){
                    //  if($(this).attr('eventdata') != dateText){
                    //      $(this).parents('.events').hide();
                    //  }
                    //  else{
                    //      $(this).parents('.events').show();
                    //  }
                    // })
                    // console.log(cont);
                    var date,
                        selectedDate = new Date(dateText),
                        i = 0,
                        event = null;

                    while (i < events.length && !event) {
                        date = events[i].Date;

                        if (selectedDate.valueOf() === date.valueOf()) {
                            event = events[i];
                            //console.log(event);
                        }
                        i++;
                    }
                    if (event) {
                        //LIKE in OLD TIME
                        window.location.href = event.Title;
                    }
                }
            });
        }); 
    </script>
</div>
</div>
<?php
    }

    function update($new_instance, $old_instance) {
        $instance = $old_instance;
        $instance['title'] = strip_tags($new_instance['title']);
        // $instance['phone'] = strip_tags($new_instance['phone']);
        // $instance['email'] = strip_tags($new_instance['email']);
        return $instance;
    }

    function form($instance) {
        if(isset($instance['title'])){
            $title = esc_attr($instance['title']);
        }
        // if(isset($instance['phone'])){
     //     $phone = esc_attr($instance['phone']);
        // }
        // if(isset($instance['email'])){
     //     $email = esc_attr($instance['email']);
        // }
        ?>
            <!-- <div class="contact_us"> -->
                <!-- <p> -->
                    <!-- <label for="<?php //echo $this->get_field_id('title'); ?>"><?php //_e('Title:'); ?></label> -->
                    <!-- <input id="<?php //echo $this->get_field_id('title'); ?>" name="<?php //echo $this->get_field_name('title'); ?>" type="text" value="<?php //if(isset($title)) echo $title; ?>" /> -->
                <!-- </p> -->
                <!-- <p> -->
                    <!-- <label for="<?php //echo $this->get_field_id('phone'); ?>"><?php //_e('Phone:'); ?></label> -->
                    <!-- <input id="<?php //echo $this->get_field_id('phone'); ?>" name="<?php //echo $this->get_field_name('phone'); ?>" type="text" value="<?php //if(isset($phone)) echo $phone; ?>" /> -->
                <!-- </p> -->
                <!-- <p> -->
                    <!-- <label for="<?php //echo $this->get_field_id('email'); ?>"><?php //_e('Email:'); ?></label> -->
                    <!-- <input id="<?php //echo $this->get_field_id('email'); ?>" name="<?php //echo $this->get_field_name('email'); ?>" type="text" value="<?php //if(isset($email)) echo $email; ?>" /> -->
                <!-- </p> -->
            <!-- </div> -->
        <?php
    }

}

?>

嗨,我想它可能是php文件。代码如下:

<script type="text/javascript">
function show_or_hide(){
    cb = document.getElementById("banner-widget-use");
    if (cb.checked){
        document.getElementById('fake').disabled = true;
    }
    else{
        document.getElementById('fake').disabled = false;
    }
    cd = document.getElementById("second-day-use");
    if (cd.checked){
        document.getElementById('fake_day').disabled = true;
    }
    else{
        document.getElementById('fake_day').disabled = false;
    }

    cd1 = document.getElementById("second-day-use_1");
    if (cd1.checked){
        document.getElementById('fake_day_1').disabled = true;
    }
    else{
        document.getElementById('fake_day_1').disabled = false;
    }

}

ID,SHORTNAME。&#34; _event_place&#34;,true);     $ event_date = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_date&#34;,true);     if($ event_date!=&#34;&#34;){         $ date = $ event_date;     }     其他{         $ date =&#39;&#39 ;;     }     $ time = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_time&#34;,true);     $ array_start = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_date_array_start&#34;,true);     if($ array_start!=&#34;&#34;){         $ start_date = $ array_start;     }     其他{         $ start_date =&#39;&#39;;     }     $ array_end = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_date_array_end&#34;,true);     if($ array_end!=&#34;&#34;){         $ end_date = $ array_end;     }     其他{         $ end_date =&#39;&#39;;     }     $ date_day = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_multiple_week_day&#34;,true);     $ multiple_from = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_multitime_time_begin&#34;,true);     $ date_day_1 = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_multiple_week_day_1&#34;,true);     $ multiple_from_1 = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_multitime_time_begin_1&#34;,true);     $ use_multidate_event = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _use_multidate_event&#34;,true);     $ use_second_event_day = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _use_second_event_day&#34;,true);     $ time_price = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _time_price&#34;,true);     $ time_price_child = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _time_price_child&#34;,true);     $ time_price_other = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _time_price_other&#34;,true);     $ due_balance = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _due_balance&#34;,true);     $ max_count = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _max_count&#34;,true);     $ reserved = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _reserved&#34;,true);     $ date_day_next = array();     $ multiple_from_next = array();     $ date_day_1_next = array();     $ multiple_from_1_next = array();     $ use_multidate_event_next = array();     $ use_second_event_day_next = array();     $ time_price_next = array();     $ time_price_child_next = array();     $ time_price_other_next = array();     $ due_balance_next = array();     $ max_count_next = array();     $ reserved_next = array();     for($ i = 1; $ i ID,SHORTNAME。&#34; _event_multiple_week_day_next&#34;。$ i,true);         $ multiple_from_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_multitime_time_begin_next&#34;。$ i,true);         // $ multiple_till_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_multitime_time_end_next&#34;。$ i,true);         $ date_day_1_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_multiple_week_day_1_next&#34;。$ i,true);         $ multiple_from_1_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_multitime_time_begin_1_next&#34;。$ i,true);         // $ multiple_till_1_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _event_multitime_time_end_1_next&#34;。$ i,true);         $ use_multidate_event_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _use_multidate_event_next&#34;。$ i,true);         $ use_second_event_day_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _use_second_event_day_next&#34;。$ i,true);         $ time_price_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _time_price_next&#34;。$ i,true);         $ time_price_child_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _time_price_child_next&#34;。$ i,true);         $ time_price_other_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _time_price_other_next&#34;。$ i,true);         $ due_balance_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _due_balance_next&#34;。$ i,true);         $ max_count_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _max_count_next&#34;。$ i,true);         $ reserved_next [$ i] = get_post_meta($ post-&gt; ID,SHORTNAME。&#34; _reserved_next&#34;。$ i,true);     }     $ week_days =数组(&#39;星期天&#39;,&#39;星期一&#39;,&#39;星期二&#39;,&#39;星期三&#39;&#39;星期四&#39;, &#39;星期五&#39;,&#39;星期六&#39;);     ?&GT;                        jQuery的(函数($){             $(&#34;#event-date&#34;)。datepicker({dateFormat:&#39; MM dd,yy&#39;});             $(&#34;#event-date-array-start&#34;)。datepicker({dateFormat:&#39; MM dd,yy&#39;});             $(&#34;#event-date-array-end&#34;)。datepicker({dateFormat:&#39; MM dd,yy&#39;});             $(&#34;#event-date-array-start_1&#34;)。datepicker({dateFormat:&#39; MM dd,yy&#39;});             $(&#34;#event-date-array-end_1&#34;)。datepicker({dateFormat:&#39; MM dd,yy&#39;});             if($(&#39;#banner-widget-use&#39;)。(&#39;:checked&#39;)){                 $(&#34; .multidate&#34)。显示();                 $(&#39; .standart_event&#39;)。隐藏();             } else {                 $(&#34; .multidate&#34)。隐藏();                 $(&#39; .standart_event&#39;)。节目();             }             $(&#39;#banner-widget-use&#39;)。click(function(){                 $(&#34; .multidate&#34;)。slideToggle(this.checked);                 $(&#39; .standart_event&#39)。的slideToggle(this.checked);                 $(&#34; .add_time&#34;)。slideToggle(this.checked);                 $(&#34; .delete_time&#34;)。slideToggle(this.checked);             });             if($(&#39;#second-day-use&#39;)。(&#39;:checked&#39;)){                 $(&#34; .second_day&#34)。显示();                 $(&#39; .add_time&#39;)。节目();                 $(&#39; .delete_time&#39;)。节目();             } else {                 $(&#34; .second_day&#34)。隐藏();                 $(&#39; .add_time&#39;)。隐藏();                 $(&#39; .delete_time&#39;)。隐藏();             }             $(&#39;#second-day-use&#39;)。click(function(){             });         });           _event_place&#34; ID =&#34;事件地方&#34;值=&#34;&#34;风格=&#34;宽度:100%;&#34;&GT;               _event_date&#34; ID =&#34;事件日期&#34;值=&#34;&#34;风格=&#34;宽度:100%;&#34;&GT;          _event_time&#34; ID =&#34;事件时间&#34;值=&#34;&#34;风格=&#34;宽度:100%;&#34;&GT;           &#39 ;. __(&#34;每周重复一次?&#34;,SHORTNAME)。&#39;
&#39 ;;             回声&#39;&#39;         }         其他{             回声&#39; &#39 ;. __(&#34;每周重复一次?&#34;,SHORTNAME)。&#39;
&#39 ;;             回声&#39;&#39;         }     ?&GT;              
_event_date_array_start&#34; ID =&#34;事件日期阵列启动&#34;值=&#34;&#34;风格=&#34;宽度:100%;&#34; /&GT;         
_event_date_array_end&#34; ID =&#34;事件日期阵列端&#34;值=&#34;&#34;风格=&#34;宽度:100%;&#34; /&GT;                      _event_multiple_week_day&#34;名称=&#34; _event_multiple_week_day&#34;&GT;                  $ day_name){                     if($ day_id == $ date_day){?&gt;                         &#34;选择&GT;                                              &#34;&GT;                                                    _event_multitime_time_begin&#34;值=&#34;&#34; &GT;         _time_price&#34;值=&#34;&#34; &GT;         _time_price_child&#34;值=&#34;&#34; &GT;         _time_price_other&#34;值=&#34;&#34; &GT;         _due_balance&#34;值=&#34;&#34; &GT;         _max_count&#34;值=&#34;&#34; &GT;         _reserved&#34;值=&#34;&#34; &GT;          &#39 ;. __(&#34;和&#34;,SHORTNAME)。&#39;
&#39 ;;                 回声&#39;&#39;             }             ELSEIF($ use_second_event_day ==&#34;无&#34;){                 回声&#39; &#39 ;. __(&#34;和&#34;,SHORTNAME)。&#39;
&#39 ;;                 回声&#39;&#39;             }             其他{                 回声&#39; &#39 ;. __(&#34;和&#34;,SHORTNAME)。&#39;
&#39 ;;                 回声&#39;&#39;             }         ?&GT;                                                         _event_multiple_week_day_1&#34;名称=&#34; _event_multiple_week_day_1&#34;&GT;                      $ day_name){                         if($ day_id == $ date_day_next1){?&gt;                             &#34;选择&GT;                                                      &#34;&GT;                                                                    _event_multitime_time_begin_1&#34;值=&#34;&#34; &GT;             _time_price&#34;值=&#34;&#34; &GT;             _time_price_child&#34;值=&#34;&#34; &GT;             _time_price_other&#34;值=&#34;&#34; &GT;             _due_balance&#34;值=&#34;&#34; &GT;             _max_count&#34;值=&#34;&#34; &GT;             _reserved&#34;值=&#34;&#34; &GT;                          和             &#34; ID =&#34;第二天use_1&#34;值=&#34;是&#34;检查=&#34;检查&#34; &GT;
                 
    <?php if(!empty($multiple_from_1_next1)){ ?>
    <div class="second_day">
        <label style="display:block"><?php _e('Every', SHORTNAME ); ?><br/ >
            <select id="<?php echo SHORTNAME; ?>_event_multiple_week_day_1_next1" name="<?php echo SHORTNAME; ?>_event_multiple_week_day_1_next1">
                <?php foreach ($week_days as $day_id => $day_name) {
                    if($day_id == $date_day_next1){ ?>
                        <option value="<?php echo $day_id; ?>" selected><?php echo $day_name; ?></option>
                    <?php }
                    else{ ?>
                        <option value="<?php echo $day_id; ?>"><?php echo $day_name; ?></option>
                    <?php }
                } ?>
            </select>
        </label>
        <label style="display:block"><?php _e('From', SHORTNAME); ?><br/ ><input type="text" name="<?php echo SHORTNAME; ?>_event_multitime_time_begin_1_next1" value="<?php echo $multiple_from_1_next1; ?>" ></label>

    </div>
    <?php } ?>

    <?php $y = 1; ?>
    <?php for($i = 1; $i <= 100; $i++){
        $block = get_post_meta( $post->ID, SHORTNAME.'_event_multitime_time_begin_1_next'.$i);  
        if(isset($block[0]) && !empty($block[0])){
        ?>
        <div class="second_day">
        <label style="display:block"><?php _e('Every', SHORTNAME ); ?><br/ >
            <select id="<?php echo SHORTNAME; ?>_event_multiple_week_day_1_next<?php echo $i; ?>" name="<?php echo SHORTNAME; ?>_event_multiple_week_day_1_next<?php echo $i; ?>">
                <?php foreach ($week_days as $day_id => $day_name) {
                    $ddn = $date_day_1_next[$i];
                    if($day_id == $ddn){ ?>
                        <option value="<?php echo $day_id; ?>" selected><?php echo $day_name; ?></option>
                    <?php }
                    else{ ?>
                        <option value="<?php echo $day_id; ?>"><?php echo $day_name; ?></option>
                    <?php }
                } ?>
            </select>
        </label>
        <?php 
        $mfn = $multiple_from_1_next[$i];
        $use_day = $use_second_event_day_next[$i];
        $price = $time_price_next[$i];
        $price_child = $time_price_child_next[$i];
        $price_other = $time_price_other_next[$i];
        $due_balance = $due_balance_next[$i];
        $max_cap = $max_count_next[$i];
        if(isset($reserved_next[$i]) && !empty($reserved_next[$i])){
            $reserve = $reserved_next[$i];
        }
        else{
            $reserve = 0;   
        }

    ?>
        <label style="display:block"><?php _e('From', SHORTNAME); ?><br/ ><input type="text" name="<?php echo SHORTNAME; ?>_event_multitime_time_begin_1_next<?php echo $y; ?>" value="<?php echo $mfn; ?>" ></label>
        <label style="display:block"><?php _e('Price Adult', SHORTNAME); ?><br/ ><input type="text" name="<?php echo SHORTNAME; ?>_time_price_next<?php echo $y; ?>" value="<?php echo $price; ?>" ></label>
        <label style="display:block"><?php _e('Price Child', SHORTNAME); ?><br/ ><input type="text" name="<?php echo SHORTNAME; ?>_time_price_child_next<?php echo $y; ?>" value="<?php echo $price_child; ?>" ></label>
        <label style="display:block"><?php _e('Price Other', SHORTNAME); ?><br/ ><input type="text" name="<?php echo SHORTNAME; ?>_time_price_other_next<?php echo $y; ?>" value="<?php echo $price_other; ?>" ></label>
        <label style="display:block"><?php _e('Minimum Deposit (%)', SHORTNAME); ?><br/ ><input type="text" name="<?php echo SHORTNAME; ?>_due_balance_next<?php echo $y; ?>" value="<?php echo $due_balance; ?>" ></label>
        <label style="display:block"><?php _e('Maximum Capacity', SHORTNAME); ?><br/ ><input type="text" name="<?php echo SHORTNAME; ?>_max_count_next<?php echo $y; ?>" value="<?php echo $max_cap; ?>" ></label>
        <input type="hidden" name="<?php echo SHORTNAME; ?>_reserved_next<?php echo $y; ?>" value="<?php echo $reserve; ?>" >
        <label for="wpcitytour_use_multidate_event" style="margin-right:10px;">And</label>
        <input type="checkbox" num="<?php echo $i; ?>" name="wpcitytour_use_second_event_day_next<?php echo $y; ?>" id="second-day-use_1" value="yes" checked="checked" ><br>
    </div>
    <?php
    $y++;
    }
}?>

</div>
<script type="text/javascript">
    jQuery(document).ready(function($){

        $('.second_day').last().find('input').last().removeAttr('checked');

        $(':checkbox').live('change', function() {

            if($(this).is(":checked")) {

                var id = $('.second_day').length;
                $('.second_day').last().after('<div class="second_day">Every<br /><select id="wpcitytour_event_multiple_week_day_1_next'+id+'" name="wpcitytour_event_multiple_week_day_1_next'+id+'"><option value="0">Sunday</option><option value="1">Monday</option><option value="2">Tuesday</option><option value="3">Wednesday</option><option value="4">Thursday</option><option value="5">Friday</option><option value="6">Saturday</option></select><label style="display:block">From<br/><input type="text" name="wpcitytour_event_multitime_time_begin_1_next'+id+'" value="" ></label><br/><label style="display:block">Price Adult<br/ ><input type="text" name="wpcitytour_time_price_next'+id+'" value="" ></label><br /><label style="display:block">Price Child<br/ ><input type="text" name="wpcitytour_time_price_child_next'+id+'" value="" ></label><br /><label style="display:block">Price Senior / Student<br/ ><input type="text" name="wpcitytour_time_price_other_next'+id+'" value="" ></label><br /><label style="display:block">Maximum Capacity<br/ ><input type="text" name="wpcitytour_max_count_next'+id+'" value="" ></label><br /><input type="hidden" name="wpcitytour_reserved_next'+id+'" value="0" ><label for="wpcitytour_use_multidate_event'+id+'" style="margin-right:10px;">And</label><input type="checkbox" name="wpcitytour_use_second_event_day'+id+'" id="*emphasized text*second-day-use" value="yes"><br><input type="hidden" id="fake" name="wpcitytour_use_multidate_event'+id+'" value="no" disabled="disabled">');
                return false;

           } else{

                var number = $(this).attr('num');
                var post_id = $('#post_ID').val();
                var send_data = {
                    post_id: post_id,
                    number: number,
                    action: "delete_time"
                };

                $.ajax({
                    type: 'POST',
                    url: ajaxurl,
                    dataType: 'json',
                    data: send_data,
                    success:function(result){
                        if(result.error == 0){

                        }
                    }
                });

                if($(this).parents().hasClass('second_day')){
                    $(this).parents('.second_day').next().find('input').val('');
                    $(this).parents('.second_day').next().addClass('trash').removeClass( "second_day" );
                    $('.trash').first().hide();
                }
                else{
                    $('.second_day').last().find('input').val('');
                    $('.second_day').last().addClass('trash').removeClass( "second_day" );
                    $('.trash').first().hide();
                }

                return false;
           }
        });

            return false;
        });

</script>

0 个答案:

没有答案