예제 #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();
} 
예제 #2
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 
}
예제 #3
0
function eme_registration_seats_page($pending = 0)
{
    global $wpdb, $plugin_page;
    // do the actions if required
    if (isset($_GET['eme_admin_action']) && $_GET['eme_admin_action'] == "editRegistration" && isset($_GET['booking_id'])) {
        $booking_id = intval($_GET['booking_id']);
        $booking = eme_get_booking($booking_id);
        $event_id = $booking['event_id'];
        $event = eme_get_event($event_id);
        // we need to set the action url, otherwise the GET parameters stay and we will fall in this if-statement all over again
        $action_url = admin_url("admin.php?page={$plugin_page}");
        $ret_string = "<form id='eme-rsvp-form' name='booking-form' method='post' action='{$action_url}'>";
        $ret_string .= __('Send mails for changed registration?', 'eme') . eme_ui_select_binary(1, "send_mail");
        $ret_string .= eme_replace_formfields_placeholders($event, $booking);
        $ret_string .= "\n         <input type='hidden' name='eme_admin_action' value='updateRegistration' />\n         <input type='hidden' name='booking_id' value='{$booking_id}' />\n         </form>";
        print $ret_string;
        return;
    } else {
        $action = isset($_POST['eme_admin_action']) ? $_POST['eme_admin_action'] : '';
        $send_mail = isset($_POST['send_mail']) ? intval($_POST['send_mail']) : 1;
        if ($action == 'newRegistration') {
            $event_id = intval($_POST['event_id']);
            $event = eme_get_event($event_id);
            $ret_string = "<form id='eme-rsvp-form' name='booking-form' method='post' action=''>";
            $ret_string .= __('Send mails for new registration?', 'eme') . eme_ui_select_binary(1, "send_mail");
            $ret_string .= eme_replace_formfields_placeholders($event);
            $ret_string .= "\n            <input type='hidden' name='eme_admin_action' value='addRegistration' />\n            <input type='hidden' name='event_id' value='{$event_id}' />\n            </form>";
            print $ret_string;
            return;
        } elseif ($action == 'addRegistration') {
            $event_id = intval($_POST['event_id']);
            $booking_payed = isset($_POST['booking_payed']) ? intval($_POST['booking_payed']) : 0;
            $event = eme_get_event($event_id);
            $booking_res = eme_book_seats($event, $send_mail);
            $result = $booking_res[0];
            $booking_id_done = $booking_res[1];
            if (!$booking_id_done) {
                print "<div id='message' class='error'><p>{$result}</p></div>";
            } else {
                print "<div id='message' class='updated'><p>{$result}</p></div>";
                eme_update_booking_payed($booking_id_done, $booking_payed);
            }
        } elseif ($action == 'updateRegistration') {
            $booking_id = intval($_POST['booking_id']);
            $booking = eme_get_booking($booking_id);
            $deprecated = get_option('eme_deprecated');
            //$event_id = $booking['event_id'];
            //$event = eme_get_event($event_id);
            if (isset($_POST['comment'])) {
                $bookerComment = eme_strip_tags($_POST['comment']);
            } else {
                $bookerComment = "";
            }
            if (isset($_POST['bookedSeats'])) {
                $bookedSeats = intval($_POST['bookedSeats']);
            } else {
                $bookedSeats = 0;
            }
            // for multiple prices, we have multiple booked Seats as well
            // the next foreach is only valid when called from the frontend
            $bookedSeats_mp = array();
            //if (eme_is_multi($event['price'])) {
            if (eme_is_multi($booking['booking_price'])) {
                // make sure the array contains the correct keys already, since
                // later on in the function eme_record_booking we do a join
                //$booking_prices_mp=eme_convert_multi2array($event['price']);
                $booking_prices_mp = eme_convert_multi2array($booking['booking_price']);
                foreach ($booking_prices_mp as $key => $value) {
                    $bookedSeats_mp[$key] = 0;
                }
                foreach ($_POST as $key => $value) {
                    if (preg_match('/bookedSeats(\\d+)/', $key, $matches)) {
                        $field_id = intval($matches[1]) - 1;
                        $bookedSeats += $value;
                        $bookedSeats_mp[$field_id] = $value;
                    }
                }
                eme_update_booking($booking_id, $booking['event_id'], eme_convert_array2multi($bookedSeats_mp), $booking['booking_price'], $bookerComment);
            } else {
                eme_update_booking($booking_id, $booking['event_id'], $bookedSeats, $booking['booking_price'], $bookerComment);
            }
            eme_update_person_with_postinfo($booking['person_id']);
            if ($send_mail) {
                eme_email_rsvp_booking($booking, $action);
            }
            print "<div id='message' class='updated'><p>" . __("Booking updated", "eme") . "</p></div>";
        } elseif ($action == 'approveRegistration' || $action == 'denyRegistration' || $action == 'updatePayedStatus') {
            $bookings = isset($_POST['bookings']) ? $_POST['bookings'] : array();
            $selected_bookings = isset($_POST['selected_bookings']) ? $_POST['selected_bookings'] : array();
            $bookings_seats = isset($_POST['bookings_seats']) ? $_POST['bookings_seats'] : array();
            $bookings_payed = isset($_POST['bookings_payed']) ? $_POST['bookings_payed'] : array();
            foreach ($bookings as $key => $booking_id) {
                if (!in_array($booking_id, $selected_bookings)) {
                    continue;
                }
                // make sure the seats are integers
                $booking = eme_get_booking($booking_id);
                if ($action == 'updatePayedStatus') {
                    if ($booking['booking_payed'] != intval($bookings_payed[$key])) {
                        eme_update_booking_payed($booking_id, intval($bookings_payed[$key]));
                    }
                } elseif ($action == 'approveRegistration') {
                    eme_approve_booking($booking_id);
                    if ($booking['booking_payed'] != intval($bookings_payed[$key])) {
                        eme_update_booking_payed($booking_id, intval($bookings_payed[$key]));
                    }
                    if ($send_mail) {
                        eme_email_rsvp_booking($booking, $action);
                    }
                } elseif ($action == 'denyRegistration') {
                    eme_delete_booking($booking_id);
                    if ($send_mail) {
                        eme_email_rsvp_booking($booking, $action);
                    }
                }
            }
        }
    }
    // now show the menu
    eme_registration_seats_form_table($pending);
}
예제 #4
0
function eme_registration_seats_page($pending=0) {
   global $wpdb,$plugin_page,$eme_timezone;

   // do the actions if required
   if (isset($_GET['eme_admin_action']) && $_GET['eme_admin_action'] == "editRegistration" && isset($_GET['booking_id'])) {
      $booking_id = intval($_GET['booking_id']);
      $booking = eme_get_booking($booking_id);
      $event_id = $booking['event_id'];
      $event = eme_get_event($event_id);
      // we need to set the action url, otherwise the GET parameters stay and we will fall in this if-statement all over again
      $action_url = admin_url("admin.php?page=$plugin_page");
      $ret_string = "<form id='eme-rsvp-form' name='booking-form' method='post' action='$action_url'>";
      $ret_string.= __('Send mails for changed registration?','eme') . eme_ui_select_binary(1,"send_mail");
      $all_events = eme_get_events("extra_conditions=".urlencode("event_rsvp=1 AND event_id!=$event_id"));
      if (count($all_events)>0) {
         $ret_string.= "<br />".__('Move booking to event','eme');
         $ret_string.= " <select name='event_id'>";
         $ret_string.=  "<option value='0' ></option>";
         foreach ( $all_events as $this_event ) {
            if ($this_event ['event_rsvp']) {
               $option_text=$this_event['event_name']." (".eme_localised_date($this_event['event_start_date']." ".$this_event['event_start_time']." ".$eme_timezone).")";
               $ret_string.=  "<option value='".$this_event['event_id']."' >".$option_text."</option>";
            }
         }
         $ret_string .= "</select>";
      }
      $ret_string.= eme_replace_formfields_placeholders ($event,$booking);
      $ret_string .= "
         <input type='hidden' name='eme_admin_action' value='updateRegistration' />
         <input type='hidden' name='booking_id' value='$booking_id' />
         </form>";
      print $ret_string;
      return;
   } else {
      $action = isset($_POST ['eme_admin_action']) ? $_POST ['eme_admin_action'] : '';
      $send_mail = isset($_POST ['send_mail']) ? intval($_POST ['send_mail']) : 1;

      if ($action == 'newRegistration') {
         $event_id = intval($_POST['event_id']);
         $event = eme_get_event($event_id);
         $ret_string = "<form id='eme-rsvp-form' name='booking-form' method='post' action=''>";
         $ret_string.= __('Send mails for new registration?','eme') . eme_ui_select_binary(1,"send_mail");
         $ret_string.= eme_replace_formfields_placeholders ($event);
         $ret_string .= "
            <input type='hidden' name='eme_admin_action' value='addRegistration' />
            <input type='hidden' name='event_id' value='$event_id' />
            </form>";
         print $ret_string;
         return;
      } elseif ($action == 'addRegistration') {
         $event_id = intval($_POST['event_id']);
         $booking_payed = isset($_POST ['booking_payed']) ? intval($_POST ['booking_payed']) : 0;
         $event = eme_get_event($event_id);
         $booking_res = eme_book_seats($event, $send_mail);
         $result=$booking_res[0];
         $booking_id_done=$booking_res[1];
         if (!$booking_id_done) {
            print "<div id='message' class='error'><p>$result</p></div>";
         } else {
            print "<div id='message' class='updated'><p>$result</p></div>";
            eme_update_booking_payed($booking_id_done,$booking_payed);
         }
      } elseif ($action == 'updateRegistration') {
         $booking_id = intval($_POST['booking_id']);
         $event_id = isset($_POST ['event_id']) ? intval($_POST ['event_id']) : 0;
         if ($event_id)
            eme_move_booking_event($booking_id,$event_id);
         $booking = eme_get_booking ($booking_id);

         if (isset($_POST['comment']))
            $bookerComment = eme_strip_tags($_POST['comment']);
         else
            $bookerComment = "";

         if (isset($_POST['bookedSeats']))
            $bookedSeats = intval($_POST['bookedSeats']);
         else
            $bookedSeats = 0;

         // for multiple prices, we have multiple booked Seats as well
         // the next foreach is only valid when called from the frontend
         $bookedSeats_mp = array();
         //if (eme_is_multi($event['price'])) {
         if (eme_is_multi($booking['booking_price'])) {
            // make sure the array contains the correct keys already, since
            // later on in the function eme_record_booking we do a join
            //$booking_prices_mp=eme_convert_multi2array($event['price']);
            $booking_prices_mp=eme_convert_multi2array($booking['booking_price']);
            foreach ($booking_prices_mp as $key=>$value) {
               $bookedSeats_mp[$key] = 0;
            }
            foreach($_POST as $key=>$value) {
               if (preg_match('/bookedSeats(\d+)/', $key, $matches)) {
                  $field_id = intval($matches[1])-1;
                  $bookedSeats += $value;
                  $bookedSeats_mp[$field_id]=$value;
               }
            }
            eme_update_booking($booking_id,$booking['event_id'],eme_convert_array2multi($bookedSeats_mp),$booking['booking_price'],$bookerComment);
         } else {
            eme_update_booking($booking_id,$booking['event_id'],$bookedSeats,$booking['booking_price'],$bookerComment);
         }
         eme_update_person_with_postinfo($booking['person_id']);

         // now get the changed booking and send mail if wanted
         $booking = eme_get_booking ($booking_id);
         if ($send_mail) eme_email_rsvp_booking($booking,$action);
         print "<div id='message' class='updated'><p>".__("Booking updated","eme")."</p></div>";

      } elseif ($action == 'approveRegistration' || $action == 'denyRegistration' || $action == 'updatePayedStatus') {
         $bookings = isset($_POST ['bookings']) ? $_POST ['bookings'] : array();
         $selected_bookings = isset($_POST ['selected_bookings']) ? $_POST ['selected_bookings'] : array();
         $bookings_seats = isset($_POST ['bookings_seats']) ? $_POST ['bookings_seats'] : array();
         $bookings_payed = isset($_POST ['bookings_payed']) ? $_POST ['bookings_payed'] : array();

         foreach ( $bookings as $key=>$booking_id ) {
            if (!in_array($booking_id,$selected_bookings)) {
               continue;
            }
            // make sure the seats are integers
            $booking = eme_get_booking ($booking_id);
            if ($action == 'updatePayedStatus') {
               if ($booking['booking_payed']!= intval($bookings_payed[$key]))
                  eme_update_booking_payed($booking_id,intval($bookings_payed[$key]));
            } elseif ($action == 'approveRegistration') {
               eme_approve_booking($booking_id);
               if ($booking['booking_payed']!= intval($bookings_payed[$key])) {
                  eme_update_booking_payed($booking_id,intval($bookings_payed[$key]));
                  // we changed something in the booking, so get the updated booking
                  // before sending out the mail
                  $booking = eme_get_booking ($booking_id);
               }
               if ($send_mail) eme_email_rsvp_booking($booking,$action);
            } elseif ($action == 'denyRegistration') {
               // the mail needs to be sent after the deletion, otherwise the count of free spaces is wrong
               eme_delete_booking($booking_id);
               if ($send_mail) eme_email_rsvp_booking($booking,$action);
               // delete the booking answers after the mail is sent, so the answers can still be used in the mail
               eme_delete_answers($booking_id);
            }
         }
      }
   }

   // now show the menu
   eme_registration_seats_form_table($pending);
}