示例#1
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);
}
示例#2
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);
}