-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#334] Initial version of the Email reminder service
* Added configuration parameters * Added a couple of email templates * Initial version of the web service
- Loading branch information
Showing
4 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Hello ###LOGIN###, | ||
|
||
The last task you recorded in PHPReport was on ###LAST_TASK_DATE###. | ||
|
||
This was a very long time ago, so please fill in your hours. | ||
|
||
Recall that you should record your hours on a more timely maner. | ||
As time passes, the accuracy of the recorded hours will suffer and some | ||
information may be lost. | ||
|
||
This situation should be fixed as soon as posible. Keep in mind that, | ||
in a couple of days, the past month will be closed and you will not | ||
be able to fill in hours but under special request to us. | ||
|
||
If you are having issues filling hours, please let us know right away. | ||
|
||
Best regards, | ||
|
||
-- | ||
Project Management |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Hello ###LOGIN###, | ||
|
||
The last task you recorded in PHPReport was on ###LAST_TASK_DATE###. | ||
|
||
This was a while ago. Recall that you should record your hours on a | ||
more timely maner. As time passes, the accuracy of the recorded hours | ||
will suffer and some information may be lost. | ||
|
||
We encourage you to fix this situation as soon as posible. If you are having | ||
issues filling hours, please let us know as soon as possible. | ||
|
||
Best regards, | ||
|
||
-- | ||
Project Management |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2018 Igalia, S.L. <info@igalia.com> | ||
* | ||
* This file is part of PhpReport. | ||
* | ||
* PhpReport 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. | ||
* | ||
* PhpReport 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 PhpReport. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** sendEmailAlertNoFill web service. | ||
* | ||
* @filesource | ||
* @package PhpReport | ||
* @subpackage services | ||
* @author Pablo Abelenda | ||
*/ | ||
|
||
error_reporting(E_ERROR | E_WARNING | E_PARSE); | ||
|
||
define('PHPREPORT_ROOT', __DIR__ . '/../../'); | ||
include_once(PHPREPORT_ROOT . '/model/facade/UsersFacade.php'); | ||
include_once(PHPREPORT_ROOT . '/model/vo/UserVO.php'); | ||
|
||
include_once(PHPREPORT_ROOT . '/util/ConfigurationParametersManager.php'); | ||
$ALL_USERS_GROUP = ConfigurationParametersManager::getParameter('ALL_USERS_GROUP'); | ||
$NO_FILL_CC_CRITICAL = ConfigurationParametersManager::getParameter('NO_FILL_CC_CRITICAL'); | ||
$NO_FILL_TEMPLATE_CRITICAL = ConfigurationParametersManager::getParameter('NO_FILL_TEMPLATE_CRITICAL'); | ||
$NO_FILL_SUBJECT_CRITICAL = ConfigurationParametersManager::getParameter('NO_FILL_SUBJECT_CRITICAL'); | ||
$NO_FILL_DAYS_TRIGGER_CRITICAL = ConfigurationParametersManager::getParameter('NO_FILL_DAYS_TRIGGER_CRITICAL'); | ||
$NO_FILL_CC_WARNING = ConfigurationParametersManager::getParameter('NO_FILL_CC_WARNING'); | ||
$NO_FILL_TEMPLATE_WARNING = ConfigurationParametersManager::getParameter('NO_FILL_TEMPLATE_WARNING'); | ||
$NO_FILL_SUBJECT_WARNING = ConfigurationParametersManager::getParameter('NO_FILL_SUBJECT_WARNING'); | ||
$NO_FILL_DAYS_TRIGGER_WARNING = ConfigurationParametersManager::getParameter('NO_FILL_DAYS_TRIGGER_WARNING'); | ||
|
||
function sendEmail($login, $lastTaskDate, $cc, $subject, $template) { | ||
$to = $login . "@domain.com"; | ||
$subject = $subject; | ||
$message = file_get_contents($template); | ||
$message = str_replace("###LAST_TASK_DATE###",$lastTaskDate->format('Y-m-d'),$message); | ||
$message = str_replace("###LOGIN###",$login,$message); | ||
$headers = ''; | ||
$headers = $headers . "From: <project-managers@domain.com>" . "\r\n"; | ||
$headers = $headers . "Reply-To: <project-managers@domain.com>" . "\r\n"; | ||
$headers = $headers . "Cc: " . $cc . "\r\n"; | ||
|
||
mail($to, $subject, $message, $headers); | ||
} | ||
|
||
$today = new DateTime(date('Y-m-d')); | ||
$initDate = new DateTime($today->format('Y').'-01-01'); | ||
|
||
$users = UsersFacade::GetAllUsers(); | ||
|
||
foreach ($users as $user) { | ||
$groups = $user->getGroups(); | ||
foreach ($groups as $group) { | ||
if ($group->getName() == $ALL_USERS_GROUP) { | ||
$report = UsersFacade::ExtraHoursReport($initDate, $today, $user); | ||
$login = $user->getLogin(); | ||
$lastTaskDate = $report[1][$user->getLogin()]["last_task_date"]; | ||
$difference = $lastTaskDate->diff($today); | ||
$difference = $difference->format('%a'); | ||
if ($difference >= $NO_FILL_DAYS_TRIGGER_CRITICAL) { | ||
$cc = $NO_FILL_CC_CRITICAL; | ||
$subject = $NO_FILL_SUBJECT_CRITICAL; | ||
$template = $NO_FILL_TEMPLATE_CRITICAL; | ||
sendEmail($login, $lastTaskDate, $cc, $subject, $template); | ||
} elseif ($difference >= $NO_FILL_DAYS_TRIGGER_WARNING) { | ||
$cc = $NO_FILL_CC_WARNING; | ||
$subject = $NO_FILL_SUBJECT_WARNING; | ||
$template = $NO_FILL_TEMPLATE_WARNING; | ||
sendEmail($login, $lastTaskDate, $cc, $subject, $template); | ||
} | ||
} | ||
} | ||
} | ||
|