Skip to content

Commit

Permalink
[#334] Initial version of the Email reminder service
Browse files Browse the repository at this point in the history
 * Added configuration parameters
 * Added a couple of email templates
 * Initial version of the web service
  • Loading branch information
pabelenda committed May 8, 2018
1 parent 3364174 commit 976f1b1
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
48 changes: 48 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,51 @@ functionality to PhpReport
* @global int Value that acts as a warning trigger for extra hours values.
*/
define('EXTRA_HOURS_WARNING_TRIGGER', 50);

/**
* @name NO_FILL_CC_WARNING
* @global string Comma separated list of mailboxes that will receive warning emails.
*/
define('NO_FILL_CC_WARNING', 'manager1@domain.com');

/**
* @name NO_FILL_CC_CRITICAL
* @global string Comma separated list of mailboxes that will receive critical emails.
*/
define('NO_FILL_CC_CRITICAL', 'manager1@domain.com, project-management@domain.com');

/**
* @name NO_FILL_TEMPLATE_WARNING
* @global string File containing warning email.
*/
define('NO_FILL_TEMPLATE_WARNING', 'templates/no_fill_warning.txt');

/**
* @name NO_FILL_TEMPLATE_CRITICAL
* @global string File containing critical email.
*/
define('NO_FILL_TEMPLATE_CRITICAL', 'templates/no_fill_critical.txt');

/**
* @name NO_FILL_SUBJECT_WARNING
* @global string Subject containing warning email subject.
*/
define('NO_FILL_SUBJECT_WARNING', 'Please log your hours in PHPReport');

/**
* @name NO_FILL_SUBJECT_CRITICAL
* @global string Subject containing critical email subject.
*/
define('NO_FILL_SUBJECT_CRITICAL', '[URGENT] Log your hours in PHPReport');

/**
* @name NO_FILL_DAYS_TRIGGER_WARNING
* @global int Value in days to consider sending a warning message.
*/
define('NO_FILL_DAYS_TRIGGER_WARNING', 8);

/**
* @name NO_FILL_DAYS_TRIGGER_CRITICAL
* @global int Value in days to consider sending a critical message.
*/
define('NO_FILL_DAYS_TRIGGER_CRITICAL', 20);
20 changes: 20 additions & 0 deletions templates/no_fill_critical.txt
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
15 changes: 15 additions & 0 deletions templates/no_fill_warning.txt
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
88 changes: 88 additions & 0 deletions web/services/sendEmailAlertNoFill.php
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);
}
}
}
}

0 comments on commit 976f1b1

Please sign in to comment.