Issues (165)

src/controllers/messenger_controller.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 Copyright (C) 2018-2020 KANOUN Salim
4
 This program is free software; you can redistribute it and/or modify
5
 it under the terms of the Affero GNU General Public v.3 License as published by
6
 the Free Software Foundation;
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
 Affero GNU General Public Public for more details.
11
 You should have received a copy of the Affero GNU General Public Public along
12
 with this program; if not, write to the Free Software Foundation, Inc.,
13
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14
 */
15
16
/**
17
 * Messenger Utility for messaging across platform, send message by emails
18
 * to user role group or individual user having a role the study
19
 */
20
21
Session::checkSession();
22
$linkpdo=Session::getLinkpdo();
23
24
if (isset($_SESSION['username'])) {
25
    
26
	if (!empty($_POST) && !empty($_SESSION['study'])) {
27
        
28
		$individualUsers=array();
29
		if (isset($_POST['destinatorsList'])) {
30
			$individualUsers=$_POST['destinatorsList'];
31
		}
32
        
33
		$rolesGroups=array();
34
		if (isset($_POST['destinatorsRoles'])) {
35
			$rolesGroups=$_POST['destinatorsRoles'];
36
		}
37
        
38
		$message=$_POST['messageText'];
39
        
40
		$sendEmail=new Send_Email($linkpdo);
41
        
42
		foreach ($rolesGroups as $role) {
43
            
44
			if ($role != User::ADMINISTRATOR) {
45
				$sendEmail->addGroupEmails($_SESSION['study'], $role);
46
			}else {
47
				$sendEmail->addAminEmails();            
48
			}
49
            
50
		}
51
        
52
		foreach ($individualUsers as $user) {
53
			$sendEmail->addEmail($sendEmail->getUserEmails($user)); 
54
		}
55
56
		$userObject=new User($_SESSION['username'], $linkpdo);
57
		$sendEmail->setMessage($message);
58
		$sendEmail->setSubject('Message From '.$userObject->firstName.' '.$userObject->lastName);
59
		$sendEmail->sendEmail();
60
        
61
		$actionDetails['destinators']=json_encode($sendEmail->emailsDestinators);
62
		$htmlMessageObject=new \Html2Text\Html2Text($message);
0 ignored issues
show
The type Html2Text\Html2Text was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
63
		$actionDetails['message']=$htmlMessageObject->getText();
64
        
65
		Tracker::logActivity($_SESSION['username'], "User", $_SESSION['study'], null, "Send Message", $actionDetails);
66
        
67
		echo(json_encode(true));
68
        
69
	}else if (!empty($_SESSION['study'])) {
70
        
71
		//list all users having a role a in the study
72
		$studyObject=new Study($_SESSION['study'], $linkpdo);
73
		$usersObjects=$studyObject->getUsersWithRoleInStudy();
74
		//Sort by Lastname
75
		usort($usersObjects, function(User $a, User $b)
76
		{
77
			return strcmp($a->lastName, $b->lastName);
78
		});
79
        
80
		require 'views/messenger_view.php';
81
        
82
83
	}else {
84
		require 'includes/no_access.php';
85
	}
86
    
87
}else {
88
	require 'includes/no_access.php';
89
}