Skip to content

Commit

Permalink
add optional email when changing resource status
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorbel committed Sep 15, 2020
1 parent 59c61ec commit 74f3365
Show file tree
Hide file tree
Showing 14 changed files with 1,565 additions and 1,321 deletions.
2,490 changes: 1,273 additions & 1,217 deletions Pages/Admin/ManageResourcesPage.php

Large diffs are not rendered by default.

49 changes: 25 additions & 24 deletions Pages/Admin/ResourceAdminManageResourcesPage.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php
/**
Copyright 2012-2020 Nick Korbel
This file is part of Booked Scheduler.
Booked Scheduler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Booked Scheduler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
* Copyright 2012-2020 Nick Korbel
*
* This file is part of Booked Scheduler.
*
* Booked Scheduler is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Booked Scheduler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
*/

require_once(ROOT_DIR . 'Pages/Admin/ManageResourcesPage.php');
Expand All @@ -29,13 +29,14 @@ public function __construct()
{
parent::__construct();
$this->presenter = new ManageResourcesPresenter(
$this,
new ResourceAdminResourceRepository(new UserRepository(), ServiceLocator::GetServer()->GetUserSession()),
new ScheduleRepository(),
new ImageFactory(),
new GroupRepository(),
new AttributeService(new AttributeRepository()),
new UserPreferenceRepository()
);
$this,
new ResourceAdminResourceRepository(new UserRepository(), ServiceLocator::GetServer()->GetUserSession()),
new ScheduleRepository(),
new ImageFactory(),
new GroupRepository(),
new AttributeService(new AttributeRepository()),
new UserPreferenceRepository(),
new ReservationViewRepository()
);
}
}
32 changes: 31 additions & 1 deletion Presenters/Admin/ManageResourcesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require_once(ROOT_DIR . 'lib/Application/Admin/ImageUploadDirectory.php');
require_once(ROOT_DIR . 'lib/Application/Admin/ResourceImportCsv.php');
require_once(ROOT_DIR . 'lib/Application/Admin/CsvImportResult.php');
require_once(ROOT_DIR . 'lib/Email/Messages/ResourceStatusChangeEmail.php');

class ManageResourcesActions
{
Expand Down Expand Up @@ -98,14 +99,20 @@ class ManageResourcesPresenter extends ActionPresenter
*/
private $userPreferenceRepository;

/**
* @var IReservationViewRepository
*/
private $reservationViewRepository;

public function __construct(
IManageResourcesPage $page,
IResourceRepository $resourceRepository,
IScheduleRepository $scheduleRepository,
IImageFactory $imageFactory,
IGroupViewRepository $groupRepository,
IAttributeService $attributeService,
IUserPreferenceRepository $userPreferenceRepository)
IUserPreferenceRepository $userPreferenceRepository,
IReservationViewRepository $reservationViewRepository)
{
parent::__construct($page);

Expand All @@ -116,6 +123,7 @@ public function __construct(
$this->groupRepository = $groupRepository;
$this->attributeService = $attributeService;
$this->userPreferenceRepository = $userPreferenceRepository;
$this->reservationViewRepository = $reservationViewRepository;

$this->AddAction(ManageResourcesActions::ActionAdd, 'Add');
$this->AddAction(ManageResourcesActions::ActionChangeAdmin, 'ChangeAdmin');
Expand Down Expand Up @@ -464,6 +472,28 @@ public function ChangeStatus()

$resource->ChangeStatus($statusId, $statusReasonId);
$this->resourceRepository->Update($resource);

if ($this->page->SendStatusChangeMessage())
{

$emails = array();
$days = intval($this->page->StatusChangeDays());
$days = max(1, min($days, 365));
$message = $this->page->GetStatusChangeMessage();

Log::Debug("Sending resource status changed email to users. Days: %s", $days);

$reservations = $this->reservationViewRepository->GetReservations(Date::Now(), Date::Now()->AddDays($days), null, null, null, $resourceId);

foreach ($reservations as $reservation) {
$email = $reservation->OwnerEmailAddress;
if (!array_key_exists($email, $emails)) {
$emails[$email] = 1;
ServiceLocator::GetEmailService()->Send(new ResourceStatusChangeEmail($email, $resource, $message, $reservation->OwnerLanguage));
}

}
}
}

public function ChangeSchedule()
Expand Down
5 changes: 5 additions & 0 deletions Web/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ td.update {
#resource-images .resource-image img {
width: 100%;
}
#sendStatusChangeMessageContent {
background-color: #f0f0f0;
border: solid 1px #999;
padding: 1em;
}
.admin-page input,
#page-manage-blackouts input,
#page-manage-reservations input,
Expand Down
8 changes: 8 additions & 0 deletions Web/css/booked.css
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,14 @@ td.update {
#resource-images .resource-image img {
width: 100%;
}
#sendStatusChangeMessageContent {
background-color: #fcfcfc;
border: solid 1px #ccc;
padding: 1em;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
}
.admin-page input,
#page-manage-blackouts input,
#page-manage-reservations input,
Expand Down
7 changes: 7 additions & 0 deletions Web/css/less/admin.less
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,13 @@ td.update {
}
}

