Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #172 from sgrubsmyon/master
Browse files Browse the repository at this point in the history
Email notifications for locations, on bookings, cancellations, deletions, and when the location changes
  • Loading branch information
sgrubsmyon authored Sep 12, 2018
2 parents ae92f2f + 3f6a68d commit e5a35ce
Show file tree
Hide file tree
Showing 14 changed files with 923 additions and 1,434 deletions.
42 changes: 38 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ No new features will be added to CB 0.X, for the new version see:
**Donate link:** https://www.wielebenwir.de/verein/unterstutzen
**Tags:** booking, commons
**Requires at least:** 3.9
**Tested up to:** 4.9.6
**Stable Tag:** 0.9.2.3
**Tested up to:** 4.9.8
**Stable Tag:** 0.9.3
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -123,10 +123,44 @@ New in this version:
## Changelog


### 0.9.2.3
### 0.9.4

* FIXED: Closed days are now correctly rendered on the calendar, and non-bookable.
Markus Voge took over adding features to Version 1.0.

* FEATURE: Locations can receive copies of confirmation emails that concern
their item. This feature must be enabled for each location by checking the new
checkbox "Send copies of booking confirmation emails to the location" on the
location edit page. By default, the checkbox is unchecked. If it is checked,
any email address entered into the contact details text field will receive
copies of all conformation emails, but only about the item managed by the
location.
* FEATURE: Emails are sent to users confirming the cancelation of a booking.
The concerned location is informed via a copy of the email if the "Send
copies ..." checkbox is checked (see above).
* FEATURE: When an admin deletes an open booking from the bookings table, the
user (and location if configured, see above) is also informed via email.
* FEATURE: When the location of an item changes, users who already booked are
informed via email of the new location. If configured for receiving email
copies (see above), also the old and new location are informed. Admins can
either edit an existing timeframe to change the location or delete the old and
create a new timeframe at the correct location. This enables to use a "fake"
location as a placeholder and then change to the actual location as soon as it
is known.
* FIXED: Bookings table shows the latest bookings at the top by default (default
order: descending by booking start date).


### 0.9.3

Maintenance release. New features will be added to Version 2.0.

* FIXED: Calendar javascript selection count failed if weekday rows enabled (Thanks to Markus Voge).
* Minimal change: Div class name changed from "intro" to "cb-intro" (Again, thanks to Markus Voge).


### 0.9.2.12

* FIXED: Closed days are now correctly rendered on the calendar, and non-bookable.


### 0.9.2.11
Expand Down
24 changes: 18 additions & 6 deletions admin/cb-bookings/class-cb-bookings-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,19 @@ function process_bulk_action()

