statuses = array( 'all' => array('label'=>__('All','dbem'), 'search'=>false), 'pending' => array('label'=>__('Pending','dbem'), 'search'=>0), 'confirmed' => array('label'=>__('Confirmed','dbem'), 'search'=>1), 'cancelled' => array('label'=>__('Cancelled','dbem'), 'search'=>2), 'rejected' => array('label'=>__('Rejected','dbem'), 'search'=>3), 'needs-attention' => array('label'=>__('Needs Attention','dbem'), 'search'=>array(0,5)), 'incomplete' => array('label'=>__('Incomplete Bookings','dbem'), 'search'=>array(0,4,5)), 'awaiting-online' => array('label'=>__('Awaiting Online Payment','dbem'), 'search'=>4), 'awaiting-payment' => array('label'=>__('Awaiting Offline Payment','dbem'), 'search'=>5) ); //Set basic vars $this->order = ( !empty($_REQUEST ['order']) ) ? $_REQUEST ['order']:'ASC'; $this->orderby = ( !empty($_REQUEST ['order']) ) ? $_REQUEST ['order']:'booking_name'; $this->limit = ( !empty($_REQUEST['limit']) ) ? $_REQUEST['limit'] : 20;//Default limit $this->page = ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:1; $this->offset = ( $this->page > 1 ) ? ($this->page-1)*$this->limit : 0; $this->scope = ( !empty($_REQUEST['scope']) && array_key_exists($_REQUEST ['scope'], em_get_scopes()) ) ? $_REQUEST ['scope']:get_option('dbem_default_bookings_search','future'); $this->status = ( !empty($_REQUEST['status']) && array_key_exists($_REQUEST['status'], $this->statuses) ) ? $_REQUEST['status']:get_option('dbem_default_bookings_search','needs-attention'); //build template of possible collumns $this->cols_template = apply_filters('em_bookings_table_cols_template', array( 'display_name'=>__('Booker','dbem'), 'event_name'=>__('Event','dbem'), 'user_email'=>__('E-mail','dbem'), 'dbem_phone'=>__('Phone Number','dbem'), 'booking_spaces'=>__('Spaces','dbem'), 'booking_status'=>__('Status','dbem'), 'booking_price'=>__('Price','dbem'), 'actions' => __('Actions','dbem') )); //calculate collumns if post requests if( !empty($_REQUEST ['cols']) && !is_array($_REQUEST ['cols']) ){ $this->cols = explode(',',$_REQUEST['cols']); }elseif( !empty($_REQUEST ['cols']) ){ $this->cols = $_REQUEST['cols']; } foreach($this->cols as $col_key){ if( !array_key_exists($col_key, $this->cols_template)){ unset($this->cols[$col_key]); } } } /** * @return EM_Person|false */ function get_person(){ global $EM_Person; if( !empty($this->person) && is_object($this->person) ){ return $this->person; }elseif( !empty($_REQUEST['person_id']) && !empty($EM_Person) && is_object($EM_Person) ){ return $EM_Person; } return false; } /** * @return EM_Ticket|false */ function get_ticket(){ global $EM_Ticket; if( !empty($this->ticket) && is_object($this->ticket) ){ return $this->ticket; }elseif( !empty($EM_Ticket) && is_object($EM_Ticket) ){ return $EM_Ticket; } return false; } /** * @return $EM_Event|false */ function get_event(){ global $EM_Event; if( !empty($this->event) && is_object($this->event) ){ return $this->event; }elseif( !empty($EM_Event) && is_object($EM_Event) ){ return $EM_Event; } return false; } function get_bookings($force_refresh = true){ if( empty($this->bookings) || $force_refresh ){ $this->events = array(); $EM_Ticket = $this->get_ticket(); $EM_Event = $this->get_event(); $EM_Person = $this->get_person(); if( $EM_Ticket !== false ){ //searching bookings with a specific ticket $this->bookings = $EM_Ticket->get_bookings(); $this->bookings_count = (is_array($this->bookings->bookings)) ? count($this->bookings->bookings):0; $this->events[$EM_Ticket->event_id] = $EM_Ticket->get_event(); }elseif( $EM_Event !== false ){ //bookings for an event $args = array('event'=>$EM_Event->event_id,'scope'=>false,'status'=>$this->get_status_search(),'order'=>$this->order,'orderby'=>$this->orderby); $this->bookings_count = EM_Bookings::count($args); $this->bookings = EM_Bookings::get(array_merge($args, array('limit'=>$this->limit,'offset'=>$this->offset))); $this->events[$EM_Event->event_id] = $EM_Event; }elseif( $EM_Person !== false ){ $args = array('person'=>$EM_Person->ID,'scope'=>$this->scope,'status'=>$this->get_status_search(),'order'=>$this->order,'orderby'=>$this->orderby); $this->bookings_count = EM_Bookings::count($args); $this->bookings = EM_Bookings::get(array_merge($args, array('limit'=>$this->limit,'offset'=>$this->offset))); foreach($this->bookings->bookings as $EM_Booking){ //create event if( !array_key_exists($EM_Booking->event_id,$this->events) ){ $this->events[$EM_Booking->event_id] = new EM_Event($EM_Booking->event_id); } } }else{ //all bookings for a status $args = array('status'=>$this->get_status_search(),'scope'=>$this->scope,'order'=>$this->order,'orderby'=>$this->orderby); $this->bookings_count = EM_Bookings::count($args); $this->bookings = EM_Bookings::get(array_merge($args, array('limit'=>$this->limit,'offset'=>$this->offset))); //Now let's create events and bookings for this instead of giving each booking an event foreach($this->bookings->bookings as $EM_Booking){ //create event if( !array_key_exists($EM_Booking->event_id,$this->events) ){ $this->events[$EM_Booking->event_id] = new EM_Event($EM_Booking->event_id); } } } } return $this->bookings; } function get_count(){ return $this->bookings_count; } function get_status_search(){ if(is_array($this->statuses[$this->status]['search'])){ return implode(',',$this->statuses[$this->status]['search']); } return $this->statuses[$this->status]['search']; } function output(){ do_action('em_bookings_table_header',$this); //won't be overwritten by JS $this->output_content(); do_action('em_bookings_table_footer',$this); //won't be overwritten by JS } /** * Used to output AJAX content as well as normal in-table content */ function output_content(){ $EM_Ticket = $this->get_ticket(); $EM_Event = $this->get_event(); $EM_Person = $this->get_person(); $this->get_bookings(true); //get bookings and refresh ?>