#sendStatusChangeMessageContent {
background-color: #fcfcfc;
border: solid 1px #ccc;
padding: 1em;
.rounded();
}

/// page level overrides

.admin-page, #page-manage-blackouts, #page-manage-reservations, #page-manage-resources, #page-manage-users, #page-manage-quotas {
Expand Down
59 changes: 41 additions & 18 deletions Web/scripts/admin/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ function ResourceManagement(opts) {
checkAllowConcurrent: $('#allowConcurrentChk'),
maxConcurrent: $('#maxConcurrentReservations'),
allowConcurrentDiv: $('#allowConcurrentDiv'),

toggleStatusChangeMessage: $('#toggleStatusChangeMessage'),
sendStatusChangeMessageContent: $('#sendStatusChangeMessageContent'),
statusMessageContent: $('#statusMessageContent'),
};

var resources = {};
Expand Down Expand Up @@ -322,17 +326,17 @@ function ResourceManagement(opts) {
}
});

$('#bulkEditConcurrent').change(function () {
if ($(this).val() == '1')
{
$('#bulkEditAllowConcurrentDiv').removeClass('no-show');
}
$('#bulkEditConcurrent').change(function () {
if ($(this).val() == '1')
{
$('#bulkEditAllowConcurrentDiv').removeClass('no-show');
}

if ($(this).val() == '0')
{
$('#bulkEditAllowConcurrentDiv').addClass('no-show');
}
});
if ($(this).val() == '0')
{
$('#bulkEditAllowConcurrentDiv').addClass('no-show');
}
});