if ('delete' === $this->current_action()) {
$ids = isset($_REQUEST['id']) ? $_REQUEST['id'] : array();

// convert to string, suited for SQL:
if (is_array($ids)) $ids = implode(',', $ids);

$items = $wpdb->get_results($wpdb->prepare("
SELECT * FROM $this->table_bookings
WHERE id IN($ids) AND date_start >= DATE(NOW()) AND status != 'canceled'
"), ARRAY_A);

foreach ($items as $item) {
do_action('cb_booking_send_delete_emails', $item['id']);
}

if (!empty($ids)) {
$wpdb->query("DELETE FROM $this->table_bookings WHERE id IN($ids)");
}
Expand Down Expand Up @@ -281,9 +292,6 @@ public function prepare_items()
// here we configure table headers, defined in our methods
$this->_column_headers = array($columns, $hidden, $sortable);

// [OPTIONAL] process bulk action if any
$this->process_bulk_action();

// get filters
$filters = $this->get_selected_Filters();
$sqlfilter = "";
Expand All @@ -298,8 +306,8 @@ public function prepare_items()

// prepare query params, as usual current page, order by and order direction
$paged = isset($_REQUEST['paged']) ? max(0, intval($_REQUEST['paged']) - 1) : 0;
$orderby = (isset($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array_keys($this->get_sortable_columns()))) ? $_REQUEST['orderby'] : $this->table_bookings . '.id';
$order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'asc';
$orderby = (isset($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array_keys($this->get_sortable_columns()))) ? $_REQUEST['orderby'] : $this->table_bookings . '.date_start';
$order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'desc';


// [REQUIRED] define $items array
Expand All @@ -313,6 +321,10 @@ public function prepare_items()
LIMIT %d OFFSET %d
", $per_page, $paged * $per_page), ARRAY_A);

// [OPTIONAL] process bulk action if any
// Run this after filling $items so that you can access them
$this->process_bulk_action();

// [REQUIRED] configure pagination
$this->set_pagination_args(array(
'total_items' => $total_items, // total items defined above
Expand Down Expand Up @@ -399,4 +411,4 @@ function add_tablenav( $var ) { //@TODO delete?

} // end Commons_Booking_Bookings_Table

?>
?>
7 changes: 6 additions & 1 deletion admin/cb-locations/includes/cb-locations-metaboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public function add_metabox ( array $meta_boxes ) {
'id' => parent::$plugin_slug . '_location_contactinfo_hide',
'type' => 'checkbox',
),
array(
'name' => __( 'Send copies of booking confirmation emails to the location. Any email address typed into "Phone Number, Email, ..." will receive copies.', 'commons-booking'),
'id' => parent::$plugin_slug . '_location_contactinfo_recv_copies',
'type' => 'checkbox',
),
),
);
$meta_boxes[ 'cb_location_metabox_openinghours' ] = array(
Expand Down Expand Up @@ -131,4 +136,4 @@ public function add_metabox ( array $meta_boxes ) {

return $meta_boxes;
}
}
}
62 changes: 50 additions & 12 deletions admin/cb-settings/cb-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ public function set_defaults( $item_page, $user_bookings_page, $booking_confirme
$this->prefix.'_mail_confirmation_sender' => '[email protected]', /* @TODO: retired – delete this with the next update */
$this->prefix.'_mail_from' => '',
$this->prefix.'_mail_from_name' => '',
$this->prefix.'_mail_registration_subject' => __( 'Welcome, {{USER_NAME}} – here´s your account information.', 'commons-booking'),
$this->prefix.'_mail_registration_body' => __( '<h2>Hi {{USER_NAME}}, thanks for registering!</h2>
<p>Only one more step: Click here to set your password:</p>
<p><strong>{{ACTIVATION_URL}}</strong></p>
<h3>Your information</h3>
<p>Username: <strong>{{USER_NAME}}</strong></p>
<p>Name: {{FIRST_NAME}} {{LAST_NAME}}</p>
<p>Address: {{ADDRESS}}</p>
<p>Phone: {{PHONE}}</p>
<p>Thanks, the Team. </p>
', 'commons-booking'),
$this->prefix.'_mail_confirmation_subject' => __( 'Your booking {{ITEM_NAME}}', 'commons-booking'),
$this->prefix.'_mail_confirmation_body' => __('<h2>Hi {{FIRST_NAME}}, thanks for booking {{ITEM_NAME}}!</h2>
Expand All @@ -96,20 +110,44 @@ public function set_defaults( $item_page, $user_bookings_page, $booking_confirme
<p>Thanks, the Team. </p>
', 'commons-booking'),
$this->prefix.'_mail_registration_subject' => __( 'Welcome, {{USER_NAME}} – here´s your account information.', 'commons-booking'),
$this->prefix.'_mail_registration_body' => __( '<h2>Hi {{USER_NAME}}, thanks for registering!</h2>
$this->prefix.'_mail_cancelation_subject' => __( 'Your booking {{ITEM_NAME}} was canceled', 'commons-booking'),
$this->prefix.'_mail_cancelation_body' => __('<h2>Hi {{FIRST_NAME}}, your booking {{ITEM_NAME}} has been canceled!</h2>
<p>Only one more step: Click here to set your password:</p>
<p><strong>{{ACTIVATION_URL}}</strong></p>
<p>Your booking of {{ITEM_NAME}} at {{LOCATION_NAME}} from {{DATE_START}} till {{DATE_END}} has been canceled.</p>
<h3>Your information</h3>
<p>Username: <strong>{{USER_NAME}}</strong></p>
<p>Name: {{FIRST_NAME}} {{LAST_NAME}}</p>
<p>Address: {{ADDRESS}}</p>
<p>Phone: {{PHONE}}</p>
<p>Thanks, the Team.</p>', 'commons-booking'),
$this->prefix.'_mail_deletion_subject' => __( 'Your booking {{ITEM_NAME}} was deleted by an admin', 'commons-booking'),
$this->prefix.'_mail_deletion_body' => __('<h2>Hi {{FIRST_NAME}}, your booking {{ITEM_NAME}} has been deleted by a page admin</h2>
<p>Thanks, the Team. </p>
', 'commons-booking'),
<p>Your booking of {{ITEM_NAME}} at {{LOCATION_NAME}} from {{DATE_START}} till {{DATE_END}} has been deleted.</p>
<p>Please contact {{SITE_EMAIL}} if you need further assistance.</p>
<p>Thanks, the Team.</p>', 'commons-booking'),
$this->prefix.'_mail_location_change_subject' => __( 'Your booking of {{ITEM_NAME}} has changed its location', 'commons-booking'),
$this->prefix.'_mail_location_change_body' => __('<h2>Hi {{FIRST_NAME}}, your booking of {{ITEM_NAME}} has a new location</h2>
<p>Your booking of {{ITEM_NAME}} from {{DATE_START}} till {{DATE_END}} has changed its location.</p>
<p>It can now be found at {{LOCATION_NAME}}:</p>
<p>Pick up {{ITEM_NAME}} at {{LOCATION_NAME}} on {{DATE_START}}.<br>
Return it there on {{DATE_END}}.<br>
Address: {{LOCATION_ADDRESS}}<br>
Opening hours: {{LOCATION_OPENINGHOURS}}.</p>
<p>Click here to see or cancel your booking: {{URL}}.</p>
<h3>Your information</h3>
<em>Please make sure you have entered the correct name and adress from your ID - otherwise you will not be able to pick up the item</em>
<p>Name: {{FIRST_NAME}} {{LAST_NAME}}.<br>
Address: {{USER_ADDRESS}}</p>
<p>Please contact {{SITE_EMAIL}} if you need further assistance.</p>
<p>Thanks, the Team.</p>', 'commons-booking'),
),
$this->prefix.'-settings-advanced' => array(
$this->prefix.'_enable_customprofile' => 'ON'
Expand Down Expand Up @@ -166,4 +204,4 @@ public function get_settings( $setting_page, $setting_name = "") {

}

?>
?>
54 changes: 45 additions & 9 deletions admin/cb-settings/views/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,28 +284,64 @@
'id' => $this->plugin_slug . '_mail_bcc',
'type' => 'text',
),
array(
'name' => __( 'Registration email subject', 'commons-booking' ),
'desc' => __( 'The subject of the registration Email. You can use <a href="http://dein-lastenrad.de/index.php?title=Registration_Mail_Template_Tags" target="_blank">Template tags</a>', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_registration_subject',
'type' => 'text',
),
array(
'name' => __( 'Registration email body', 'commons-booking' ),
'desc' => __( 'The body of the registration confirmation email. You can use HTML & <a href="http://dein-lastenrad.de/index.php?title=Registration_Mail_Template_Tags" target="_blank">Template tags</a>. ', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_registration_body',
'type' => 'textarea',
),
array(
'name' => __( 'Booking Confirmation email subject', 'commons-booking' ),
'desc' => __( 'The subject of the confirmation Email. You can use <a href="http://dein-lastenrad.de/index.php?title=Settings:Template_Tags" target="_blank">Template tags</a>', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_confirmation_subject',
'type' => 'text',
),
),
array(
'name' => __( 'Booking confirmation email body', 'commons-booking' ),
'desc' => __( 'The body of the confirmation email. You can use HTML & <a href="http://dein-lastenrad.de/index.php?title=Settings:Template_Tags" target="_blank">Template tags</a>. ', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_confirmation_body',
'type' => 'textarea',
),
),
array(
'name' => __( 'Registration email subject', 'commons-booking' ),
'desc' => __( 'The subject of the registration Email. You can use <a href="http://dein-lastenrad.de/index.php?title=Registration_Mail_Template_Tags" target="_blank">Template tags</a>', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_registration_subject',
'name' => __( 'Booking cancelation email subject', 'commons-booking' ),
'desc' => __( 'The subject of the cancelation Email. You can use <a href="http://dein-lastenrad.de/index.php?title=Settings:Template_Tags" target="_blank">Template tags</a>.', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_cancelation_subject',
'type' => 'text',
),
),
array(
'name' => __( 'Registration email body', 'commons-booking' ),
'desc' => __( 'The body of the registration confirmation email. You can use HTML & <a href="http://dein-lastenrad.de/index.php?title=Registration_Mail_Template_Tags" target="_blank">Template tags</a>. ', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_registration_body',
'name' => __( 'Booking cancelation email body', 'commons-booking' ),
'desc' => __( 'The body of the cancelation email. You can use HTML & <a href="http://dein-lastenrad.de/index.php?title=Settings:Template_Tags" target="_blank">Template tags</a>.', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_cancelation_body',
'type' => 'textarea',
),
array(
'name' => __( 'Booking deletion email subject', 'commons-booking' ),
'desc' => __( 'The subject of the email sent when an admin deletes a booking from the list of bookings. You can use <a href="http://dein-lastenrad.de/index.php?title=Settings:Template_Tags" target="_blank">Template tags</a>', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_deletion_subject',
'type' => 'text',
),
array(
'name' => __( 'Booking deletion email body', 'commons-booking' ),
'desc' => __( 'The body of the email sent when an admin deletes a booking from the list of bookings. You can use HTML & <a href="http://dein-lastenrad.de/index.php?title=Settings:Template_Tags" target="_blank">Template tags</a>.', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_deletion_body',
'type' => 'textarea',
),
array(
'name' => __( 'Booking location change email subject', 'commons-booking' ),
'desc' => __( 'The subject of the email sent when the location of a booking changes. You can use <a href="http://dein-lastenrad.de/index.php?title=Settings:Template_Tags" target="_blank">Template tags</a>', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_location_change_subject',
'type' => 'text',
),
array(
'name' => __( 'Booking location change email body', 'commons-booking' ),
'desc' => __( 'The body of the email sent when the location of a booking changes. You can use HTML & <a href="http://dein-lastenrad.de/index.php?title=Settings:Template_Tags" target="_blank">Template tags</a>.', 'commons-booking' ),
'id' => $this->plugin_slug . '_mail_location_change_body',
'type' => 'textarea',
),
),
Expand Down
33 changes: 33 additions & 0 deletions admin/cb-timeframes/cb-timeframes-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function cb_timeframes_table_form_page_handler( )
{
global $wpdb;
$table_name = $wpdb->prefix . 'cb_timeframes';
$bookings_table = $wpdb->prefix . 'cb_bookings';

$message = '';
$notice = '';
Expand All @@ -33,10 +34,12 @@ function cb_timeframes_table_form_page_handler( )
// if id is zero insert otherwise update
$item_valid = cb_timeframes_table_validate_entry( $item );
if ($item_valid === true) {
$timeframe_change = false;
if ($item['id'] == 0) {
$result = $wpdb->insert($table_name, $item);
$item['id'] = $wpdb->insert_id;
if ($result) {
$timeframe_change = true;
new Admin_Table_Message ( __('Item saved', 'commons-booking'), 'updated' );
$codes = new Commons_Booking_Codes_Generate;
$codes->generate_codes( $item['id'] );
Expand All @@ -47,6 +50,7 @@ function cb_timeframes_table_form_page_handler( )
} else {
$result = $wpdb->update($table_name, $item, array('id' => $item['id']));
if ($result) {
$timeframe_change = true;
new Admin_Table_Message( __('Timeframe updated.', 'commons-booking'), 'updated' );
$codes = new Commons_Booking_Codes_Generate;
$codes->generate_codes( $item['id'] );
Expand All @@ -55,6 +59,35 @@ function cb_timeframes_table_form_page_handler( )
new Admin_Table_Message ( __('Nothing changed.', 'commons-booking'), 'updated' );
}
}
if ($timeframe_change) {
// Check if there are already bookings in the DB with the same
// item_id during this new/changed timeframe (if the booking's
// date_start falls within the timeframe and lies in the
// future). If yes, check if the location in the bookings
// table is correct and if not, update the bookings table and
// send the user and the (new) location update emails.
$bookings = $wpdb->get_results($wpdb->prepare("
SELECT * FROM $bookings_table
WHERE item_id = %d AND date_start >= DATE(NOW()) AND date_start <= %s AND status != 'canceled'
", $item['item_id'], $item['date_end']), ARRAY_A);
foreach ($bookings as $booking) {
// if the booking's location does not match the timeframe's
// location
if ($booking['location_id'] != $item['location_id']) {
// then change it in the bookings table and notify the
// user via email that the location has changed
$old_loc_id = $booking['location_id'];
$booking['location_id'] = $item['location_id'];
$result = $wpdb->update($bookings_table, $booking, array('id' => $booking['id']));
if ($result) {
new Admin_Table_Message( sprintf(__('Bookings table updated for booking %d.', 'commons-booking'), $booking['id']), 'updated' );
do_action('cb_booking_send_location_change_emails', $booking['id'], $old_loc_id);
} else { // nothing changed or there was an error
new Admin_Table_Message ( sprintf(__('Bookings table could not be updated for booking %d.', 'commons-booking'), $booking['id']), 'error' );
}
}
}
}
} else {
// if $item_valid not true it contains error message(s)
$notice = $item_valid;
Expand Down
Loading

0 comments on commit e5a35ce

Please sign in to comment.