1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
require_once __DIR__.'/../inc/global.inc.php'; |
6
|
|
|
require_once __DIR__.'/cm_webservice.php'; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Description of cm_soap_user. |
10
|
|
|
* |
11
|
|
|
* @author marcosousa |
12
|
|
|
*/ |
13
|
|
|
class WSCMUser extends WSCM |
14
|
|
|
{ |
15
|
|
|
public function find_id_user($username, $password, $name) |
16
|
|
|
{ |
17
|
|
|
if ("valid" == $this->verifyUserPass($username, $password)) { |
18
|
|
|
$listResult = "#"; |
19
|
|
|
|
20
|
|
|
$listArrayResult = []; |
21
|
|
|
$listArray = []; |
22
|
|
|
|
23
|
|
|
$list = $this->get_user_list_like_start( |
24
|
|
|
['firstname' => $name], |
25
|
|
|
['firstname'] |
26
|
|
|
); |
27
|
|
|
foreach ($list as $userData) { |
28
|
|
|
$listArray[] = $userData['user_id']; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$list = $this->get_user_list_like_start( |
32
|
|
|
['lastname' => $name], |
33
|
|
|
['firstname'] |
34
|
|
|
); |
35
|
|
|
foreach ($list as $userData) { |
36
|
|
|
$listArray[] = $userData['user_id']; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$list = $this->get_user_list_like_start( |
40
|
|
|
['email' => $name], |
41
|
|
|
['firstname'] |
42
|
|
|
); |
43
|
|
|
foreach ($list as $userData) { |
44
|
|
|
$listArray[] = $userData['user_id']; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$listArrayResult = array_unique($listArray); |
48
|
|
|
foreach ($listArrayResult as $result) { |
49
|
|
|
$listResult .= $result."#"; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $listResult; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return "0"; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function get_link_user_picture($username, $password, $id) |
59
|
|
|
{ |
60
|
|
|
if ("valid" == $this->verifyUserPass($username, $password)) { |
61
|
|
|
$userPic = UserManager::getUserPicture($id); |
62
|
|
|
if (empty($userPic)) { |
63
|
|
|
return "0"; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $userPic; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return "0"; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function get_user_name($username, $password, $id, $field) |
73
|
|
|
{ |
74
|
|
|
if ("valid" == $this->verifyUserPass($username, $password)) { |
75
|
|
|
$userInfo = api_get_user_info($id); |
76
|
|
|
switch ($field) { |
77
|
|
|
case 'firstname': |
78
|
|
|
return $userInfo['firstname']; |
79
|
|
|
break; |
|
|
|
|
80
|
|
|
case 'lastname': |
81
|
|
|
return $userInfo['lastname']; |
82
|
|
|
break; |
83
|
|
|
case 'bothfl': |
84
|
|
|
return $userInfo['firstname']." ".$userInfo['lastname']; |
85
|
|
|
break; |
86
|
|
|
case 'bothlf': |
87
|
|
|
return $userInfo['lastname']." ".$userInfo['firstname']; |
88
|
|
|
break; |
89
|
|
|
default: |
90
|
|
|
return $userInfo['firstname']; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return "0"; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return "0"; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/*public function send_invitation( |
100
|
|
|
$username, |
101
|
|
|
$password, |
102
|
|
|
$userfriend_id, |
103
|
|
|
$content_message = '' |
104
|
|
|
) { |
105
|
|
|
global $charset; |
106
|
|
|
if ("valid" == $this->verifyUserPass($username, $password)) { |
107
|
|
|
$user_id = UserManager::get_user_id_from_username($username); |
108
|
|
|
$message_title = get_lang('Invitation'); |
109
|
|
|
$count_is_true = SocialManager::send_invitation_friend( |
110
|
|
|
$user_id, |
111
|
|
|
$userfriend_id, |
112
|
|
|
$message_title, |
113
|
|
|
$content_message |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
if ($count_is_true) { |
117
|
|
|
return Display::return_message( |
118
|
|
|
api_htmlentities( |
119
|
|
|
get_lang('The invitation has been sent'), |
120
|
|
|
ENT_QUOTES, |
121
|
|
|
$charset |
122
|
|
|
), |
123
|
|
|
'normal', |
124
|
|
|
false |
125
|
|
|
); |
126
|
|
|
} else { |
127
|
|
|
return Display::return_message( |
128
|
|
|
api_htmlentities( |
129
|
|
|
get_lang('You already sent an invitation'), |
130
|
|
|
ENT_QUOTES, |
131
|
|
|
$charset |
132
|
|
|
), |
133
|
|
|
'error', |
134
|
|
|
false |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return get_lang('Login failed - incorrect login or password.'); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function accept_friend($username, $password, $userfriend_id) |
143
|
|
|
{ |
144
|
|
|
if ("valid" == $this->verifyUserPass($username, $password)) { |
145
|
|
|
$user_id = UserManager::get_user_id_from_username($username); |
146
|
|
|
UserManager::relate_users( |
147
|
|
|
$userfriend_id, |
148
|
|
|
$user_id, |
149
|
|
|
USER_RELATION_TYPE_FRIEND |
150
|
|
|
); |
151
|
|
|
SocialManager::invitation_accepted($userfriend_id, $user_id); |
152
|
|
|
|
153
|
|
|
return get_lang('Added contact to list'); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
return get_lang('Login failed - incorrect login or password.'); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function denied_invitation($username, $password, $userfriend_id) |
160
|
|
|
{ |
161
|
|
|
if ("valid" == $this->verifyUserPass($username, $password)) { |
162
|
|
|
$user_id = UserManager::get_user_id_from_username($username); |
163
|
|
|
SocialManager::invitation_denied($userfriend_id, $user_id); |
164
|
|
|
|
165
|
|
|
return get_lang('Invitation denied'); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return get_lang('Login failed - incorrect login or password.'); |
169
|
|
|
}*/ |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Get a list of users of which the given conditions match with a LIKE '%cond%'. |
173
|
|
|
* |
174
|
|
|
* @param array $conditions a list of condition (exemple : status=>STUDENT) |
175
|
|
|
* @param array $order_by a list of fields on which sort |
176
|
|
|
* |
177
|
|
|
* @return array an array with all users of the platform |
178
|
|
|
* |
179
|
|
|
* @todo optional course code parameter, optional sorting parameters... |
180
|
|
|
*@todo Use the UserManager class |
181
|
|
|
* @todo security filter order by |
182
|
|
|
*/ |
183
|
|
|
private static function get_user_list_like_start($conditions = [], $order_by = []) |
184
|
|
|
{ |
185
|
|
|
$user_table = Database::get_main_table(TABLE_MAIN_USER); |
186
|
|
|
$return_array = []; |
187
|
|
|
$sql_query = "SELECT * FROM $user_table"; |
188
|
|
|
if (count($conditions) > 0) { |
189
|
|
|
$sql_query .= ' WHERE '; |
190
|
|
|
foreach ($conditions as $field => $value) { |
191
|
|
|
$field = Database::escape_string($field); |
192
|
|
|
$value = Database::escape_string($value); |
193
|
|
|
$sql_query .= $field.' LIKE \''.$value.'%\''; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
$order = ''; |
197
|
|
|
foreach ($order_by as $orderByItem) { |
198
|
|
|
$order .= Database::escape_string($orderByItem).', '; |
199
|
|
|
} |
200
|
|
|
$order = substr($order, 0, -2); |
201
|
|
|
if (count($order_by) > 0) { |
202
|
|
|
$sql_query .= ' ORDER BY '.$order; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
$sql_result = Database::query($sql_query); |
206
|
|
|
while ($result = Database::fetch_array($sql_result)) { |
207
|
|
|
$return_array[] = $result; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
return $return_array; |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.