elements.bulkUpdatePromptButton.click(function (e) {
e.preventDefault();
Expand Down Expand Up @@ -460,6 +464,18 @@ function ResourceManagement(opts) {
window.location.reload();
});


elements.toggleStatusChangeMessage.on('change', function (e) {
if ($(this).is(":checked"))
{
elements.sendStatusChangeMessageContent.removeClass('no-show');
}
else
{
elements.sendStatusChangeMessageContent.addClass('no-show');
}
});

var imageSaveErrorHandler = function (result) {
alert(result);
};
Expand Down Expand Up @@ -532,6 +548,7 @@ function ResourceManagement(opts) {
ConfigureAsyncForm(elements.copyForm, defaultSubmitCallback(elements.copyForm));
ConfigureAsyncForm(elements.importForm, defaultSubmitCallback(elements.importForm), importHandler);
ConfigureAsyncForm(elements.bulkDeleteForm, defaultSubmitCallback(elements.bulkDeleteForm));
ConfigureAsyncForm(elements.statusForm, defaultSubmitCallback(elements.statusForm));
};

ResourceManagement.prototype.add = function (resource) {
Expand Down Expand Up @@ -813,12 +830,12 @@ function ResourceManagement(opts) {

var showStatusPrompt = function (e) {
var resource = getActiveResource();
var statusForm = $('.popover:visible').find('form');
var statusForm = elements.statusForm;

var statusOptions = statusForm.find(elements.statusOptions);
var statusReasons = statusForm.find(elements.statusReasons);
var addStatusReason = statusForm.find(elements.addStatusReason);
var saveButton = statusForm.find('.save');
// var saveButton = statusForm.find('.save');

statusOptions.val(resource.statusId);
statusReasons.val(resource.reasonId);
Expand Down Expand Up @@ -849,14 +866,20 @@ function ResourceManagement(opts) {
}
});

saveButton.unbind();
// saveButton.unbind();
//
//
//
// saveButton.click(function () {
// statusForm.submit();
// });
//

ConfigureAsyncForm(statusForm, defaultSubmitCallback(statusForm));

saveButton.click(function () {
statusForm.submit();
});
elements.toggleStatusChangeMessage.prop('checked', false);
elements.sendStatusChangeMessageContent.addClass('no-show');
elements.statusMessageContent.val('');

elements.statusDialog.modal('show');
statusOptions.focus();
};

Expand Down
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<project name="booked" default="package">
<property name="version" value="2.8.4"/>
<property name="version" value="2.8.5"/>
<property name="is.pre.release" value="false"/>
<property name="packagename" value="booked-${version}"/>
<property name="root.dir" value="../.."/>
Expand Down
5 changes: 5 additions & 0 deletions lang/en_us.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,10 @@ protected function _LoadStrings()
$strings['ResourceDisplayInstructions'] = 'No resource has been selected. You can find the URL to display a resource in Application Management, Resources. The resource must be publicly accessible.';
$strings['Owner'] = 'Owner';
$strings['MaximumConcurrentReservations'] = 'Maximum Concurrent Reservations';
$strings['NotifyUsers'] = 'Notify Users';
$strings['Message'] = 'Message';
$strings['AllUsersWhoHaveAReservationInTheNext'] = 'Anyone with a reservation in the next';
$strings['ChangeResourceStatus'] = 'Change Resource Status';
// End Strings

// Install
Expand Down Expand Up @@ -1017,6 +1021,7 @@ protected function _LoadStrings()
$strings['ReservationParticipantDecline'] = '%s has declined your reservation invitation for %s on %s';
$strings['ReservationParticipantJoin'] = '%s has joined your reservation for %s on %s';
$strings['ReservationAvailableSubject'] = '%s is available on %s';
$strings['ResourceStatusChangedSubject'] = 'The availability of %s has changed';
// End Email Subjects

$this->Strings = $strings;
Expand Down
23 changes: 23 additions & 0 deletions lang/en_us/ResourceStatusChanged.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{*
Copyright 2011-2020 Nick Korbel
This file is part of Booked Scheduler.
Booked Scheduler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Booked Scheduler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
*}
<p>You are receiving this message because you have an upcoming reservation on {$ResourceName} and its availability has changed.</p>

<p>{$Message|nl2br}</p>

<p><a href="{$ScriptUrl}">Log in to {$AppTitle}</a></p>
4 changes: 2 additions & 2 deletions lib/Application/Authentication/CaptchaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public static function Create()
new BooleanConverter())
)
{
Log::Debug('Using ReCaptchaService');
// Log::Debug('Using ReCaptchaService');
return new ReCaptchaService();
}
Log::Debug('Using CaptchaService');
// Log::Debug('Using CaptchaService');
return new CaptchaService();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Config/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Configuration implements IConfiguration
const DEFAULT_CONFIG_ID = 'booked';
const DEFAULT_CONFIG_FILE_PATH = 'config/config.php';

const VERSION = '2.8.4';
const VERSION = '2.8.5';

protected function __construct()
{
Expand Down
Loading

0 comments on commit 74f3365

Please sign in to comment.