className = get_class( $this ); $this->parentPath = trailingslashit( dirname( dirname( dirname( __FILE__ ) ) ) ); $this->parentUrl = trailingslashit( plugins_url( '', $this->parentPath ) ); // Register all TribeEventsTickets api consumers self::$active_modules[$this->className] = $this->pluginName; self::$active = true; if ( is_admin() ) { add_action( 'tribe_events_event_save', array( $this, 'save_tickets' ), 10, 1 ); add_action( 'tribe_events_tickets_metabox_advanced', array( $this, 'do_metabox_advanced_options' ), 10, 2 ); } add_filter( 'tribe_events_tickets_modules', array( $this, 'modules' ) ); // Admin AJAX actions add_action( 'wp_ajax_tribe-ticket-add-' . $this->className, array( $this, 'ajax_handler_ticket_add' ) ); add_action( 'wp_ajax_tribe-ticket-delete-' . $this->className, array( $this, 'ajax_handler_ticket_delete' ) ); add_action( 'wp_ajax_tribe-ticket-edit-' . $this->className, array( $this, 'ajax_handler_ticket_edit' ) ); add_action( 'wp_ajax_tribe-ticket-checkin-' . $this->className, array( $this, 'ajax_handler_attendee_checkin' ) ); add_action( 'wp_ajax_tribe-ticket-uncheckin-' . $this->className, array( $this, 'ajax_handler_attendee_uncheckin' ) ); // Attendees list add_filter( 'post_row_actions', array( $this, 'attendees_row_action' ) ); add_action( 'admin_menu', array( $this, 'attendees_page_register' ) ); // Front end add_filter( 'tribe_get_ticket_form', array( $this, 'front_end_tickets_form' ) ); } public final function do_meta_box( $post_id ) { if ( self::$done_metabox ) return; $startMinuteOptions = TribeEventsViewHelpers::getMinuteOptions( null ); $endMinuteOptions = TribeEventsViewHelpers::getMinuteOptions( null ); $startHourOptions = TribeEventsViewHelpers::getHourOptions( null, true ); $endHourOptions = TribeEventsViewHelpers::getHourOptions( null, false ); $startMeridianOptions = TribeEventsViewHelpers::getMeridianOptions( null, true ); $endMeridianOptions = TribeEventsViewHelpers::getMeridianOptions( null ); $tickets = self::get_event_tickets( $post_id ); include $this->parentPath . 'admin-views/tickets-meta-box.php'; self::$done_metabox = true; } protected final function load_pdf_libraries() { if ( class_exists( 'FPDF' ) ) return; include $this->parentPath . 'vendor/fpdf/fpdf.php'; } public final function generate_attendees_PDF( $tickets_list ) { $this->load_pdf_libraries(); $pdf = new FPDF(); $ecp = TribeEvents::instance(); $pdf->AddFont('OpenSans','','opensans.php'); $pdf->AddFont('SteelFish','','steelfish.php'); $pdf->SetTitle('EventTicket'); $pdf->SetAuthor('The Events Calendar'); $pdf->SetCreator('The Events Calendar'); $defaults = array( 'event_id' => 0, 'ticket_name' => '', 'holder_name' => '', 'order_id' => '', 'ticket_id' => '', 'security_code' => '' ); foreach ( $tickets_list as $ticket ) { $ticket = wp_parse_args( $ticket, $defaults ); $event = get_post( $ticket['event_id'] ); $venue_id = tribe_get_venue_id( $event->ID ); $venue = ( !empty( $venue_id ) ) ? get_post( $venue_id )->post_title : ''; $address = tribe_get_address( $event->ID ); $zip = tribe_get_zip( $event->ID ); $state = tribe_get_stateprovince( $event->ID ); $city = tribe_get_city( $event->ID ); $pdf->AddPage(); $pdf->SetDrawColor( 28, 166, 205 ); $pdf->SetFillColor( 28, 166, 205 ); $pdf->Rect( 15, 10, 180, 34, 'F' ); $pdf->SetTextColor( 255 ); $pdf->SetFont( 'OpenSans', '', 10 ); $pdf->SetXY( 30, 15 ); $pdf->Write( 5, __( 'EVENT NAME:', 'tribe-events-calendar' ) ); $pdf->SetXY( 30, 28 ); $pdf->SetFont( 'SteelFish', '', 53 ); $title = strtoupper( utf8_decode( $event->post_title ) ); $size = 53; while ( $pdf->GetStringWidth( $title ) > 151 ) { $size--; $pdf->SetFontSize( $size ); } $pdf->Write( 5, $title ); $pdf->SetTextColor( 41 ); $pdf->SetFont( 'OpenSans', '', 10 ); $pdf->SetXY( 30, 50 ); $pdf->Write( 5, __( 'TICKET HOLDER:', 'tribe-events-calendar' ) ); $pdf->SetXY( 104, 50 ); $pdf->Write( 5, __( 'LOCATION:', 'tribe-events-calendar' ) ); $pdf->SetFont( 'SteelFish', '', 30 ); $pdf->SetXY( 30, 59 ); $holder = strtoupper( utf8_decode( $ticket['holder_name'] ) ); $size = 30; while ( $pdf->GetStringWidth( $holder ) > 70 ) { $size--; $pdf->SetFontSize( $size ); } $pdf->Write( 5, $holder ); $pdf->SetXY( 104, 59 ); $venue = strtoupper( utf8_decode( $venue ) ); $size = 30; while ( $pdf->GetStringWidth( $venue ) > 70 ) { $size--; $pdf->SetFontSize( $size ); } $pdf->Write( 5, $venue ); $pdf->SetXY( 104, 71 ); $address = strtoupper( utf8_decode( $address ) ); $size = 30; while ( $pdf->GetStringWidth( $address ) > 70 ) { $size--; $pdf->SetFontSize( $size ); } $pdf->Write( 5, $address ); $pdf->SetXY( 104, 83 ); $address2 = array( $city, $state, $zip ); $address2 = array_filter( $address2 ); $address2 = join( ', ', $address2 ); $address2 = strtoupper( utf8_decode( $address2 ) ); $size = 30; while ( $pdf->GetStringWidth( $address2 ) > 70 ) { $size--; $pdf->SetFontSize( $size ); } $pdf->Write( 5, $address2 ); $pdf->Line( 15, 97, 195, 97 ); $pdf->SetFont( 'OpenSans', '', 10 ); $pdf->SetXY( 30, 105 ); $pdf->Write( 5, __( 'ORDER:', 'tribe-events-calendar' ) ); $pdf->SetXY( 80, 105 ); $pdf->Write( 5, __( 'TICKET:', 'tribe-events-calendar' ) ); $pdf->SetXY( 120, 105 ); $pdf->Write( 5, __( 'VERIFICATION:', 'tribe-events-calendar' ) ); $pdf->SetFont( 'SteelFish', '', 53 ); $pdf->SetXY( 30, 118 ); $pdf->Write( 5, $ticket['order_id'] ); $pdf->SetXY( 80, 118 ); $pdf->Write( 5, $ticket['ticket_id'] ); $pdf->SetXY( 120, 118 ); $pdf->Write( 5, $ticket['security_code'] ); $pdf->Rect( 15, 135, 180, 15, 'F' ); $pdf->SetTextColor( 255 ); $pdf->SetFont( 'OpenSans', '', 10 ); $pdf->SetXY( 30, 140 ); $pdf->Write( 5, get_bloginfo('name') ); $pdf->SetXY( 104, 140 ); $pdf->Write( 5, get_home_url() ); } $upload_path = wp_upload_dir(); $upload_url = $upload_path['url']; $upload_path = $upload_path['path']; $filename = wp_unique_filename( $upload_path, sanitize_file_name( md5( time() ) ) . '.pdf' ); $upload_path = trailingslashit( $upload_path ) . $filename; $upload_url = trailingslashit( $upload_url ) . $filename; $pdf->Output( $upload_path, 'F' ); return array( $upload_path, $upload_url ); } /* AJAX Handlers */ public final function ajax_handler_ticket_add() { if ( ! isset( $_POST["formdata"] ) ) $this->ajax_error( 'Bad post' ); if ( ! isset( $_POST["post_ID"] ) ) $this->ajax_error( 'Bad post' ); $data = wp_parse_args( $_POST["formdata"] ); $post_id = $_POST["post_ID"]; if ( !isset( $data["ticket_provider"] ) || !$this->module_is_valid( $data["ticket_provider"] ) ) $this->ajax_error( 'Bad module' ); $ticket = new TribeEventsTicketObject(); $ticket->ID = isset( $data["ticket_id"] ) ? $data["ticket_id"] : null; $ticket->name = isset( $data["ticket_name"] ) ? $data["ticket_name"] : null; $ticket->description = isset( $data["ticket_description"] ) ? $data["ticket_description"] : null; $ticket->price = isset( $data["ticket_price"] ) ? trim( $data["ticket_price"] ) : 0; if ( empty( $ticket->price ) ) { $ticket->price = 0; } else { //remove non-money characters $ticket->price = preg_replace( '/[^0-9\.]/Uis', '', $ticket->price ); } if ( !empty( $data['ticket_start_date'] ) ) { $meridian = !empty( $data['ticket_start_meridian'] ) ? " " . $data['ticket_start_meridian'] : ""; $ticket->start_date = date( TribeDateUtils::DBDATETIMEFORMAT, strtotime( $data['ticket_start_date'] . " " . $data['ticket_start_hour'] . ":" . $data['ticket_start_minute'] . ":00" . $meridian ) ); } if ( !empty( $data['ticket_end_date'] ) ) { $meridian = !empty( $data['ticket_end_meridian'] ) ? " " . $data['ticket_end_meridian'] : ""; $ticket->end_date = date( TribeDateUtils::DBDATETIMEFORMAT, strtotime( $data['ticket_end_date'] . " " . $data['ticket_end_hour'] . ":" . $data['ticket_end_minute'] . ":00" . $meridian ) ); } $ticket->provider_class = $this->className; // Pass the control to the child object $return = $this->save_ticket( $post_id, $ticket, $data ); // If saved OK, let's create a tickets list markup to return if ( $return ) { $tickets = $this->get_event_tickets( $post_id ); $return = $this->get_ticket_list_markup( $tickets ); $return = $this->notice( __( 'Your ticket has been saved.', 'tribe-events-calendar' ) ) . $return; } $this->ajax_ok( $return ); } public final function ajax_handler_attendee_checkin() { if ( ! isset( $_POST["order_ID"] ) || intval( $_POST["order_ID"] ) == 0 ) $this->ajax_error( 'Bad post' ); if ( ! isset( $_POST["provider"] ) || ! $this->module_is_valid( $_POST["provider"] ) ) $this->ajax_error( 'Bad module' ); $order_id = $_POST["order_ID"]; // Pass the control to the child object $return = $this->checkin( $order_id ); $this->ajax_ok( $return ); } public final function ajax_handler_attendee_uncheckin() { if ( !isset( $_POST["order_ID"] ) || intval( $_POST["order_ID"] ) == 0 ) $this->ajax_error( 'Bad post' ); if ( !isset( $_POST["provider"] ) || !$this->module_is_valid( $_POST["provider"] ) ) $this->ajax_error( 'Bad module' ); $order_id = $_POST["order_ID"]; // Pass the control to the child object $return = $this->uncheckin( $order_id ); $this->ajax_ok( $return ); } public final function ajax_handler_ticket_delete() { if ( ! isset( $_POST["post_ID"] ) ) $this->ajax_error( 'Bad post' ); if ( ! isset( $_POST["ticket_id"] ) ) $this->ajax_error( 'Bad post' ); $post_id = $_POST["post_ID"]; $ticket_id = $_POST["ticket_id"]; // Pass the control to the child object $return = $this->delete_ticket( $post_id, $ticket_id ); // If deleted OK, let's create a tickets list markup to return if ( $return ) { $tickets = $this->get_event_tickets( $post_id ); $return = $this->get_ticket_list_markup( $tickets ); $return = $this->notice( __( 'Your ticket has been deleted.', 'tribe-events-calendar' ) ) . $return; } $this->ajax_ok( $return ); } public final function ajax_handler_ticket_edit() { if ( ! isset( $_POST["post_ID"] ) ) $this->ajax_error( 'Bad post' ); if ( ! isset( $_POST["ticket_id"] ) ) $this->ajax_error( 'Bad post' ); $post_id = $_POST["post_ID"]; $ticket_id = $_POST["ticket_id"]; $return = get_object_vars( $this->get_ticket( $post_id, $ticket_id ) ); ob_start(); $this->do_metabox_advanced_options( $post_id, $ticket_id ); $extra = ob_get_contents(); ob_end_clean(); $return["advanced_fields"] = $extra; $this->ajax_ok( $return ); } protected function notice( $msg ) { return sprintf( '
%s