diff --git a/application/Espo/Controllers/Email.php b/application/Espo/Controllers/Email.php index d7636fa237..1dc8b039a9 100644 --- a/application/Espo/Controllers/Email.php +++ b/application/Espo/Controllers/Email.php @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ namespace Espo\Controllers; @@ -29,18 +29,18 @@ use \Espo\Core\Exceptions\Error; class Email extends \Espo\Core\Controllers\Record { public function actionGetCopiedAttachments($params, $data, $request) - { + { $id = $request->get('id'); - + return $this->getRecordService()->getCopiedAttachments($id); } - + public function actionSendTestEmail($params, $data, $request) { if (!$request->isPost()) { throw new BadRequest(); } - + if (empty($data['password'])) { if ($data['type'] == 'preferences') { if (!$this->getUser()->isAdmin() && $data['id'] != $this->getUser()->id) { @@ -50,7 +50,7 @@ class Email extends \Espo\Core\Controllers\Record if (!$preferences) { throw new Error(); } - + $data['password'] = $this->getContainer()->get('crypt')->decrypt($preferences->get('smtpPassword')); } else { if (!$this->getUser()->isAdmin()) { @@ -59,8 +59,21 @@ class Email extends \Espo\Core\Controllers\Record $data['password'] = $this->getConfig()->get('smtpPassword'); } } - + return $this->getRecordService()->sendTestEmail($data); } + + public function actionMarkAsRead($params, $data, $request) + { + if (!$request->isPost()) { + throw new BadRequest(); + } + if (empty($data['ids']) || !is_array($data['ids'])) { + throw new BadRequest(); + } + $ids = $data['ids']; + + return $this->getRecordService()->markAsReadByIds($ids); + } } diff --git a/application/Espo/Resources/i18n/en_US/Email.json b/application/Espo/Resources/i18n/en_US/Email.json index 6a116832b6..28fde07b9c 100644 --- a/application/Espo/Resources/i18n/en_US/Email.json +++ b/application/Espo/Resources/i18n/en_US/Email.json @@ -24,7 +24,8 @@ "Draft": "Draft", "Sending": "Sending", "Sent": "Sent", - "Archived": "Archived" + "Archived": "Archived", + "Received": "Received" }, "labels": { "Create Email": "Archive Email", @@ -38,7 +39,8 @@ "Email Accounts": "Email Accounts", "Send Test Email": "Send Test Email", "Send": "Send", - "Email Address": "Email Address" + "Email Address": "Email Address", + "Mark Read": "Mark Read" }, "messages": { "noSmtpSetup": "No SMTP setup. {link}.", diff --git a/application/Espo/Resources/layouts/Email/list.json b/application/Espo/Resources/layouts/Email/list.json index b54b532bbe..2011bce4b5 100644 --- a/application/Espo/Resources/layouts/Email/list.json +++ b/application/Espo/Resources/layouts/Email/list.json @@ -1,6 +1,6 @@ [ {"name":"personStringData","width":16,"notSortable": true, "customLabel": ""}, - {"name":"name","width":32,"link":true,"notSortable": true}, + {"name":"subject","width":32,"link":true,"notSortable": true}, {"name":"status","notSortable": true, "width":10}, {"name":"parent","notSortable": true}, {"name":"dateSent","view": "Fields.DatetimeShort", "notSortable": true, "width":10, "align": "right"} diff --git a/application/Espo/Resources/metadata/entityDefs/Email.json b/application/Espo/Resources/metadata/entityDefs/Email.json index 852639396a..451fe107cb 100644 --- a/application/Espo/Resources/metadata/entityDefs/Email.json +++ b/application/Espo/Resources/metadata/entityDefs/Email.json @@ -8,7 +8,8 @@ "type": "varchar", "required": true, "db": false, - "notStorable": true + "notStorable": true, + "view": "Email.Fields.Subject" }, "fromName": { "type": "varchar" @@ -44,6 +45,11 @@ "notStorable": true, "disabled": true }, + "isRead": { + "type": "bool", + "notStorable": true, + "default": true + }, "nameHash": { "type": "text", "notStorable": true, @@ -101,7 +107,7 @@ }, "status": { "type": "enum", - "options": ["Draft", "Sending", "Sent", "Archived"], + "options": ["Draft", "Sending", "Sent", "Received", "Archived"], "readOnly": true, "default": "Archived" }, @@ -167,7 +173,13 @@ "users": { "type": "hasMany", "entity": "User", - "foreign": "emails" + "foreign": "emails", + "additionalColumns": { + "isRead": { + "type": "bool", + "default": false + } + } }, "attachments": { "type": "hasChildren", diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php index d7869b7266..d070b8c2b0 100644 --- a/application/Espo/Services/Email.php +++ b/application/Espo/Services/Email.php @@ -206,10 +206,34 @@ class Email extends Record $this->loadAttachmentsTypes($entity); + $this->markAsRead($entity->id); } return $entity; } + public function markAsReadByIds(array $ids) + { + foreach ($ids as $id) { + $this->markAsRead($id); + } + return true; + } + + public function markAsRead($id) + { + + $pdo = $this->getEntityManager()->getPDO(); + $sql = " + UPDATE email_user SET is_read = 1 + WHERE + deleted = 0 AND + user_id = " . $pdo->quote($this->getUser()->id) . " AND + email_id = " . $pdo->quote($id) . " + "; + $pdo->query($sql); + return true; + } + public function loadAdditionalFieldsForList(Entity $entity) { parent::loadAdditionalFieldsForList($entity); @@ -246,8 +270,26 @@ class Email extends Record } $entity->set('personStringData', 'To: ' . implode(', ', $arr)); } - } + + $pdo = $this->getEntityManager()->getPDO(); + + $sql = " + SELECT is_read AS 'isRead' FROM email_user + WHERE + deleted = 0 AND + user_id = " . $pdo->quote($this->getUser()->id) . " AND + email_id = " . $pdo->quote($entity->id) . " + "; + + $sth = $pdo->prepare($sql); + $sth->execute(); + if ($row = $sth->fetch(\PDO::FETCH_ASSOC)) { + $isRead = !empty($row['isRead']) ? true : false; + } else { + $isRead = true; + } + $entity->set('isRead', $isRead); } protected function loadAttachmentsTypes(Entity $entity) diff --git a/frontend/client/res/templates/email/fields/subject/list-link.tpl b/frontend/client/res/templates/email/fields/subject/list-link.tpl new file mode 100644 index 0000000000..1f54f78735 --- /dev/null +++ b/frontend/client/res/templates/email/fields/subject/list-link.tpl @@ -0,0 +1,3 @@ +{{#unless isRead}}{{/unless}} +{{value}} +{{#unless isRead}}{{/unless}} diff --git a/frontend/client/res/templates/record/list-expanded.tpl b/frontend/client/res/templates/record/list-expanded.tpl index bcf854981b..aec5f7bcff 100644 --- a/frontend/client/res/templates/record/list-expanded.tpl +++ b/frontend/client/res/templates/record/list-expanded.tpl @@ -6,7 +6,7 @@ {{{pagination}}} {{/if}} - + {{#if checkboxes}}