Advertisement
Beee

my-bookings.php

Apr 18th, 2015
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.26 KB | None | 0 0
  1. <?php
  2.     do_action('em_template_my_bookings_header');
  3.     global $wpdb, $current_user, $EM_Notices, $EM_Person;
  4.     if ( is_user_logged_in() ) :
  5.         $EM_Person = new EM_Person( get_current_user_id() );
  6.         $EM_Bookings = $EM_Person->get_bookings();
  7.         $bookings_count = count($EM_Bookings->bookings);
  8.         if ($bookings_count > 0) {
  9.             // Get events here in one query to speed things up
  10.             $event_ids = array();
  11.             foreach($EM_Bookings as $EM_Booking) {
  12.                 $event_ids[] = $EM_Booking->event_id;
  13.             }
  14.         }
  15.         $limit = ( !empty($_GET['limit']) ) ? $_GET['limit'] : 20; // Default limit
  16.         $page = ( !empty($_GET['pno']) ) ? $_GET['pno']:1;
  17.         $offset = ( $page > 1 ) ? ($page-1) * $limit : 0;
  18.         echo $EM_Notices;
  19. ?>
  20.     <div class='em-my-bookings'>
  21.             <?php if ( $bookings_count >= $limit ) : ?>
  22.             <div class='tablenav'>
  23.             <?php
  24.             if ( $bookings_count >= $limit ) {
  25.                 $link = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%'), false); // don't html encode, so em_paginate does its thing
  26.                 $bookings_nav = em_paginate( $link, $bookings_count, $limit, $page);
  27.                 echo $bookings_nav;
  28.             }
  29.             ?>
  30.                 <div class="clear"></div>
  31.             </div>
  32.             <?php endif; ?>
  33.             <div class="clear"></div>
  34.             <?php if ( $bookings_count > 0 ) : ?>
  35.             <div class='table-wrap'>
  36.             <table id='dbem-bookings-table' class='widefat post fixed'>
  37.                 <?php // set table columns ?>
  38.                 <thead>
  39.                     <tr>
  40.                         <th class='manage-column' scope='col'><?php _e('Event', 'dbem'); ?></th>
  41.                         <th class='manage-column' scope='col'><?php _e('Date', 'dbem'); ?></th>
  42.                         <th class='manage-column' scope='col'><?php _e('Status', 'dbem'); ?></th>
  43.                         <th class='manage-column' scope='col'>&nbsp;</th>
  44.                     </tr>
  45.                 </thead>
  46.                 <tbody>
  47.                     <?php
  48.                         $rowno = 0;
  49.                         $event_count = 0;
  50.                         foreach ($EM_Bookings as $EM_Booking) {
  51.                             // start of an event
  52.                             $EM_Event = $EM_Booking->get_event();                      
  53.                             if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
  54.                                 $rowno++;
  55.                                 $bookingid              = $EM_Booking->output("#_BOOKINGID");
  56.                                 $eventid                    = $EM_Event->output("#_EVENTID");
  57.                                 $event_post_id      = $EM_Event->output("#_EVENTPOSTID");
  58.                                 $siteurl                    = home_url();
  59.                                 $stripzerodprice    = str_replace("000","0",$EM_Booking->booking_price);
  60.                     ?>
  61.                     <tr class="bookingstartrow">
  62.                         <td class="eventlink"><?php echo $EM_Event->output("#_EVENTLINK"); ?></td>
  63.                         <td><?php echo date_i18n( get_option('dbem_date_format'), $EM_Event->start ); ?></td>
  64.                         <td>
  65.                             <?php
  66.                                 echo $EM_Booking->get_status(); // echo payment status
  67.                                
  68.                                 if ( in_array($EM_Booking->booking_status, array(0,5)) ) { // if status = pending/awaiting payment 
  69.                                     // event specific paypal values
  70.                                     $paypalaccount      = get_post_meta($event_post_id, 'Paypal', true);
  71.                                     $paypalmerchant     = get_post_meta($event_post_id, 'Merchant ID', true);
  72.                                     $paypalcurrency     = get_post_meta($event_post_id, 'Paypal currency', true);
  73.                                     if ( empty($paypalcurrency) ) { $paypalcurrency = 'EUR'; } // if no Paypal currency set, use EUR
  74.  
  75.                                     if ( !empty($paypalaccount) ) { // paypal payments standard
  76.                                         ?>
  77.                                         <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
  78.                                             <input type="hidden" name="amount" value="<?php echo $stripzerodprice; ?>">
  79.                                             <input type="hidden" name="business" value="<?php echo $paypalaccount; ?>">
  80.                                             <input type="hidden" name="cancel_return" value="<?php echo $siteurl; ?>/events/cancelled/">                                               
  81.                                             <input type="hidden" name="cmd" value="_xclick">
  82.                                             <input type="hidden" name="currency_code" value="<?php echo $paypalcurrency; ?>">
  83.                                             <input type="hidden" name="custom" value="<?php echo $bookingid; ?>">                                              
  84.                                             <input type="hidden" name="item_name" value="<?php echo $EM_Event->output("#_EVENTNAME"); ?>">                                             
  85.                                             <input type="hidden" name="notify_url" value="<?php echo $siteurl; ?>/wp-admin/admin-ajax.php?action=em_payment&em_payment_gateway=paypal">
  86.                                             <input type="hidden" name="no_note" value="0">
  87.                                             <input type="hidden" name="quantity" value="1">
  88.                                             <input type="hidden" name="return" value="<?php echo $siteurl; ?>/events/registration-completed/">                                             
  89.                                             <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/x-click-but6.gif" border="0" name="submit" alt="Pay now with Paypal">
  90.                                         </form>
  91.                                         <?
  92.                                     } // end if paypal payments standard
  93.                                                                    
  94.                                     if ( !empty($paypalmerchant) ) { // if organizer has business account/merchant id
  95.                                         echo '<p><script
  96.                                             async="async"
  97.                                             src="http://www.domein.com/wp-content/themes/theme-name/js/paypal-button.min.js?merchant='.$paypalmerchant.'"
  98.                                             custom="'.$bookingid.'"
  99.                                             data-button="paynow"
  100.                                             data-name="'.$EM_Event->event_name.'"
  101.                                             data-quantity="1"
  102.                                             data-amount="'.$stripzerodprice.'"
  103.                                             data-currency="'.$paypalcurrency.'"
  104.                                             data-shipping="0"
  105.                                             data-tax="0"
  106.                                             data-cancel-return="'.$siteurl.'/events/cancelled/"
  107.                                             data-return="'.$siteurl.'/events/registration-completed/"
  108.                                             data-callback="'.$siteurl.'/wp-admin/admin-ajax.php?action=em_payment&em_payment_gateway=paypal"
  109.                                             txn_id="'.$bookingid.'"
  110.                                         ></script></p>';
  111.                                         echo '<p></p>';
  112.                                     }
  113.  
  114.                                 }
  115.                             ?>
  116.                         </td>
  117.                         <td>
  118.                         <?php
  119.                             if ( !in_array($EM_Booking->booking_status, array(1)) ) { // if status = pending/awaiting payment  
  120.                                
  121.                                 // option to resend last email
  122.                                 echo '<form action="" method="post" class="em-booking-single-status-info">';
  123.                                 echo '<input type="submit" class="em-booking-resend-email" id="em-booking-resend-email" value="Resend Mail" />';
  124.                                 echo '<input type="hidden" name="action" value="booking_resend_email"/>';
  125.                                 echo '<input type="hidden" name="booking_id" value="'.$bookingid.'"/>';
  126.                                 echo '<input type="hidden" name="event_id" value="'.$EM_Event->output("#_EVENTID").'"/>';
  127.                                 echo '<input type="hidden" name="_wpnonce" value="'.wp_create_nonce('booking_resend_email_'.$bookingid).'"/>';
  128.                                 echo '</form>';
  129.    
  130.                             }
  131.                         ?>
  132.                         </td>
  133.                     </tr>
  134.                     <tr class="">
  135.                         <td colspan="5">
  136.                             <?php
  137.                                 if ( in_array($EM_Booking->booking_status, array(0,5)) ) { // if status = pending/awaiting payment 
  138.                                     // bank info
  139.                                     $ibaninfo               = get_post_meta($event_post_id, 'Bank IBAN', true);
  140.                                     $bicinfo                    = get_post_meta($event_post_id, 'Bank BIC', true);
  141.                                     $accountholder      = get_post_meta($event_post_id, 'Account holder', true);
  142.                                    
  143.                                 if ( $ibaninfo && $bicinfo && $accountholder ) {
  144.                                         echo '<div class="toon fjalla">Pay now by bank (click to for more info)</div>';
  145.                                         echo '<div class="verberg">';
  146.                                             echo '<p><span class="fjalla">BANK INFO</span><br />IBAN: '.$ibaninfo.'<br />BIC/Swift: '.$bicinfo.'<br />';
  147.                                             echo 'Account holder: '.$accountholder.'<br />';
  148.                                             echo '</p>';
  149.                                             echo '<p class="paymentinfo">Use this payment description: '.$EM_Booking->booking_id.' - '.$EM_Booking->person->display_name.' - '.$EM_Event->output("#_EVENTNAME").'</p>';
  150.                                         echo '</div>';
  151.                                     }
  152.                                    
  153.                                 if ( !$ibaninfo && !$paypalaccount && !$paypalmerchant ) {
  154.                                     $cashevents = array('4521');
  155.                                     if (in_array($event_post_id, $cashevents)) {
  156.                                         echo "<p><span class='fjalla'>PAYMENT INFO</span><br />This organizer has on-site cash payment only.</p>";
  157.                                     } else {
  158.                                         echo "<p>The organizer hasn't entered his payment details yet (his fault, sorry), so we can't provide them right now. Once he enters them, we will send you the email.</p>";
  159.                                     }
  160.                                 }
  161.                                        
  162.                                 } // end if status = pending/awaiting payment
  163.                                
  164.                                 echo '<div class="toon fjalla">Bookings info (click to for more info)</div>';
  165.                                 echo '<div class="verberg">';      
  166.                                     if ( !in_array($EM_Booking->booking_status, array(2,3)) ) { // if is not cancelled/rejected
  167.                                         echo '<p>Your booking ID = '.$bookingid.'</p>';
  168.                                         echo '<p>The total price of your booking is '.$EM_Booking->get_price(true).'.</p>';
  169.                                         echo '<p>You have registered the following people/info:</p>';
  170.                                         echo $EM_Booking->output("#_BOOKINGATTENDEES");
  171.                                     }
  172.                                 echo '</div>';
  173.                             ?>
  174.                         </td>
  175.                     </tr>
  176.                     <?php
  177.                         } // end foreach/event
  178.                         do_action('em_my_bookings_booking_loop',$EM_Booking);
  179.                         $event_count++;
  180.                     }
  181.                     ?>
  182.                 </tbody>
  183.             </table>
  184.             </div>
  185.             <?php else: ?>
  186.                 <?php _e('You haven\'t registered for any events (yet).', 'dbem'); ?>
  187.             <?php endif; ?>
  188.         <?php if( !empty($bookings_nav) && $bookings_count >= $limit ) : ?>
  189.         <div class='tablenav'>
  190.             <?php echo $bookings_nav; ?>
  191.             <div class="clear"></div>
  192.         </div>
  193.         <?php endif; ?>
  194.     </div>
  195.     <?php do_action('em_template_my_bookings_footer', $EM_Bookings); ?>
  196. <?php else : ?>
  197.     <p><?php echo sprintf(__('Please <a href="%s">Log In</a> to view your bookings.','dbem'),site_url('wp-login.php?redirect_to=' . urlencode(get_permalink()), 'login')); ?></p>
  198. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement