function wpestate_ajax_add_custom_price()
 {
     //  check_ajax_referer( 'booking_ajax_nonce','security');
     global $current_user;
     get_currentuserinfo();
     $allowded_html = array();
     $userID = $current_user->ID;
     $from = $current_user->user_login;
     $new_custom_price = '';
     if (isset($_POST['new_price'])) {
         $new_custom_price = floatval($_POST['new_price']);
     }
     $property_id = intval($_POST['listing_id']);
     $fromdate = wp_kses($_POST['book_from'], $allowded_html);
     $to_date = wp_kses($_POST['book_to'], $allowded_html);
     // build the price array
     $price_array = get_post_meta($property_id, 'custom_price' . $property_id, true);
     if (empty($price_array)) {
         $price_array = array();
     }
     $from_date = new DateTime($fromdate);
     $from_date_unix = $from_date->getTimestamp();
     $to_date = new DateTime($to_date);
     $to_date_unix = $to_date->getTimestamp();
     $price_array[$from_date_unix] = $new_custom_price;
     $from_date->modify('tomorrow');
     $from_date_unix = $from_date->getTimestamp();
     while ($from_date_unix <= $to_date_unix) {
         $price_array[$from_date_unix] = $new_custom_price;
         $from_date->modify('tomorrow');
         $from_date_unix = $from_date->getTimestamp();
     }
     // clean price options from old data
     $now = time() - 30 * 24 * 60 * 60;
     foreach ($price_array as $key => $value) {
         if ($key < $now) {
             unset($price_array[$key]);
         }
     }
     // end clean
     update_post_meta($property_id, 'custom_price' . $property_id, $price_array);
     echo wpestate_show_price_custom($new_custom_price);
     die;
 }
示例#2
0
function wpestate_draw_month_price($property_price, $month_no, $custom_price_array, $unixmonth, $daywithpost, $thismonth, $thisyear, $last_day)
{
    global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
    $week_begins = intval(get_option('start_of_week'));
    $initial = true;
    $echo = true;
    $table_style = '';
    if ($month_no > 2) {
        $table_style = 'style="display:none;"';
    }
    $calendar_output = '<div class="booking-calendar-wrapper-in-price booking-price col-md-6" data-mno="' . $month_no . '" ' . $table_style . '>
            <div class="month-title"> ' . date("F", mktime(0, 0, 0, $thismonth, 10)) . ' ' . $thisyear . ' </div>
            <table class="wp-calendar booking-calendar">
        <thead>
        <tr>';
    $myweek = array();
    for ($wdcount = 0; $wdcount <= 6; $wdcount++) {
        $myweek[] = $wp_locale->get_weekday(($wdcount + $week_begins) % 7);
    }
    foreach ($myweek as $wd) {
        $day_name = true == $initial ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
        $wd = esc_attr($wd);
        $calendar_output .= "\n\t\t<th scope=\"col\" title=\"{$wd}\">{$day_name}</th>";
    }
    $calendar_output .= '
        </tr>
        </thead>

        <tfoot>
        <tr>';
    $calendar_output .= '
        </tr>
        </tfoot>
        <tbody>
        <tr>';
    // See how much we should pad in the beginning
    $pad = calendar_week_mod(date('w', $unixmonth) - $week_begins);
    if (0 != $pad) {
        $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr($pad) . '" class="pad">&nbsp;</td>';
    }
    $daysinmonth = intval(date('t', $unixmonth));
    for ($day = 1; $day <= $daysinmonth; ++$day) {
        $timestamp = strtotime($day . '-' . $thismonth . '-' . $thisyear) . ' | ';
        $timestamp_java = strtotime($day . '-' . $thismonth . '-' . $thisyear);
        if (isset($newrow) && $newrow) {
            $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
        }
        $newrow = false;
        $has_past_class = 'has_future';
        $is_reserved = 0;
        $calendar_output .= '<td class="calendar-free ' . $has_past_class . '" data-curent-date="' . $timestamp_java . '">';
        $calendar_output .= '<span class="day-label">' . $day . '</span>';
        if (array_key_exists($timestamp_java, $custom_price_array)) {
            // custom price
            $calendar_output .= '<span class="custom_set_price">' . wpestate_show_price_custom($custom_price_array[$timestamp_java]) . '</span>';
        } else {
            // default price
            $calendar_output .= '<span class="price-day">' . wpestate_show_price_custom($property_price) . '</span>';
        }
        $calendar_output .= '</td>';
        if (6 == calendar_week_mod(date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear)) - $week_begins)) {
            $newrow = true;
        }
    }
    $pad = 7 - calendar_week_mod(date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear)) - $week_begins);
    if ($pad != 0 && $pad != 7) {
        $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr($pad) . '">&nbsp;</td>';
    }
    $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table></div>";
    if ($echo) {
        echo apply_filters('get_calendar', $calendar_output);
    } else {
        return apply_filters('get_calendar', $calendar_output);
    }
}