Exemplo n.º 1
0
function eme_printable_booking_report($event_id) {
   global $eme_timezone;
   $event = eme_get_event($event_id);
   $current_userid=get_current_user_id();
   if (!(current_user_can( get_option('eme_cap_edit_events')) || current_user_can( get_option('eme_cap_list_events')) ||
        (current_user_can( get_option('eme_cap_author_event')) && ($event['event_author']==$current_userid || $event['event_contactperson_id']==$current_userid)))) {
        echo "No access";
        die;
   }

   $is_multiprice = eme_is_multi($event['price']);
   $is_multiseat = eme_is_multi($event['event_seats']);
   $bookings = eme_get_bookings_for($event_id);
   $answer_columns = eme_get_answercolumns(eme_get_bookingids_for($event_id));
   $available_seats = eme_get_available_seats($event_id);
   $booked_seats = eme_get_booked_seats($event_id);
   $pending_seats = eme_get_pending_seats($event_id);
   if ($is_multiseat) {
      $available_seats_ms=eme_convert_array2multi(eme_get_available_multiseats($event_id));
      $booked_seats_ms=eme_convert_array2multi(eme_get_booked_multiseats($event_id));
      $pending_seats_ms=eme_convert_array2multi(eme_get_pending_multiseats($event_id));
   }

   $stylesheet = EME_PLUGIN_URL."events_manager.css";
   foreach($answer_columns as $col) {
      $formfield[$col["field_name"]]=eme_get_formfield_id_byname($col["field_name"]);
   }
   ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html>
      <head>
         <meta http-equiv="Content-type" content="text/html; charset=utf-8">
         <title>Bookings for <?php echo eme_trans_sanitize_html($event['event_name']);?></title>
          <link rel="stylesheet" href="<?php echo $stylesheet; ?>" type="text/css" media="screen" />
          <?php
            $file_name= get_stylesheet_directory()."/eme.css";
            if (file_exists($file_name))
               echo "<link rel='stylesheet' href='".get_stylesheet_directory_uri()."/eme.css' type='text/css' media='screen' />\n";
            $file_name= get_stylesheet_directory()."/eme_print.css";
            if (file_exists($file_name))
               echo "<link rel='stylesheet' href='".get_stylesheet_directory_uri()."/eme_print.css' type='text/css' media='print' />\n";
          ?>
      </head>
      <body id="eme_printable_body">
         <div id="eme_printable_container">
         <h1>Bookings for <?php echo eme_trans_sanitize_html($event['event_name']);?></h1> 
         <p><?php echo eme_localised_date($event['event_start_date']." ".$event['event_start_time']." ".$eme_timezone); ?></p>
         <p><?php if ($event['location_id']) echo eme_replace_placeholders("#_LOCATIONNAME, #_ADDRESS, #_TOWN", $event); ?></p>
         <?php if ($event['price']) ?>
            <p><?php _e ( 'Price: ','eme' ); echo eme_replace_placeholders("#_CURRENCY #_PRICE", $event)?></p>
         <h1><?php _e('Bookings data', 'eme');?></h1>
         <table id="eme_printable_table">
            <tr>
               <th scope='col' class='eme_print_id'><?php _e('ID', 'eme')?></th>
               <th scope='col' class='eme_print_name'><?php _e('Last Name', 'eme')?></th>
               <th scope='col' class='eme_print_name'><?php _e('First Name', 'eme')?></th>
               <th scope='col' class='eme_print_email'><?php _e('E-mail', 'eme')?></th>
               <th scope='col' class='eme_print_phone'><?php _e('Phone number', 'eme')?></th> 
               <th scope='col' class='eme_print_seats'><?php if ($is_multiprice) _e('Seats (Multiprice)', 'eme'); else _e('Seats', 'eme'); ?></th>
               <th scope='col' class='eme_print_paid'><?php _e('Paid', 'eme')?></th>
               <th scope='col' class='eme_print_booking_date'><?php _e('Booking date', 'eme')?></th>
               <th scope='col' class='eme_print_total_price'><?php _e('Total price', 'eme')?></th>
               <th scope='col' class='eme_print_unique_nbr'><?php _e('Unique nbr', 'eme')?></th>
               <th scope='col' class='eme_print_comment'><?php _e('Comment', 'eme')?></th> 
            <?php
            $nbr_columns=11;
            foreach($answer_columns as $col) {
               $class="eme_print_formfield".$formfield[$col['field_name']];
               print "<th scope='col' class='$class'>".$col['field_name']."</th>";
               $nbr_columns++;
            }
            ?>
            </tr>
            <?php
            foreach($bookings as $booking) {
               $localised_booking_date = eme_localised_date($booking['creation_date']." ".$eme_timezone);
               $localised_booking_time = eme_localised_time($booking['creation_date']." ".$eme_timezone);
               $person = eme_get_person ($booking['person_id']);
               $pending_string="";
               if (eme_event_needs_approval($event_id) && !$booking['booking_approved']) {
                  $pending_string=__('(pending)','eme');
               }
                ?>
            <tr>
               <td class='eme_print_id'><?php echo $booking['booking_id']?></td> 
               <td class='eme_print_name'><?php echo $person['lastname']?></td> 
               <td class='eme_print_name'><?php echo $person['firstname']?></td> 
               <td class='eme_print_email'><?php echo $person['email']?></td>
               <td class='eme_print_phone'><?php echo $person['phone']?></td>
               <td class='eme_print_seats' class='seats-number'><?php 
               if ($is_multiprice) {
                  // in cases where the event switched to multiprice, but somebody already registered while it was still single price: booking_seats_mp is then empty
                  if ($booking['booking_seats_mp'] == "")
                     $booking['booking_seats_mp']=$booking['booking_seats'];
                  echo $booking['booking_seats']." (".$booking['booking_seats_mp'].") ".$pending_string;
               } else {
                  echo $booking['booking_seats']." ".$pending_string;
               }
               ?>
               </td>
               <td class='eme_print_paid'><?php if ($booking['booking_payed']) _e('Yes'); else _e('No'); ?></td>
               <td class='eme_print_booking_date'><?php echo $localised_booking_date." ".$localised_booking_time; ?></td>
               <td class='eme_print_total_price'><?php echo eme_get_total_booking_price($event,$booking); ?></td>
               <td class='eme_print_unique_nbr'><?php echo $booking['transfer_nbr_be97']; ?></td>
               <td class='eme_print_comment'><?=$booking['booking_comment'] ?></td> 
               <?php
                  $answers = eme_get_answers($booking['booking_id']);
                  foreach($answer_columns as $col) {
                     $found=0;
                     foreach ($answers as $answer) {
                        $class="eme_print_formfield".$formfield[$col['field_name']];
                        if ($answer['field_name'] == $col['field_name']) {
                           print "<td class='$class'>".eme_sanitize_html(eme_convert_answer2tag($answer))."</td>";
                           $found=1;
                           break;
                        }
                     }
                     # to make sure the number of columns are correct, we add an empty answer if none was found
                     if (!$found)
                        print "<td class='$class'>&nbsp;</td>";
                  }
               ?>
            </tr>
               <?php } ?>
            <tr id='eme_printable_booked-seats'>
               <td colspan='<?php echo $nbr_columns-4;?>'>&nbsp;</td>
               <td class='total-label'><?php _e('Booked', 'eme')?>:</td>
               <td colspan='3' class='seats-number'><?php
               print $booked_seats;
               if ($is_multiseat) print " ($booked_seats_ms)";
			      if ($pending_seats>0) {
                  if ($is_multiseat)
                     print " ".sprintf( __('(%s pending)','eme'), $pending_seats . " ($pending_seats_ms)");
                  else
                     print " ".sprintf( __('(%s pending)','eme'), $pending_seats);
               }
               ?>
            </td>
            </tr>
            <tr id='eme_printable_available-seats'>
               <td colspan='<?php echo $nbr_columns-4;?>'>&nbsp;</td>
               <td class='total-label'><?php _e('Available', 'eme')?>:</td>
               <td colspan='3' class='seats-number'><?php print $available_seats; if ($is_multiseat) print " ($available_seats_ms)"; ?></td>
            </tr>
         </table>
         </div>
      </body>
      </html>
      <?php
      die();
} 
Exemplo n.º 2
0
function eme_registration_seats_form_table($pending = 0)
{
    global $plugin_page;
    $scope_names = array();
    $scope_names['past'] = __('Past events', 'eme');
    $scope_names['all'] = __('All events', 'eme');
    $scope_names['future'] = __('Future events', 'eme');
    $event_id = isset($_POST['event_id']) ? intval($_POST['event_id']) : 0;
    $scope = isset($_POST['scope']) ? $_POST['scope'] : 'future';
    if (isset($_GET['search'])) {
        $scope = "all";
        $search = "[person_id=" . intval($_GET['search']) . "]";
    }
    $all_events = eme_get_events(0, $scope);
    ?>
<div class="wrap">
<div id="icon-events" class="icon32"><br />
</div>
<h2><?php 
    _e('Add a registration for an event', 'eme');
    ?>
</h2>
<div class="wrap">
<br />
<?php 
    admin_show_warnings();
    ?>
   <form id='add-booking' name='add-booking' action="" method="post">
   <input type='hidden' name='eme_admin_action' value='newRegistration' />
   <table class="widefat">
   <tbody>
            <tr><th scope='row'><?php 
    _e('Event', 'eme');
    ?>
:</th><td>
   <select name="event_id">
   <?php 
    foreach ($all_events as $event) {
        if ($event['event_rsvp']) {
            $option_text = $event['event_name'] . " (" . eme_localised_date($event['event_start_date']) . ")";
            echo "<option value='" . $event['event_id'] . "' >" . $option_text . "</option>  ";
        }
    }
    ?>
   </select>
                </td>
            </tr>
   </tbody>
   </table>
   <input type="submit" class="button-primary action" value="<?php 
    _e('Register new booking', 'eme');
    ?>
" />
   </form>
<br />
</div>
<div class="clear"></div>
<h2><?php 
    if ($pending) {
        _e('Pending Approvals', 'eme');
    } else {
        _e('Change reserved spaces or cancel registrations', 'eme');
    }
    ?>
</h2>
<div class="wrap">
<br />

   <div class="tablenav">
   <div class="alignleft">
   <form id="eme-admin-regsearchform" name="eme-admin-regsearchform" action="<?php 
    echo admin_url("admin.php?page={$plugin_page}");
    ?>
" method="post">

   <select name="scope">
   <?php 
    foreach ($scope_names as $key => $value) {
        $selected = "";
        if ($key == $scope) {
            $selected = "selected='selected'";
        }
        echo "<option value='{$key}' {$selected}>{$value}</option>  ";
    }
    ?>
   </select>

   <select name="event_id">
   <option value='0'><?php 
    _e('All events');
    ?>
</option>
   <?php 
    $events_with_bookings = array();
    foreach ($all_events as $event) {
        $selected = "";
        if ($event_id && $event['event_id'] == $event_id) {
            $selected = "selected='selected'";
        }
        if ($pending && eme_get_pending_bookings($event['event_id']) > 0) {
            $events_with_bookings[] = $event['event_id'];
            echo "<option value='" . $event['event_id'] . "' {$selected}>" . $event['event_name'] . "</option>  ";
        } elseif (eme_get_approved_seats($event['event_id']) > 0) {
            $events_with_bookings[] = $event['event_id'];
            echo "<option value='" . $event['event_id'] . "' {$selected}>" . $event['event_name'] . "</option>  ";
        }
    }
    ?>
   </select>

   <input class="button-secondary" type="submit" value="<?php 
    _e('Filter');
    ?>
" />
   </form>
   </div>
   <br />
   <br />
   <form id="eme-admin-regform" name="eme-admin-regform" action="" method="post">
   <select name="eme_admin_action">
   <option value="-1" selected="selected"><?php 
    _e('Bulk Actions');
    ?>
</option>
<?php 
    if ($pending) {
        ?>
   <option value="approveRegistration"><?php 
        _e('Approve registration', 'eme');
        ?>
</option>
<?php 
    }
    ?>
   <option value="updatePayedStatus"><?php 
    _e('Update payed status', 'eme');
    ?>
</option>
   <option value="denyRegistration"><?php 
    _e('Deny registration', 'eme');
    ?>
</option>
   </select>
   <input type="submit" class="button-secondary" value="<?php 
    _e('Apply');
    ?>
" />

   <div class="clear"><p>
   <?php 
    _e('Send mails to attendees upon changes being made?', 'eme');
    echo eme_ui_select_binary(1, "send_mail");
    ?>
   </p></div>
<?php 
    if ($pending) {
        $booking_status = 1;
        // different table id for pending bookings, so the save-state from datatables doesn't interfere with the one from non-pending
        $table_id = "eme_pending_admin_bookings";
    } else {
        $booking_status = 2;
        $table_id = "eme_admin_bookings";
    }
    if ($event_id) {
        $bookings = eme_get_bookings_for($event_id, $booking_status);
    } else {
        $bookings = eme_get_bookings_for($events_with_bookings, $booking_status);
    }
    if (!empty($bookings)) {
        ?>
   <table class="widefat hover stripe" id="<?php 
        print "{$table_id}";
        ?>
">
   <thead>
      <tr>
         <th class='manage-column column-cb check-column' scope='col'><input
            class='select-all' type="checkbox" value='1' /></th>
         <th>hidden for person id search</th>
         <th><?php 
        _e('ID', 'eme');
        ?>
</th>
         <th><?php 
        _e('Name', 'eme');
        ?>
</th>
         <th><?php 
        _e('Date and time', 'eme');
        ?>
</th>
         <th><?php 
        _e('Booker', 'eme');
        ?>
</th>
         <th><?php 
        _e('Booking date', 'eme');
        ?>
</th>
         <th><?php 
        _e('Seats', 'eme');
        ?>
</th>
         <th><?php 
        _e('Event price', 'eme');
        ?>
</th>
         <th><?php 
        _e('Total price', 'eme');
        ?>
</th>
         <th><?php 
        _e('Unique nbr', 'eme');
        ?>
</th>
         <th><?php 
        _e('Paid', 'eme');
        ?>
</th>
      </tr>
   </thead>
   <tbody>
     <?php 
        $search_dest = admin_url("admin.php?page=eme-people");
        foreach ($bookings as $event_booking) {
            $person = eme_get_person($event_booking['person_id']);
            $search_url = add_query_arg(array('search' => $person['person_id']), $search_dest);
            $event = eme_get_event($event_booking['event_id']);
            $payment_id = eme_get_booking_payment_id($event_booking['booking_id']);
            $localised_start_date = eme_localised_date($event['event_start_date']);
            $localised_start_time = eme_localised_time($event['event_start_time']);
            $localised_end_date = eme_localised_date($event['event_end_date']);
            $localised_end_time = eme_localised_time($event['event_end_time']);
            $localised_booking_date = eme_localised_date($event_booking['creation_date']);
            $localised_booking_time = eme_localised_time($event_booking['creation_date']);
            $startstring = strtotime($event['event_start_date'] . " " . $event['event_start_time']);
            $bookingtimestamp = strtotime($event_booking['creation_date']);
            $style = "";
            $today = date("Y-m-d");
            if ($event['event_start_date'] < $today) {
                $style = "style ='background-color: #FADDB7;'";
            }
            ?>
      <tr <?php 
            echo "{$style}";
            ?>
>
         <td><input type='checkbox' class='row-selector' value='<?php 
            echo $event_booking['booking_id'];
            ?>
' name='selected_bookings[]' />
             <input type='hidden' class='row-selector' value='<?php 
            echo $event_booking['booking_id'];
            ?>
' name='bookings[]' /></td>
          <td>[person_id=<?php 
            echo $person['person_id'];
            ?>
]</td>
         <td><a class="row-title" href="<?php 
            echo admin_url("admin.php?page={$plugin_page}&amp;eme_admin_action=editRegistration&amp;booking_id=" . $event_booking['booking_id']);
            ?>
" title="<?php 
            _e('Click the booking ID in order to see and/or edit the details of the booking.', 'eme');
            ?>
"><?php 
            echo $event_booking['booking_id'];
            ?>
</a>
         <td><strong>
         <a class="row-title" href="<?php 
            echo admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_event&amp;event_id=" . $event_booking['event_id']);
            ?>
" title="<?php 
            _e('Click the event name in order to see and/or edit the details of the event.', 'eme');
            ?>
"><?php 
            echo eme_trans_sanitize_html($event['event_name']);
            ?>
</a>
         </strong>
         <?php 
            $approved_seats = eme_get_approved_seats($event['event_id']);
            $pending_seats = eme_get_pending_seats($event['event_id']);
            $total_seats = $event['event_seats'];
            echo "<br />" . __('Approved: ', 'eme') . $approved_seats . ", " . __('Pending: ', 'eme') . $pending_seats . ", " . __('Max: ', 'eme') . $total_seats;
            if ($approved_seats > 0) {
                $printable_address = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_printable&amp;event_id=" . $event['event_id']);
                $csv_address = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_csv&amp;event_id=" . $event['event_id']);
                echo " (<a id='booking_printable_" . $event['event_id'] . "'  target='' href='{$printable_address}'>" . __('Printable view', 'eme') . "</a>)";
                echo " (<a id='booking_csv_" . $event['event_id'] . "'  target='' href='{$csv_address}'>" . __('CSV export', 'eme') . "</a>)";
            }
            ?>
         </td>
         <td data-sort="<?php 
            echo $startstring;
            ?>
">
            <?php 
            echo $localised_start_date;
            if ($localised_end_date != '' && $localised_end_date != $localised_start_date) {
                echo " - " . $localised_end_date;
            }
            ?>
<br />
            <?php 
            echo "{$localised_start_time} - {$localised_end_time}";
            ?>
         </td>
         <td><a href="<?php 
            echo $search_url;
            ?>
" title="<?php 
            _e('Click the name of the booker in order to see and/or edit the details of the booker.', 'eme');
            ?>
"><?php 
            echo eme_sanitize_html($person['lastname']) . "(" . eme_sanitize_html($person['phone']) . ", " . eme_sanitize_html($person['email']) . ")";
            ?>
</a>
         </td>
         <td data-sort="<?php 
            echo $bookingtimestamp;
            ?>
">
            <?php 
            echo $localised_booking_date . " " . $localised_booking_time;
            ?>
         </td>
         <?php 
            if (eme_is_multi(eme_get_booking_price($event, $event_booking))) {
                ?>
         <td>
            <?php 
                echo $event_booking['booking_seats_mp'] . '<br />' . __('(Multiprice)', 'eme');
                ?>
         </td>
         <?php 
            } else {
                ?>
         <td>
            <?php 
                echo $event_booking['booking_seats'];
                ?>
         </td>
         <?php 
            }
            ?>
         <td>
            <?php 
            echo eme_get_booking_price($event, $event_booking);
            ?>
         </td>
         <td>
            <?php 
            echo eme_get_total_booking_price($event, $event_booking);
            ?>
         </td>
         <td>
            <span title="<?php 
            print sprintf(__('This is based on the payment ID of the booking: %d', 'eme'), $payment_id);
            ?>
"><?php 
            echo eme_sanitize_html($event_booking['transfer_nbr_be97']);
            ?>
</span>
         </td>
         <td>
            <?php 
            echo eme_ui_select_binary($event_booking['booking_payed'], "bookings_payed[]");
            ?>
         </td>
      </tr>
      <?php 
        }
        ?>
   </tbody>
   </table>

<script type="text/javascript">
   jQuery(document).ready( function() {
         jQuery('#<?php 
        print "{$table_id}";
        ?>
').dataTable( {
            "dom": 'CT<"clear">Rlfrtip',
            <?php 
        // jquery datatables locale loading
        $locale_code = get_locale();
        $locale_file = EME_PLUGIN_DIR . "js/jquery-datatables/i18n/{$locale_code}.json";
        $locale_file_url = EME_PLUGIN_URL . "js/jquery-datatables/i18n/{$locale_code}.json";
        if ($locale_code != "en_US" && file_exists($locale_file)) {
            ?>
            "language": {
               "url": "<?php 
            echo $locale_file_url;
            ?>
"
               },
            <?php 
        }
        ?>
 
            "stateSave": true,
            <?php 
        if (!empty($search)) {
            // If datatables state is saved, the initial search
            // is ignored and we need to use stateloadparams
            // So we give the 2 options
            ?>
 
            "stateLoadParams": function (settings, data) {
               data.search.search = "<?php 
            echo $search;
            ?>
";
            },
            "search": {
               "search":  "<?php 
            echo $search;
            ?>
"
            },
            <?php 
        }
        ?>
 
            "pagingType": "full",
            "columnDefs": [
               { "sortable": false, "targets": 0 },
               { "visible": false, "targets": 1 }
            ],
            "colVis": {
               "exclude": [0,1]
            },
            "tableTools": {
               "aButtons": [ { "sExtends": "csv", "mColumns": "visible"},
                             "print"
                           ],
               "sSwfPath": "<?php 
        echo EME_PLUGIN_URL;
        ?>
js/jquery-datatables/extensions/TableTools-2.2.4-dev/swf/copy_csv_xls.swf"
            }
         } );
   } );
</script>

<?php 
    }
    ?>

   <div class='tablenav'>
   <div class="alignleft actions"><br class='clear' />
   </div>
   <br class='clear' />
   </div>

   </div>
   </form>
