function send_email_non_paid_members_callback()
 {
     global $wpdb;
     $data = stripslashes_deep($_POST);
     $event_id = !empty($data['event_id']) && (int) $data['event_id'] ? (int) $data['event_id'] : false;
     $status = 'yes';
     //!empty($data['status']) ? $data['status'] : false;
     $response = array('status' => 1, 'sent' => 0);
     if (!$event_id || !$status) {
         die(json_encode($response));
     }
     $event = new Eab_EventModel(get_post($event_id));
     if (!$event->is_premium()) {
         die(json_encode($response));
     }
     // Not a paid event
     $all_events = array($event);
     if ($event->is_recurring()) {
         $all_events = Eab_CollectionFactory::get_all_recurring_children_events($event);
     }
     $all_event_ids = array();
     foreach ($all_events as $e) {
         $all_event_ids[] = $e->get_id();
     }
     $all_event_ids = array_filter(array_map('intval', $all_event_ids));
     $bookings = $wpdb->get_results($wpdb->prepare("SELECT id,user_id,event_id FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id IN(" . join(',', $all_event_ids) . ") AND status = %s ORDER BY timestamp;", $status));
     if (!count($bookings)) {
         die(json_encode($response));
     }
     foreach ($bookings as $booking) {
         if ($event->user_paid($booking->user_id)) {
             continue;
         }
         $this->_send_notification_email($event->get_id(), $user_id);
         $response['sent'] += 1;
     }
     $response['status'] = 0;
     die(json_encode($response));
 }
 /**
  * Converts event RSVPs into a send list.
  */
 public function rsvps_to_member_group($event_id, $bookings = array())
 {
     if (empty($event_id) || empty($bookings)) {
         return false;
     }
     $event = new Eab_EventModel(get_post($event_id));
     $all_events = array($event);
     if ($event->is_recurring()) {
         $all_events = Eab_CollectionFactory::get_all_recurring_children_events($event);
     }
     $all_event_ids = array();
     foreach ($all_events as $e) {
         $all_event_ids[] = $e->get_id();
     }
     $all_event_ids = array_filter(array_map('intval', $all_event_ids));
     $rsvps = $this->_db->get_col("SELECT DISTINCT user_id FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id IN(" . join(',', $all_event_ids) . ") AND status IN ('" . join("','", $bookings) . "')");
     //if (empty($rsvps)) return false;
     $group_id = $this->_spawn_event_rsvp_group($event, $bookings);
     if (empty($group_id)) {
         return false;
     }
     return !empty($rsvps) ? $this->_newsletter->add_members_to_groups($rsvps, $group_id, false) : true;
 }
 protected function _get_bookings($status)
 {
     $event = new Eab_EventModel($this->_event_id);
     $event_id = "event_id = " . (int) $this->_event_id;
     if ($event->is_recurring()) {
         $all_event_ids = array();
         $events = Eab_CollectionFactory::get_all_recurring_children_events($event);
         foreach ($events as $e) {
             $all_event_ids[] = $e->get_id();
         }
         $all_event_ids = array_filter(array_map('intval', $all_event_ids));
         $event_id = "event_id IN(" . join(',', $all_event_ids) . ")";
     }
     global $wpdb;
     return $wpdb->get_results($wpdb->prepare("SELECT id,user_id,event_id,timestamp FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE {$event_id} AND status = %s ORDER BY timestamp;", $status));
 }
 /**
  * Maps order to a related Event ID, if possible.
  */
 function order_to_event_id($product_id, $variation = array())
 {
     $event_id = get_post_meta($product_id, 'eab_event_id', true);
     if (!$event_id) {
         return false;
     }
     $event = new Eab_EventModel(get_post($event_id));
     if (!$event->is_recurring()) {
         return $event_id;
     }
     // Event is recurring, check SKUs
     return !empty($variation['SKU']) ? $variation['SKU'] : false;
 }
 private function _cancel_event($event_id)
 {
     $event = new Eab_EventModel(get_post($event_id));
     if ($event->is_recurring() && !$event->is_recurring_child()) {
         // Recurring root - cancel children too
         update_post_meta($event_id, 'incsub_event_status', self::STATUS_CANCEL);
         $events = Eab_CollectionFactory::get_all_recurring_children_events($event);
         foreach ($events as $event) {
             $this->_cancel_event($event->get_id());
         }
     } else {
         // Regular event or single instance. All good
         update_post_meta($event_id, 'incsub_event_status', self::STATUS_CANCEL);
         $this->_add_event_to_schedule_queue($event_id);
     }
 }
 function manage_posts_custom_column($column)
 {
     global $post;
     switch ($column) {
         case "attendees":
             global $wpdb;
             $event = $post instanceof Eab_EventModel ? $post : new Eab_EventModel($post);
             $yes = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id = %d AND status = %s;", $event->get_id(), Eab_EventModel::BOOKING_YES));
             $no = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id = %d AND status = %s;", $event->get_id(), Eab_EventModel::BOOKING_NO));
             $maybe = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id = %d AND status = %s;", $event->get_id(), Eab_EventModel::BOOKING_MAYBE));
             printf('<b>' . __('Attending / Undecided', self::TEXT_DOMAIN) . ':</b> %d / %d<br />', $yes, $maybe);
             printf('<b>' . __('Not Attending', self::TEXT_DOMAIN) . ':</b> %d', $no);
             echo '&nbsp;';
             echo '<a class="button" href="' . admin_url('index.php?eab_export=attendees&event_id=' . $event->get_id()) . '" class="eab-export_attendees">' . __('Export', self::TEXT_DOMAIN) . '</a>';
             break;
         case "start":
             $event = new Eab_EventModel($post);
             $df = get_option('date_format', 'Y-m-d');
             if (!$event->is_recurring()) {
                 echo date_i18n($df, $event->get_start_timestamp()) . ' - ' . date_i18n($df, $event->get_end_timestamp());
             } else {
                 $repeats = $event->get_supported_recurrence_intervals();
                 $title = @$repeats[$event->get_recurrence()];
                 $start = date_i18n($df, $event->get_recurrence_starts());
                 $end = date_i18n($df, $event->get_recurrence_ends());
                 printf(__("From %s, repeats every %s until %s", self::TEXT_DOMAIN), $start, $title, $end);
             }
             break;
         case "venue":
             $event = new Eab_EventModel($post);
             echo $event->get_venue_location();
             break;
         case "event":
             $event = new Eab_EventModel($post);
             $post_type_object = get_post_type_object($post->post_type);
             $edit_link = get_edit_post_link($event->get_id());
             $statuses = array();
             if ('draft' == $post->post_status) {
                 $statuses[] = __('Draft');
             }
             if ('private' == $post->post_status) {
                 $statuses[] = __('Private');
             }
             if ('pending' == $post->post_status) {
                 $statuses[] = __('Pending');
             }
             $status = $statuses ? ' - <span class="post-state">' . join(', ', $statuses) . '</span>' : '';
             $title = current_user_can($post_type_object->cap->edit_post, $event->get_id()) && 'trash' != $post->post_status ? '<strong>' . '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $event->get_title())) . '">' . $event->get_title() . '</a>&nbsp;' . $status . '</strong>' : '<strong>' . $event->get_title() . '&nbsp;' . $status . '</strong>';
             if (current_user_can($post_type_object->cap->edit_post, $event->get_id()) && 'trash' != $post->post_status) {
                 $actions['edit'] = '<a title="' . esc_attr(__('Edit Event', self::TEXT_DOMAIN)) . '" href="' . $edit_link . '">' . __('Edit') . '</a>';
                 if (!$event->is_recurring()) {
                     $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this Event inline', self::TEXT_DOMAIN)) . '">' . __('Quick&nbsp;Edit') . '</a>';
                 }
             }
             if (current_user_can($post_type_object->cap->delete_post, $event->get_id())) {
                 if ('trash' == $post->post_status) {
                     $actions['untrash'] = "<a title='" . esc_attr(__('Restore this Event from the Trash', self::TEXT_DOMAIN)) . "' href='" . wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&amp;action=untrash', $event->get_id())), 'untrash-' . $post->post_type . '_' . $event->get_id()) . "'>" . __('Restore') . "</a>";
                 } else {
                     if (EMPTY_TRASH_DAYS) {
                         $actions['trash'] = '<a class="submitdelete" title="' . esc_attr(__('Move this Event to the Trash', self::TEXT_DOMAIN)) . '" href="' . get_delete_post_link($event->get_id()) . '">' . __('Trash') . '</a>';
                     }
                 }
                 if ('trash' == $post->post_status || !EMPTY_TRASH_DAYS) {
                     $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this Event permanently', self::TEXT_DOMAIN)) . "' href='" . get_delete_post_link($event->get_id(), '', true) . "'>" . __('Delete Permanently') . "</a>";
                 }
             }
             if ('trash' != $post->post_status) {
                 $event_id = $event->get_id();
                 if ($event->is_recurring()) {
                     $children = Eab_CollectionFactory::get_all_recurring_children_events($event);
                     if (!$children || !$children[0] instanceof Eab_EventModel) {
                         $event_id = false;
                     } else {
                         $event_id = $children[0]->get_id();
                     }
                 }
                 if ($event_id) {
                     $actions['view'] = '<a href="' . get_permalink($event_id) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $event->get_title())) . '" rel="permalink">' . __('View') . '</a>';
                 }
             }
             echo $title;
             if (!empty($actions)) {
                 foreach ($actions as $action => $link) {
                     $actions[$action] = "<span class='{$action}'>{$link}</span>";
                 }
             }
             echo '<div class="row-actions">' . join('&nbsp;|&nbsp;', $actions) . '</div>';
             get_inline_data($post);
             break;
     }
 }