</div>
</div>
<?php 
}
Exemplo n.º 3
0
function eme_replace_placeholders($format, $event, $target = "html", $do_shortcode = 1, $lang = '')
{
    global $eme_need_gmap_js, $eme_timezone;
    // an initial filter for the format, in case people want to change anything before the placeholders get replaced
    if (has_filter('eme_events_format_prefilter')) {
        $format = apply_filters('eme_events_format_prefilter', $format, $event);
    }
    // some variables we'll use further down more than once
    $current_userid = get_current_user_id();
    $person_id = eme_get_person_id_by_wp_id($current_userid);
    $eme_enable_notes_placeholders = get_option('eme_enable_notes_placeholders');
    if (isset($event['location_id']) && $event['location_id']) {
        $location = eme_get_location($event['location_id']);
    } else {
        $location = eme_new_location();
    }
    // first replace the notes sections, since these can contain other placeholders
    if ($eme_enable_notes_placeholders) {
        $format = eme_replace_notes_placeholders($format, $event, $target);
    }
    // then we do the custom attributes, since these can contain other placeholders
    preg_match_all("/#(ESC|URL)?_ATT\\{.+?\\}(\\{.+?\\})?/", $format, $results);
    foreach ($results[0] as $resultKey => $result) {
        $need_escape = 0;
        $need_urlencode = 0;
        $orig_result = $result;
        if (strstr($result, '#ESC')) {
            $result = str_replace("#ESC", "#", $result);
            $need_escape = 1;
        } elseif (strstr($result, '#URL')) {
            $result = str_replace("#URL", "#", $result);
            $need_urlencode = 1;
        }
        $replacement = "";
        //Strip string of placeholder and just leave the reference
        $attRef = substr(substr($result, 0, strpos($result, '}')), 6);
        if (isset($event['event_attributes'][$attRef])) {
            $replacement = $event['event_attributes'][$attRef];
        }
        if (trim($replacement) == '' && isset($results[2][$resultKey]) && $results[2][$resultKey] != '') {
            //Check to see if we have a second set of braces;
            $replacement = substr($results[2][$resultKey], 1, strlen(trim($results[2][$resultKey])) - 2);
        }
        if ($need_escape) {
            $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement)));
        }
        if ($need_urlencode) {
            $replacement = rawurlencode($replacement);
        }
        $format = str_replace($orig_result, $replacement, $format);
    }
    // and now all the other placeholders
    $legacy = get_option('eme_legacy');
    $deprecated = get_option('eme_deprecated');
    if ($legacy) {
        preg_match_all("/#(ESC|URL)?@?_?[A-Za-z0-9_]+(\\[.*\\])?(\\[.*\\])?/", $format, $placeholders);
    } else {
        preg_match_all("/#(ESC|URL)?@?_?[A-Za-z0-9_]+(\\{.*?\\})?(\\{.*?\\})?/", $format, $placeholders);
    }
    // make sure we set the largest matched placeholders first, otherwise if you found e.g.
    // #_LOCATION, part of #_LOCATIONPAGEURL would get replaced as well ...
    usort($placeholders[0], 'sort_stringlenth');
    // if the add and remove booking form appear on the same page, we need to decide which form shows the "message" upon booking
    // the first one wins
    $a1 = strpos($format, "ADDBOOKINGFORM");
    $a2 = strpos($format, "REMOVEBOOKINGFORM");
    $show_message_on_add = 1;
    $show_message_on_remove = 1;
    if ($a1 !== false && $a2 !== false) {
        if ($a1 < $a2) {
            $show_message_on_remove = 0;
        } else {
            $show_message_on_add = 0;
        }
    }
    $eme_date_obj_now = new ExpressiveDate(null, $eme_timezone);
    foreach ($placeholders[0] as $result) {
        $need_escape = 0;
        $need_urlencode = 0;
        $orig_result = $result;
        $found = 1;
        if (strstr($result, '#ESC')) {
            $result = str_replace("#ESC", "#", $result);
            $need_escape = 1;
        } elseif (strstr($result, '#URL')) {
            $result = str_replace("#URL", "#", $result);
            $need_urlencode = 1;
        }
        $replacement = "";
        // matches all fields placeholder
        if ($event && preg_match('/#_EDITEVENTLINK/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = "<a href=' " . admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_event&amp;event_id=" . $event['event_id']) . "'>" . __('Edit') . "</a>";
            }
        } elseif ($event && preg_match('/#_EDITEVENTURL/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_event&amp;event_id=" . $event['event_id']);
            }
        } elseif ($event && preg_match('/#_EVENTPRINTBOOKINGSLINK/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = "<a href=' " . admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_printable&amp;event_id=" . $event['event_id']) . "'>" . __('Printable view of bookings', 'eme') . "</a>";
            }
        } elseif ($event && preg_match('/#_EVENTPRINTBOOKINGSURL/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_printable&amp;event_id=" . $event['event_id']);
            }
        } elseif ($event && preg_match('/#_EVENTCSVBOOKINGSLINK/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = "<a href=' " . admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_csv&amp;event_id=" . $event['event_id']) . "'>" . __('Printable view of bookings', 'eme') . "</a>";
            }
        } elseif ($event && preg_match('/#_EVENTCSVBOOKINGSURL/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_csv&amp;event_id=" . $event['event_id']);
            }
        } elseif ($event && preg_match('/#_STARTDATE/', $result)) {
            $replacement = eme_localised_date($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_STARTTIME/', $result)) {
            $replacement = eme_localised_time($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_ENDDATE/', $result)) {
            $replacement = eme_localised_date($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_ENDTIME/', $result)) {
            $replacement = eme_localised_time($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_24HSTARTTIME/', $result)) {
            $replacement = substr($event['event_start_time'], 0, 5);
        } elseif ($event && preg_match('/#_24HENDTIME$/', $result)) {
            $replacement = substr($event['event_end_time'], 0, 5);
        } elseif ($event && preg_match('/#_PAST_FUTURE_CLASS/', $result)) {
            $eme_start_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $eme_end_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            if ($eme_start_obj->greaterThan($eme_date_obj_now)) {
                $replacement = "eme-future-event";
            } elseif ($eme_start_obj->lessOrEqualTo($eme_date_obj_now) && $eme_end_obj->greaterOrEqualTo($eme_date_obj_now)) {
                $replacement = "eme-ongoing-event";
            } else {
                $replacement = "eme-past-event";
            }
        } elseif ($event && preg_match('/#_12HSTARTTIME$/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone)->format('h:i A');
        } elseif ($event && preg_match('/#_12HENDTIME$/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone)->format('h:i A');
        } elseif ($event && preg_match('/#_12HSTARTTIME_NOLEADINGZERO/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone)->format('g:i A');
            if (get_option('eme_time_remove_leading_zeros')) {
                $replacement = str_replace(":00", "", $replacement);
                $replacement = str_replace(":0", ":", $replacement);
            }
        } elseif ($event && preg_match('/#_12HENDTIME_NOLEADINGZERO/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone)->format('g:i A');
            if (get_option('eme_time_remove_leading_zeros')) {
                $replacement = str_replace(":00", "", $replacement);
                $replacement = str_replace(":0", ":", $replacement);
            }
        } elseif ($event && preg_match('/#_MAP/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } elseif (isset($event['location_id']) && $event['location_id']) {
                $replacement = eme_single_location_map($location);
            }
        } elseif ($event && preg_match('/#_DIRECTIONS/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } elseif (isset($event['location_id']) && $event['location_id']) {
                $replacement = eme_add_directions_form($location);
            }
        } elseif ($event && preg_match('/#_EVENTS_FILTERFORM/', $result)) {
            if ($target == "rss" || $target == "text" || eme_is_single_event_page()) {
                $replacement = "";
            } else {
                $replacement = eme_filter_form();
            }
        } elseif ($event && preg_match('/#_ADDBOOKINGFORM$/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } else {
                $replacement = eme_add_booking_form($event['event_id'], $show_message_on_add);
            }
        } elseif ($event && preg_match('/#_ADDBOOKINGFORM_IF_NOT_REGISTERED/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } else {
                $not_registered_only = 1;
                $replacement = eme_add_booking_form($event['event_id'], $show_message_on_add, $not_registered_only);
            }
        } elseif ($event && preg_match('/#_REMOVEBOOKINGFORM$/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } else {
                // when the booking just happened and the user needs to pay, we don't show the remove booking form
                if ($booking_id_done && eme_event_can_pay_online($event)) {
                    $replacement = "";
                } else {
                    $replacement = eme_delete_booking_form($event['event_id'], $show_message_on_remove);
                }
            }
        } elseif ($event && preg_match('/#_REMOVEBOOKINGFORM_IF_REGISTERED/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } elseif (is_user_logged_in()) {
                // when the booking just happened and the user needs to pay, we don't show the remove booking form
                if ($booking_id_done && eme_event_can_pay_online($event)) {
                    $replacement = "";
                } elseif (eme_get_booking_ids_by_wp_id($current_userid, $event['event_id'])) {
                    $replacement = eme_delete_booking_form($event['event_id'], $show_message_on_remove);
                }
            }
        } elseif ($event && preg_match('/#_(AVAILABLESPACES|AVAILABLESEATS)$/', $result)) {
            $replacement = eme_get_available_seats($event['event_id']);
        } elseif ($deprecated && preg_match('/#_(AVAILABLESPACES|AVAILABLESEATS)(\\d+)/', $result, $matches) || preg_match('/#_(AVAILABLESPACES|AVAILABLESEATS)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]) - 1;
            if (eme_is_multi($event['event_seats'])) {
                $seats = eme_get_available_multiseats($event['event_id']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif ($event && preg_match('/#_(TOTALSPACES|TOTALSEATS)$/', $result)) {
            $replacement = $event['event_seats'];
        } elseif ($deprecated && preg_match('/#_(TOTALSPACES|TOTALSEATS)(\\d+)/', $result, $matches) || preg_match('/#_(TOTALSPACES|TOTALSEATS)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]) - 1;
            $replacement = 0;
            if (eme_is_multi($event['event_seats'])) {
                $seats = eme_convert_multi2array($event['event_seats']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif ($event && preg_match('/#_(RESERVEDSPACES|BOOKEDSEATS)$/', $result)) {
            $replacement = eme_get_booked_seats($event['event_id']);
        } elseif ($deprecated && preg_match('/#_(RESERVEDSPACES|BOOKEDSEATS)(\\d+)/', $result, $matches) || preg_match('/#_(RESERVEDSPACES|BOOKEDSEATS)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]) - 1;
            $replacement = 0;
            if (eme_is_multi($event['event_seats'])) {
                $seats = eme_get_booked_multiseats($event['event_id']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif ($event && preg_match('/#_(PENDINGSPACES|PENDINGSEATS)$/', $result)) {
            $replacement = eme_get_pending_seats($event['event_id']);
        } elseif ($event && preg_match('/#_(PENDINGSPACES|PENDINGSEATS)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]) - 1;
            $replacement = 0;
            if (eme_is_multi($event['event_seats'])) {
                $seats = eme_get_pending_multiseats($event['event_id']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif ($event && preg_match('/#_(APPROVEDSPACES|APPROVEDSEATS)$/', $result)) {
            $replacement = eme_get_approved_seats($event['event_id']);
        } elseif ($event && preg_match('/#_(APPROVEDSPACES|APPROVEDSEATS)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]) - 1;
            $replacement = 0;
            if (eme_is_multi($event['event_seats'])) {
                $seats = eme_get_approved_multiseats($event['event_id']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif ($event && preg_match('/#_USER_(RESERVEDSPACES|BOOKEDSEATS)$/', $result)) {
            if (is_user_logged_in()) {
                $replacement = eme_get_booked_seats_by_wp_event_id($current_userid, $event['event_id']);
            }
        } elseif ($event && preg_match('/#_LINKEDNAME/', $result)) {
            $event_link = eme_event_url($event, $lang);
            if ($target == "html") {
                $replacement = "<a href='{$event_link}' title='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'>" . eme_trans_sanitize_html($event['event_name'], $lang) . "</a>";
            } else {
                $replacement = eme_translate($event['event_name'], $lang);
            }
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_ICALLINK/', $result)) {
            $url = site_url("/?eme_ical=public_single&amp;event_id=" . $event['event_id']);
            $replacement = "<a href='{$url}'>ICAL</a>";
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_ICALURL/', $result)) {
            $replacement = site_url("/?eme_ical=public_single&amp;event_id=" . $event['event_id']);
        } elseif ($event && preg_match('/#_EVENTIMAGE$/', $result)) {
            if (!empty($event['event_image_id'])) {
                $event['event_image_url'] = wp_get_attachment_url($event['event_image_id']);
            }
            if ($event['event_image_url'] != '') {
                $replacement = "<img src='" . $event['event_image_url'] . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>";
                if ($target == "html") {
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_EVENTIMAGEURL$/', $result)) {
            if (!empty($event['event_image_id'])) {
                $event['event_image_url'] = wp_get_attachment_url($event['event_image_id']);
            }
            if ($event['event_image_url'] != '') {
                $replacement = $event['event_image_url'];
            }
        } elseif ($event && preg_match('/#_EVENTIMAGETHUMB$/', $result)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], get_option('eme_thumbnail_size'));
                $thumb_url = $thumb_array[0];
                $thumb_width = $thumb_array[1];
                $thumb_height = $thumb_array[2];
                $replacement = "<img width='{$thumb_width}' height='{$thumb_height}' src='" . $thumb_url . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>";
                if ($target == "html") {
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_EVENTIMAGETHUMBURL$/', $result)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], get_option('eme_thumbnail_size'));
                $thumb_url = $thumb_array[0];
                $replacement = $thumb_url;
            }
        } elseif ($event && preg_match('/#_EVENTIMAGETHUMB\\{(.+)\\}/', $result, $matches)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], $matches[1]);
                $thumb_url = $thumb_array[0];
                $thumb_width = $thumb_array[1];
                $thumb_height = $thumb_array[2];
                $replacement = "<img width='{$thumb_width}' height='{$thumb_height}' src='" . $thumb_url . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>";
                if ($target == "html") {
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($legacy && $event && preg_match('/#_EVENTIMAGETHUMB\\[(.+)\\]/', $result, $matches)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], $matches[1]);
                $thumb_url = $thumb_array[0];
                $thumb_width = $thumb_array[1];
                $thumb_height = $thumb_array[2];
                $replacement = "<img width='{$thumb_width}' height='{$thumb_height}' src='" . $thumb_url . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>";
                if ($target == "html") {
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_EVENTIMAGETHUMBURL\\{(.+)\\}/', $result, $matches)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], $matches[1]);
                $thumb_url = $thumb_array[0];
                $replacement = $thumb_url;
            }
        } elseif ($legacy && $event && preg_match('/#_EVENTIMAGETHUMBURL\\[(.+)\\]/', $result, $matches)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], $matches[1]);
                $thumb_url = $thumb_array[0];
                $replacement = $thumb_url;
            }
        } elseif ($event && preg_match('/#_EVENTATT\\{(.+)\\}\\{(.+)\\}/', $result, $matches)) {
            $tmp_event_id = intval($matches[1]);
            $tmp_event_attkey = $matches[2];
            $tmp_event = eme_get_event($tmp_event_id);
            if (isset($tmp_event['event_attributes'][$tmp_event_attkey])) {
                $replacement = $tmp_event['event_attributes'][$tmp_event_attkey];
            }
        } elseif ($event && preg_match('/#_MYLOCATIONATT\\{(.+)\\}/', $result, $matches)) {
            $tmp_attkey = $matches[1];
            if (isset($location['location_attributes'][$tmp_attkey])) {
                $replacement = $location['location_attributes'][$tmp_attkey];
            }
        } elseif ($event && preg_match('/#_EVENTPAGEURL\\{(.+)\\}/', $result, $matches)) {
            $events_page_link = eme_get_events_page(true, false);
            $replacement = add_query_arg(array('event_id' => intval($matches[1])), $events_page_link);
            if (!empty($lang)) {
                $replacement = add_query_arg(array('lang' => $lang), $replacement);
            }
        } elseif ($legacy && $event && preg_match('/#_EVENTPAGEURL\\[(.+)\\]/', $result, $matches)) {
            $events_page_link = eme_get_events_page(true, false);
            $replacement = add_query_arg(array('event_id' => intval($matches[1])), $events_page_link);
            if (!empty($lang)) {
                $replacement = add_query_arg(array('lang' => $lang), $replacement);
            }
        } elseif ($event && preg_match('/#_EVENTPAGEURL$/', $result)) {
            $replacement = eme_event_url($event, $lang);
        } elseif ($event && preg_match('/#_(NAME|EVENTNAME)$/', $result)) {
            $field = "event_name";
            if (isset($event[$field])) {
                $replacement = $event[$field];
            }
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html($replacement, $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate($replacement, $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate($replacement, $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_EVENTID/', $result)) {
            $field = "event_id";
            $replacement = intval($event[$field]);
        } elseif ($event && preg_match('/#_SINGLE_EVENTPAGE_EVENTID/', $result)) {
            // returns the event id of the single event page currently shown
            if (eme_is_single_event_page()) {
                $replacement = intval(get_query_var('event_id'));
            }
        } elseif ($event && preg_match('/#_DAYS_TILL_START/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $replacement = $eme_date_obj_now->getDifferenceInDays($eme_date_obj);
        } elseif ($event && preg_match('/#_DAYS_TILL_END/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            $replacement = $eme_date_obj_now->getDifferenceInDays($eme_date_obj);
        } elseif ($event && preg_match('/#_HOURS_TILL_START/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $replacement = round($eme_date_obj_now->getDifferenceInHours($eme_date_obj));
        } elseif ($event && preg_match('/#_HOURS_TILL_END/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            $replacement = round($eme_date_obj_now->getDifferenceInHours($eme_date_obj));
        } elseif ($event && preg_match('/#_EVENTPRICE$|#_PRICE$/', $result)) {
            $field = "price";
            if ($event[$field]) {
                $replacement = $event[$field];
            }
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($deprecated && $event && preg_match('/#_(EVENT)?PRICE(\\d+)/', $result, $matches) || $event && preg_match('/#_(EVENT)?PRICE\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2] - 1);
            if ($event["price"] && eme_is_multi($event["price"])) {
                $prices = eme_convert_multi2array($event["price"]);
                if (is_array($prices) && array_key_exists($field_id, $prices)) {
                    $replacement = $prices[$field_id];
                    if ($target == "html") {
                        $replacement = apply_filters('eme_general', $replacement);
                    } elseif ($target == "rss") {
                        $replacement = apply_filters('eme_general_rss', $replacement);
                    } else {
                        $replacement = apply_filters('eme_text', $replacement);
                    }
                }
            }
        } elseif ($event && preg_match('/#_CURRENCY/', $result)) {
            $field = "currency";
            // currency is only important if the price is not empty as well
            if ($event['price']) {
                $replacement = $event[$field];
            }
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_ATTENDEES/', $result)) {
            $replacement = eme_get_attendees_list_for($event);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_BOOKINGS/', $result)) {
            $replacement = eme_get_bookings_list_for_event($event);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_(CONTACTNAME|CONTACTPERSON)/', $result)) {
            $contact = eme_get_contact($event);
            if ($contact) {
                $replacement = $contact->display_name;
            }
            $replacement = eme_trans_sanitize_html($replacement, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_(CONTACTEMAIL|PLAIN_CONTACTEMAIL)/', $result)) {
            $contact = eme_get_contact($event);
            if ($contact) {
                $replacement = $contact->user_email;
                if ($target == "html") {
                    // ascii encode for primitive harvesting protection ...
                    $replacement = eme_ascii_encode($replacement);
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_CONTACTPHONE/', $result)) {
            $contact = eme_get_contact($event);
            if ($contact) {
                $phone = eme_get_user_phone($contact->ID);
                // ascii encode for primitive harvesting protection ...
                $replacement = eme_ascii_encode($phone);
            }
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_AUTHORNAME/', $result)) {
            $author = eme_get_author($event);
            if ($author) {
                $replacement = $author->display_name;
            }
            $replacement = eme_trans_sanitize_html($replacement, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_AUTHOREMAIL/', $result)) {
            $author = eme_get_author($event);
            if ($author) {
                $replacement = $author->user_email;
                if ($target == "html") {
                    // ascii encode for primitive harvesting protection ...
                    $replacement = eme_ascii_encode($replacement);
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_AUTHORPHONE/', $result)) {
            $author = eme_get_author($event);
            if ($author) {
                $phone = eme_get_user_phone($author->ID);
                // ascii encode for primitive harvesting protection ...
                $replacement = eme_ascii_encode($phone);
            }
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif (preg_match('/#_EVENTCREATIONDATE/', $result)) {
            $replacement = eme_localised_date($event['creation_date'] . " " . $eme_timezone);
        } elseif (preg_match('/#_EVENTMODIFDATE/', $result)) {
            $replacement = eme_localised_date($event['modif_date'] . " " . $eme_timezone);
        } elseif (preg_match('/#_EVENTCREATIONTIME/', $result)) {
            $replacement = eme_localised_time($event['creation_date'] . " " . $eme_timezone);
        } elseif (preg_match('/#_EVENTMODIFTIME/', $result)) {
            $replacement = eme_localised_time($event['modif_date'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#[A-Za-z]$/', $result)) {
            // matches all PHP date placeholders for startdate-time
            $replacement = eme_localised_date($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone, ltrim($result, "#"));
            if (get_option('eme_time_remove_leading_zeros') && $result == "#i") {
                $replacement = ltrim($replacement, "0");
            }
        } elseif ($event && preg_match('/#@[A-Za-z]$/', $result)) {
            // matches all PHP time placeholders for enddate-time
            $replacement = eme_localised_date($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone, ltrim($result, "#@"));
            if (get_option('eme_time_remove_leading_zeros') && $result == "#@i") {
                $replacement = ltrim($replacement, "0");
            }
        } elseif ($event && preg_match('/#_EVENTCATEGORYIDS$/', $result) && get_option('eme_categories_enabled')) {
            $categories = $event['event_category_ids'];
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html($categories, $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_trans_sanitize_html($categories, $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_trans_sanitize_html($categories, $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_(EVENT)?CATEGORIES$/', $result) && get_option('eme_categories_enabled')) {
            $categories = eme_get_event_category_names($event['event_id']);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_EVENTCATEGORIES_CSS$/', $result) && get_option('eme_categories_enabled')) {
            $categories = eme_get_event_category_names($event['event_id']);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_EVENTCATEGORYDESCRIPTIONS$/', $result) && get_option('eme_categories_enabled')) {
            $categories = eme_get_event_category_descriptions($event['event_id']);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_LINKED(EVENT)?CATEGORIES$/', $result) && get_option('eme_categories_enabled')) {
            $categories = eme_get_event_categories($event['event_id']);
            $cat_links = array();
            foreach ($categories as $category) {
                $cat_link = eme_category_url($category);
                $cat_name = $category['category_name'];
                if ($target == "html") {
                    array_push($cat_links, "<a href='{$cat_link}' title='" . eme_trans_sanitize_html($cat_name, $lang) . "'>" . eme_trans_sanitize_html($cat_name, $lang) . "</a>");
                } else {
                    array_push($cat_links, eme_translate($cat_name, $lang));
                }
            }
            $replacement = join(", ", $cat_links);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/^#_(EVENT)?CATEGORIES\\{(.*?)\\}\\{(.*?)\\}/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[2];
            $exclude_cats = $matches[3];
            $extra_conditions_arr = array();
            if (!empty($include_cats)) {
                array_push($extra_conditions_arr, "category_id IN ({$include_cats})");
            }
            if (!empty($exclude_cats)) {
                array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})");
            }
            $extra_conditions = join(" AND ", $extra_conditions_arr);
            $categories = eme_get_event_category_names($event['event_id'], $extra_conditions);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/^#_EVENTCATEGORIES_CSS\\{(.*?)\\}\\{(.*?)\\}/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[1];
            $exclude_cats = $matches[2];
            $extra_conditions_arr = array();
            if (!empty($include_cats)) {
                array_push($extra_conditions_arr, "category_id IN ({$include_cats})");
            }
            if (!empty($exclude_cats)) {
                array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})");
            }
            $extra_conditions = join(" AND ", $extra_conditions_arr);
            $categories = eme_get_event_category_names($event['event_id'], $extra_conditions);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($legacy && $event && preg_match('/^#_(EVENT)?CATEGORIES\\[(.*?)\\]\\[(.*?)\\]/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[2];
            $exclude_cats = $matches[3];
            $extra_conditions_arr = array();
            if (!empty($include_cats)) {
                array_push($extra_conditions_arr, "category_id IN ({$include_cats})");
            }
            if (!empty($exclude_cats)) {
                array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})");
            }
            $extra_conditions = join(" AND ", $extra_conditions_arr);
            $categories = eme_get_event_category_names($event['event_id'], $extra_conditions);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_LINKED(EVENT)?CATEGORIES\\{(.*?)\\}\\{(.*?)\\}/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[2];
            $exclude_cats = $matches[3];
            $extra_conditions_arr = array();
            if (!empty($include_cats)) {
                array_push($extra_conditions_arr, "category_id IN ({$include_cats})");
            }
            if (!empty($exclude_cats)) {
                array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})");
            }
            $extra_conditions = join(" AND ", $extra_conditions_arr);
            $categories = eme_get_event_categories($event['event_id'], $extra_conditions);
            $cat_links = array();
            foreach ($categories as $category) {
                $cat_link = eme_category_url($category);
                $cat_name = $category['category_name'];
                if ($target == "html") {
                    array_push($cat_links, "<a href='{$cat_link}' title='" . eme_trans_sanitize_html($cat_name, $lang) . "'>" . eme_trans_sanitize_html($cat_name, $lang) . "</a>");
                } else {
                    array_push($cat_links, eme_translate($cat_name, $lang));
                }
            }
            $replacement = join(", ", $cat_links);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($legacy && $event && preg_match('/#_LINKED(EVENT)?CATEGORIES\\[(.*?)\\]\\[(.*?)\\]/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[2];
            $exclude_cats = $matches[3];
            $extra_conditions_arr = array();
            if (!empty($include_cats)) {
                array_push($extra_conditions_arr, "category_id IN ({$include_cats})");
            }
            if (!empty($exclude_cats)) {
                array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})");
            }
            $extra_conditions = join(" AND ", $extra_conditions_arr);
            $categories = eme_get_event_categories($event['event_id'], $extra_conditions);
            $cat_links = array();
            foreach ($categories as $category) {
                $cat_link = eme_category_url($category);
                $cat_name = $category['category_name'];
                if ($target == "html") {
                    array_push($cat_links, "<a href='{$cat_link}' title='" . eme_trans_sanitize_html($cat_name, $lang) . "'>" . eme_trans_sanitize_html($cat_name, $lang) . "</a>");
                } else {
                    array_push($cat_links, eme_translate($cat_name, $lang));
                }
            }
            $replacement = join(", ", $cat_links);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif (preg_match('/#_CALENDAR_DAY/', $result)) {
            $day_key = get_query_var('calendar_day');
            $replacement = eme_localised_date($day_key . " " . $eme_timezone);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_RECURRENCE_DESC|#_RECURRENCEDESC/', $result)) {
            if ($event['recurrence_id']) {
                $replacement = eme_get_recurrence_desc($event['recurrence_id']);
                if ($target == "html") {
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_RECURRENCE_NBR/', $result)) {
            // returns the sequence number of an event in a recurrence series
            if ($event['recurrence_id']) {
                $events = eme_get_recurrence_eventids($event['recurrence_id']);
                $nbr = array_search($event['event_id'], $events);
                if ($nbr !== false) {
                    $replacement = $nbr + 1;
                }
            }
        } elseif ($event && preg_match('/#_RSVPEND/', $result)) {
            // show the end date+time for which a user can rsvp for an event
            if (eme_is_event_rsvp($event)) {
                $rsvp_number_days = $event['rsvp_number_days'];
                $rsvp_number_hours = $event['rsvp_number_hours'];
                $rsvp_end_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
                $rsvp_end_obj->minusDays($rsvp_number_days);
                $rsvp_end_obj->minusHours($rsvp_number_hours);
                $rsvp_end_date = eme_localised_date($rsvp_end_obj->getDateTime() . " " . $eme_timezone);
                $rsvp_end_time = eme_localised_time($rsvp_end_obj->getDateTime() . " " . $eme_timezone);
                $replacement = $rsvp_end_date . " " . $rsvp_end_time;
            }
        } elseif ($event && preg_match('/#_IS_RSVP_ENDED/', $result)) {
            if (eme_is_event_rsvp($event)) {
                $rsvp_number_days = $event['rsvp_number_days'];
                $rsvp_number_hours = $event['rsvp_number_hours'];
                $rsvp_end_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
                $rsvp_end_obj->minusDays($rsvp_number_days);
                $rsvp_end_obj->minusHours($rsvp_number_hours);
                if ($rsvp_end_obj->lessThan($eme_date_obj_now)) {
                    $replacement = 1;
                } else {
                    $replacement = 0;
                }
            }
        } elseif ($event && preg_match('/#_EVENT_EXTERNAL_REF/', $result)) {
            $replacement = $event['event_external_ref'];
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif (preg_match('/#_IS_SINGLE_DAY/', $result)) {
            if (eme_is_single_day_page()) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif (preg_match('/#_IS_SINGLE_EVENT/', $result)) {
            if (eme_is_single_event_page()) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif (preg_match('/#_IS_LOGGED_IN/', $result)) {
            if (is_user_logged_in()) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif (preg_match('/#_IS_ADMIN_PAGE/', $result)) {
            if (is_admin()) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_RSVP_ENABLED/', $result)) {
            if (eme_is_event_rsvp($event)) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_PRIVATE_EVENT/', $result)) {
            if ($event['event_status'] == STATUS_PRIVATE) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_RECURRENT_EVENT/', $result)) {
            if ($event['recurrence_id']) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_ONGOING_EVENT/', $result)) {
            $eme_start_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $eme_end_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            if ($eme_start_obj->lessOrEqualTo($eme_date_obj_now) && $eme_end_obj->greaterOrEqualTo($eme_date_obj_now)) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_REGISTERED/', $result)) {
            if (is_user_logged_in() && eme_get_booking_ids_by_wp_id($current_userid, $event['event_id'])) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_MULTIPRICE/', $result)) {
            if (eme_is_multi($event['price'])) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_MULTISEAT/', $result)) {
            if (eme_is_multi($event['event_seats'])) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_ALLDAY/', $result)) {
            if ($event['event_properties']['all_day']) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_ATTENDANCE/', $result)) {
            if ($event['event_properties']['take_attendance']) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_AUTHOR$/', $result)) {
            if ($event['event_author'] == $current_userid) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_CONTACTPERSON/', $result)) {
            if ($event['event_contactperson_id'] == $current_userid) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_AUTHOR_OR_CONTACTPERSON/', $result)) {
            if ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_MULTIDAY/', $result)) {
            if ($event['event_start_date'] != $event['event_end_date']) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_FIRST_RECURRENCE/', $result)) {
            // returns 1 if the event is the first event in a recurrence series
            if ($event['recurrence_id']) {
                $events = eme_get_recurrence_eventids($event['recurrence_id']);
                $nbr = array_search($event['event_id'], $events);
                if ($nbr !== false && $nbr == 0) {
                    $replacement = 1;
                }
            }
        } elseif ($event && preg_match('/#_IS_LAST_RECURRENCE/', $result)) {
            // returns 1 if the event is the last event in a recurrence series
            if ($event['recurrence_id']) {
                $events = eme_get_recurrence_eventids($event['recurrence_id']);
                $nbr = array_search($event['event_id'], $events);
                $last_index = count($events) - 1;
                if ($nbr !== false && $nbr == $last_index) {
                    $replacement = 1;
                }
            }
        } elseif (preg_match('/#_LOCALE/', $result)) {
            $replacement = get_locale();
        } else {
            $found = 0;
        }
        if ($found) {
            if ($need_escape) {
                $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement)));
            }
            if ($need_urlencode) {
                $replacement = rawurlencode($replacement);
            }
            $format = str_replace($orig_result, $replacement, $format);
        }
    }
    # now handle all possible location placeholders
    # but the eme_replace_locations_placeholders can't do "do_shortcode" at the end, because
    # this would cause [eme_if] tags to be replaced here already, while some placeholders of the
    # event haven't been replaced yet (like time placeholders, and event details)
    $format = eme_replace_locations_placeholders($format, $location, $target, 0, $lang);
    // for extra date formatting, eg. #_{d/m/Y}
    preg_match_all("/#(ESC|URL)?@?_\\{.*?\\}/", $format, $results);
    // make sure we set the largest matched placeholders first, otherwise if you found e.g.
    // #_LOCATION, part of #_LOCATIONPAGEURL would get replaced as well ...
    usort($results[0], 'sort_stringlenth');
    foreach ($results[0] as $result) {
        $need_escape = 0;
        $need_urlencode = 0;
        $orig_result = $result;
        if (strstr($result, '#ESC')) {
            $result = str_replace("#ESC", "#", $result);
            $need_escape = 1;
        } elseif (strstr($result, '#URL')) {
            $result = str_replace("#URL", "#", $result);
            $need_urlencode = 1;
        }
        $replacement = '';
        if (substr($result, 0, 3) == "#@_") {
            $my_date = "event_end_date";
            $my_time = "event_end_time";
            $offset = 4;
        } else {
            $my_date = "event_start_date";
            $my_time = "event_start_time";
            $offset = 3;
        }
        $replacement = eme_localised_date($event[$my_date] . " " . $event[$my_time] . " " . $eme_timezone, substr($result, $offset, strlen($result) - ($offset + 1)));
        if ($need_escape) {
            $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement)));
        }
        if ($need_urlencode) {
            $replacement = rawurlencode($replacement);
        }
        $format = str_replace($orig_result, $replacement, $format);
    }
    # we handle NOTES the last, this used to be the default behavior
    # so no placeholder replacement happened accidentaly in possible shortcodes inside #_NOTES
    # but since we have templates to aid in all that ...
    if (!$eme_enable_notes_placeholders) {
        $format = eme_replace_notes_placeholders($format, $event, $target);
    }
    // now, replace any language tags found in the format itself
    $format = eme_translate($format, $lang);
    if ($do_shortcode) {
        return do_shortcode($format);
    } else {
        return $format;
    }
}
Exemplo n.º 4
0
function eme_events_table($message = "", $scope = "future")
{
    global $eme_timezone;
    if (!empty($message)) {
        echo "<div id='message' class='updated fade'><p>" . eme_trans_sanitize_html($message) . "</p></div>";
    }
    //$list_limit = get_option('eme_events_admin_limit');
    //if ($list_limit<5 || $list_limit>200) {
    //   $list_limit=20;
    //   update_option('eme_events_admin_limit',$list_limit);
    //}
    //$offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
    //$events = eme_get_events ( $limit+1, "future", "ASC", $offset );
    $o_category = isset($_GET['category']) ? intval($_GET['category']) : 0;
    $status = isset($_GET['event_status']) ? intval($_GET['event_status']) : '';
    if (!empty($status)) {
        $extra_conditions = 'event_status = ' . $status;
    } else {
        $extra_conditions = '';
    }
    //$events = eme_get_events ( 0, $scope, "ASC", $offset, "", $o_category, '', '', 1, '', 0, $extra_conditions);
    $events = eme_get_events(0, $scope, "ASC", 0, "", $o_category, '', '', 1, '', 0, $extra_conditions);
    $events_count = count($events);
    $scope_names = array();
    $scope_names['past'] = __('Past events', 'eme');
    $scope_names['all'] = __('All events', 'eme');
    $scope_names['future'] = __('Future events', 'eme');
    ?>

<div class="wrap">
<div id="icon-events" class="icon32"><br />
</div>
<h1><?php 
    echo $scope_names[$scope];
    ?>
</h1>
   <?php 
    admin_show_warnings();
    ?>
   <!--<div id='new-event' class='switch-tab'><a href="<?php 
    echo admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_event");
    ?>
><?php 
    _e('New Event ...', 'eme');
    ?>
</a></div>-->
   <?php 
    $event_status_array = eme_status_array();
    ?>
 
      
   <div class="tablenav">
   <form id="posts-filter" action="" method="get">
   <input type='hidden' name='page' value='events-manager' />
   <select name="scope">
   <?php 
    foreach ($scope_names as $key => $value) {
        $selected = "";
        if ($key == $scope) {
            $selected = "selected='selected'";
        }
        echo "<option value='{$key}' {$selected}>{$value}</option>  ";
    }
    ?>
   </select>
   <select id="event_status" name="event_status">
      <option value="0"><?php 
    _e('Event Status', 'eme');
    ?>
</option>
      <?php 
    foreach ($event_status_array as $event_status_key => $event_status_value) {
        ?>
         <option value="<?php 
        echo $event_status_key;
        ?>
" <?php 
        if (isset($_GET['event_status']) && $_GET['event_status'] == $event_status_key) {
            echo 'selected="selected"';
        }
        ?>
><?php 
        echo $event_status_value;
        ?>
</option>
      <?php 
    }
    ?>
   </select>
   <select name="category">
   <option value='0'><?php 
    _e('All categories', 'eme');
    ?>
</option>
   <?php 
    $categories = eme_get_categories();
    foreach ($categories as $category) {
        $selected = "";
        if ($o_category == $category['category_id']) {
            $selected = "selected='selected'";
        }
        echo "<option value='" . $category['category_id'] . "' {$selected}>" . $category['category_name'] . "</option>";
    }
    ?>
   </select>
   <input id="post-query-submit" class="button-secondary" type="submit" value="<?php 
    _e('Filter');
    ?>
" />
   </form>

   <?php 
    if ($events_count > 0) {
        ?>
   <form id="eme_events_listform" action="" method="get">
   <input type='hidden' name='page' value='events-manager' />
   <select name="eme_admin_action">
   <option value="-1" selected="selected"><?php 
        _e('Bulk Actions');
        ?>
</option>
   <option value="deleteEvents"><?php 
        _e('Delete selected events', 'eme');
        ?>
</option>
   <option value="deleteRecurrence"><?php 
        _e('Delete selected recurrent events', 'eme');
        ?>
</option>
   <option value="publicEvents"><?php 
        _e('Publish selected events', 'eme');
        ?>
</option>
   <option value="privateEvents"><?php 
        _e('Make selected events private', 'eme');
        ?>
</option>
   <option value="draftEvents"><?php 
        _e('Make selected events draft', 'eme');
        ?>
</option>
   </select>
   <input type="submit" value="<?php 
        _e('Apply');
        ?>
" name="doaction2" id="doaction2" class="button-secondary action" />
   <div class="clear"></div>
   <br />

   <table class="widefat hover stripe" id="eme_admin_events">
   <thead>
      <tr>
         <th class='manage-column column-cb check-column' scope='col'><input
            class='select-all' type="checkbox" value='1' /></th>
         <th><?php 
        _e('ID', 'eme');
        ?>
</th>
         <th><?php 
        _e('Name', 'eme');
        ?>
</th>
         <th><?php 
        _e('Status', 'eme');
        ?>
</th>
         <th><?php 
        _e('Copy', 'eme');
        ?>
</th>
         <th><?php 
        _e('Location', 'eme');
        ?>
</th>
         <th><?php 
        _e('Date and time', 'eme');
        ?>
</th>
         <th><?php 
        _e('Recurrence info', 'eme');
        ?>
</th>
      </tr>
   </thead>
   <tbody>
   <?php 
        $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
        $today = $eme_date_obj->getDate();
        foreach ($events as $event) {
            $localised_start_date = eme_localised_date($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
            $localised_start_time = eme_localised_time($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
            $localised_end_date = eme_localised_date($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone);
            $localised_end_time = eme_localised_time($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone);
            $datasort_startstring = strtotime($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
            $location_summary = "";
            if (isset($event['location_id']) && $event['location_id']) {
                $location = eme_get_location($event['location_id']);
                $location_summary = "<b>" . eme_trans_sanitize_html($location['location_name']) . "</b><br />" . eme_trans_sanitize_html($location['location_address']) . " - " . eme_trans_sanitize_html($location['location_town']);
            }
            $style = "";
            if ($event['event_start_date'] < $today) {
                $style = "style ='background-color: #FADDB7;'";
            }
            ?>
     <tr <?php 
            echo "{$style}";
            ?>
>
         <td><input type='checkbox' class='row-selector' value='<?php 
            echo $event['event_id'];
            ?>
' name='events[]' /></td>
         <td><?php 
            echo $event['event_id'];
            ?>
</td>
         <td><strong>
         <a class="row-title" href="<?php 
            echo admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_event&amp;event_id=" . $event['event_id']);
            ?>
" title="<?php 
            _e('Edit event', 'eme');
            ?>
"><?php 
            echo eme_trans_sanitize_html($event['event_name']);
            ?>
</a>
         </strong>
         <?php 
            $categories = explode(',', $event['event_category_ids']);
            foreach ($categories as $cat) {
                $category = eme_get_category($cat);
                if ($category) {
                    echo "<br /><span title='" . __('Category', 'eme') . ": " . eme_trans_sanitize_html($category['category_name']) . "'>" . eme_trans_sanitize_html($category['category_name']) . "</span>";
                }
            }
            if ($event['event_rsvp']) {
                $booked_seats = eme_get_booked_seats($event['event_id']);
                $available_seats = eme_get_available_seats($event['event_id']);
                $pending_seats = eme_get_pending_seats($event['event_id']);
                $total_seats = $event['event_seats'];
                if (eme_is_multi($event['event_seats'])) {
                    $available_seats_string = $available_seats . ' (' . eme_convert_array2multi(eme_get_available_multiseats($event['event_id'])) . ')';
                    $pending_seats_string = $pending_seats . ' (' . eme_convert_array2multi(eme_get_pending_multiseats($event['event_id'])) . ')';
                    $total_seats_string = eme_get_multitotal($total_seats) . ' (' . $event['event_seats'] . ')';
                } else {
                    $available_seats_string = $available_seats;
                    $pending_seats_string = $pending_seats;
                    $total_seats_string = $total_seats;
                }
                if ($pending_seats > 0) {
                    echo "<br />" . __('RSVP Info: ', 'eme') . __('Free: ', 'eme') . $available_seats_string . ", " . __('Pending: ', 'eme') . $pending_seats_string . ", " . __('Max: ', 'eme') . $total_seats_string;
                } else {
                    echo "<br />" . __('RSVP Info: ', 'eme') . __('Free: ', 'eme') . $available_seats_string . ", " . __('Max: ', 'eme') . $total_seats_string;
                }
                if ($booked_seats > 0 || $pending_seats > 0) {
                    $printable_address = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_printable&amp;event_id=" . $event['event_id']);
                    $csv_address = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_csv&amp;event_id=" . $event['event_id']);
                    echo " (<a id='booking_printable_" . $event['event_id'] . "' href='{$printable_address}'>" . __('Printable view', 'eme') . "</a>)";
                    echo " (<a id='booking_csv_" . $event['event_id'] . "' href='{$csv_address}'>" . __('CSV export', 'eme') . "</a>)";
                }
            }
            ?>
 
         </td>
         <td>
         <?php 
            if (isset($event_status_array[$event['event_status']])) {
                echo $event_status_array[$event['event_status']];
                $event_url = eme_event_url($event);
                if ($event['event_status'] == STATUS_DRAFT) {
                    echo "<br /> <a href='{$event_url}'>" . __('Preview event', 'eme') . "</a>";
                } else {
                    echo "<br /> <a href='{$event_url}'>" . __('View event', 'eme') . "</a>";
                }
            }
            ?>
 
         </td>
         <td>
         <a href="<?php 
            echo admin_url("admin.php?page=events-manager&amp;eme_admin_action=duplicate_event&amp;event_id=" . $event['event_id']);
            ?>
" title="<?php 
            _e('Duplicate this event', 'eme');
            ?>
"><img src='<?php 
            echo EME_PLUGIN_URL . "images/copy_24.png";
            ?>
'/></a>
         </td>
         <td>
             <?php 
            echo $location_summary;
            ?>
         </td>
         <td data-sort="<?php 
            echo $datasort_startstring;
            ?>
">
            <?php 
            echo $localised_start_date;
            if ($localised_end_date != '' && $localised_end_date != $localised_start_date) {
                echo " - " . $localised_end_date;
            }
            ?>
<br />
            <?php 
            if ($event['event_properties']['all_day'] == 1) {
                _e('All day', 'eme');
            } else {
                echo "{$localised_start_time} - {$localised_end_time}";
            }
            ?>
         </td>
         <td>
             <?php 
            if ($event['recurrence_id']) {
                $recurrence_desc = eme_get_recurrence_desc($event['recurrence_id']);
                ?>
               <b><?php 
                echo $recurrence_desc;
                ?>
            <br />
            <a href="<?php 
                echo admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_recurrence&amp;recurrence_id=" . $event['recurrence_id']);
                ?>
"><?php 
                print sprintf(__('Edit Recurrence ID %d', 'eme'), $event['recurrence_id']);
                ?>
</a></b>
            <?php 
            }
            ?>
         </td>
   </tr>
   <?php 
        }
        ?>
   
   </tbody>
   </table>

   </form>

<?php 
    } else {
        echo "<div id='events-admin-no-events'>" . get_option('eme_no_events_message') . "</div></div>";
    }
    ?>

   <script type="text/javascript">
   jQuery(document).ready( function() {
         jQuery('#eme_admin_events').dataTable( {
            "dom": 'Blfrtip',
	    "colReorder": true,
<?php 
    $locale_code = get_locale();
    $locale_file = EME_PLUGIN_DIR . "js/jquery-datatables/i18n/{$locale_code}.json";
    $locale_file_url = EME_PLUGIN_URL . "js/jquery-datatables/i18n/{$locale_code}.json";
    if ($locale_code != "en_US" && file_exists($locale_file)) {
        ?>
            "language": {
                            "url": "<?php 
        echo $locale_file_url;
        ?>
"
                        },
<?php 
    }
    ?>
            "stateSave": true,
            "pagingType": "full",
            "columnDefs": [
               { "sortable": false, "targets": [0,4,7] }
            ],
            "buttons": [
               'csv',
               'print',
               {
                  extend: 'colvis',
                  columns: ':not(:first-child)'
               }
            ]
         } );
   } );
   </script>

   </div>
</div>
<?php 
}