-
Notifications
You must be signed in to change notification settings - Fork 3
/
message_write.php
327 lines (289 loc) · 12.1 KB
/
message_write.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
/**
***********************************************************************************************
* E-Mails versenden aus dem Plugin Mitgliedsbeitrag
*
* @copyright The Admidio Team
* @see https://www.admidio.org/
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 only
*
* Parameters:
*
* user_uuid : send message to the given user UUID
* usf_uuid : UUID of the (email) profile field which was transferred
***********************************************************************************************
*/
require_once(__DIR__ . '/../../adm_program/system/common.php');
require_once(__DIR__ . '/common_function.php');
require_once(__DIR__ . '/classes/configtable.php');
$getUserUuid = admFuncVariableIsValid($_GET, 'user_uuid', 'string');
$getUsfUuid = admFuncVariableIsValid($_GET, 'usf_uuid', 'string');
// only authorized user are allowed to start this module
if (!isUserAuthorized($_SESSION['pMembershipFee']['script_name']))
{
$gMessage->show($gL10n->get('SYS_NO_RIGHTS'));
// => EXIT
}
// check if the call of the page was allowed by settings
if (!$gSettingsManager->getBool('enable_mail_module'))
{
// message if the sending of PM is not allowed
$gMessage->show($gL10n->get('SYS_MODULE_DISABLED'));
// => EXIT
}
// check if user has email address for sending a email
if (!$gCurrentUser->hasEmail())
{
$gMessage->show($gL10n->get('SYS_CURRENT_USER_NO_EMAIL', array('<a href="'.ADMIDIO_URL.FOLDER_MODULES.'/profile/profile.php">', '</a>')));
// => EXIT
}
$pPreferences = new ConfigTablePMB();
$pPreferences->read();
$mailSubject = '';
$mailBody = '';
$mailToArray = array();
$user = new User($gDb, $gProfileFields);
$userField = new TableUserField($gDb);
$singleMail = false;
if ($getUserUuid !== '' && $getUsfUuid !== '') // ein E-Mail-Link wurde angeklickt
{
$user->readDataByUuid($getUserUuid);
$userField->readDataByUuid($getUsfUuid);
$singleMail = true;
}
elseif (isset($_SESSION['pMembershipFee']['checkedArray']))
{
$mailToArray = $_SESSION['pMembershipFee']['checkedArray'];
foreach ($mailToArray as $userId => $usfUuid )
{
if ($usfUuid === '')
{
unset($mailToArray[$userId]);
}
}
if (count($mailToArray) < 1)
{
$gMessage->show($gL10n->get('PLG_MITGLIEDSBEITRAG_EMAIL_EMPTY'));
// => EXIT
}
elseif (count($mailToArray) === 1) // der Mail-Button wurde angeklickt (aber es gibt nur eine Mail-Adresse in der Liste)
{
$user->readDataById(key($mailToArray));
$getUserUuid = $user->getValue('usr_uuid');
$getUsfUuid = current($mailToArray);
$userField->readDataByUuid($getUsfUuid);
$singleMail = true;
}
}
else
{
$gMessage->show($gL10n->get('PLG_MITGLIEDSBEITRAG_EMAIL_EMPTY'));
// => EXIT
}
// Subject und Body erzeugen
$text = new TableText($gDb);
//abhaengig vom aufrufenden Modul Text einlesen
if (substr_count($gNavigation->getUrl(), 'pre_notification') === 1)
{
$text->readDataByColumns(array('txt_name' => 'PMBMAIL_PRE_NOTIFICATION', 'txt_org_id' => $gCurrentOrgId));
//wenn noch nichts drin steht (=> "Einstellungen" und "Sichern" wurde noch nicht aufgerufen), dann vorbelegen (aber nicht speichern)
if ($text->getValue('txt_text') == '')
{
// convert <br /> to a normal line feed
$value = preg_replace('/<br[[:space:]]*\/?[[:space:]]*>/', chr(13).chr(10), $gL10n->get('PLG_MITGLIEDSBEITRAG_PMBMAIL_PRE_NOTIFICATION'));
$text->setValue('txt_text', $value);
}
}
elseif (substr_count($gNavigation->getUrl(), 'payments') === 1)
{
$text->readDataByColumns(array('txt_name' => 'PMBMAIL_CONTRIBUTION_PAYMENTS', 'txt_org_id' => $gCurrentOrgId));
//wenn noch nichts drin steht (=> "Einstellungen" und "Sichern" wurde noch nicht aufgerufen), dann vorbelegen (aber nicht speichern)
if ($text->getValue('txt_text') == '')
{
// convert <br /> to a normal line feed
$value = preg_replace('/<br[[:space:]]*\/?[[:space:]]*>/', chr(13).chr(10), $gL10n->get('PLG_MITGLIEDSBEITRAG_PMBMAIL_CONTRIBUTION_PAYMENTS'));
$text->setValue('txt_text', $value);
}
}
elseif (substr_count($gNavigation->getUrl(), 'bill') === 1)
{
$text->readDataByColumns(array('txt_name' => 'PMBMAIL_BILL', 'txt_org_id' => $gCurrentOrgId));
//wenn noch nichts drin steht (=> "Einstellungen" und "Sichern" wurde noch nicht aufgerufen), dann vorbelegen (aber nicht speichern)
if ($text->getValue('txt_text') == '')
{
// convert <br /> to a normal line feed
$value = preg_replace('/<br[[:space:]]*\/?[[:space:]]*>/', chr(13).chr(10), $gL10n->get('PLG_MITGLIEDSBEITRAG_PMBMAIL_BILL'));
$text->setValue('txt_text', $value);
}
}
$mailSrcText = $text->getValue('txt_text');
if ($singleMail)
{
$mailSrcText = replace_emailparameter($mailSrcText, $user); // nur wenn eine einzige Empfängeradresse vorhanden ist, die Parameter ersetzen
}
// Betreff und Inhalt anhand von Kennzeichnungen splitten oder ggf. Default-Inhalte nehmen
if(strpos($mailSrcText, '#subject#') !== false)
{
$mailSubject = trim(substr($mailSrcText, strpos($mailSrcText, '#subject#') + 9, strpos($mailSrcText, '#content#') - 9));
}
else
{
$mailSubject = 'Nachricht von '. $gCurrentOrganization->getValue('org_longname');
}
if(strpos($mailSrcText, '#content#') !== false)
{
$mailBody = trim(substr($mailSrcText, strpos($mailSrcText, '#content#') + 9));
}
else
{
$mailBody = $mailSrcText;
}
$mailBody = preg_replace('/\r\n/', '<br/>', $mailBody);
if ($mailSubject !== '')
{
$headline = $gL10n->get('SYS_SUBJECT').': '.$mailSubject;
}
else
{
$headline = $gL10n->get('SYS_SEND_EMAIL');
}
if ($singleMail)
{
//Datensatz fuer E-Mail-Adresse zusammensetzen
if($userField->getValue('usf_name_intern') === 'DEBTOR_EMAIL') // Problem: 'DEBTOR_EMAIL' ist als TEXT in der DB definiert
{
if(StringUtils::strValidCharacters((string) $user->getValue('DEBTOR_EMAIL'), 'email'))
{
$userEmail = $user->getValue('DEBTOR').' <'.$user->getValue('DEBTOR_EMAIL').'>';
}
else
{
$gMessage->show($gL10n->get('SYS_USER_NO_EMAIL', array($user->getValue('DEBTOR'))));
// => EXIT
}
}
else
{
if(StringUtils::strValidCharacters((string) $user->getValue($userField->getValue('usf_name_intern')), 'email'))
{
$userEmail = $user->getValue('FIRST_NAME'). ' '. $user->getValue('LAST_NAME').' <'.$user->getValue($userField->getValue('usf_name_intern')).'>';
}
else
{
$gMessage->show($gL10n->get('SYS_USER_NO_EMAIL', array($user->getValue('FIRST_NAME').' '.$user->getValue('LAST_NAME'))));
// => EXIT
}
}
}
else
{
$userEmail = $gL10n->get('PLG_MITGLIEDSBEITRAG_MAILCOUNT', array(count($mailToArray)));
}
// Wenn die letzte URL in der Zuruecknavigation die des Scriptes message_send.php ist,
// dann soll das Formular gefuellt werden mit den Werten aus der Session
// dieser Fall tritt i.d.R. nur ein, wenn der Mailversand fehlgeschlagen ist
if (strpos($gNavigation->getUrl(), 'message_send.php') > 0 && isset($_SESSION['pMembershipFee']['message_request']))
{
// Das Formular wurde also schon einmal ausgef�llt,
// da der User hier wieder gelandet ist nach der Mailversand-Seite
$formValues = $_SESSION['pMembershipFee']['message_request'];
unset($_SESSION['pMembershipFee']['message_request']);
$gNavigation->deleteLastUrl();
if(!isset($formValues['carbon_copy']))
{
$formValues['carbon_copy'] = false;
}
if(!isset($formValues['delivery_confirmation']))
{
$formValues['delivery_confirmation'] = false;
}
if(!isset($formValues['mailfrom']))
{
$formValues['mailfrom'] = $gCurrentUser->getValue('EMAIL');
}
}
else
{
$formValues['msg_subject'] = $mailSubject;
$formValues['msg_body'] = $mailBody;
$formValues['namefrom'] = '';
$formValues['mailfrom'] = $gCurrentUser->getValue('EMAIL');
$formValues['carbon_copy'] = false;
$formValues['delivery_confirmation'] = false;
}
// add current url to navigation stack
$gNavigation->addUrl(CURRENT_URL, $headline);
$page = new HtmlPage('plg-mitgliedsbeitrag-message-write', $headline);
// show form
$form = new HtmlForm('mail_send_form', SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER .'/message_send.php', array('user_uuid' => $getUserUuid, 'usf_uuid' => $getUsfUuid)), $page, array('enableFileUpload' => true));
$form->openGroupBox('gb_mail_contact_details', $gL10n->get('SYS_CONTACT_DETAILS'));
$form->addInput('msg_to', $gL10n->get('SYS_TO'), $userEmail, array('maxLength' => 50, 'property' => HtmlForm::FIELD_DISABLED));
$form->addLine();
$form->addInput('namefrom', $gL10n->get('SYS_YOUR_NAME'), $gCurrentUser->getValue('FIRST_NAME'). ' '. $gCurrentUser->getValue('LAST_NAME'),
array('maxLength' => 50, 'property' => HtmlForm::FIELD_DISABLED)
);
//Auswahlmöglichkeit für Sender-EMail-Adresse (falls es mehrere gibt)
$sql = 'SELECT COUNT(*) AS count
FROM '.TBL_USER_FIELDS.'
INNER JOIN '. TBL_USER_DATA .'
ON usd_usf_id = usf_id
WHERE usf_type = \'EMAIL\'
AND usd_usr_id = ? -- $gCurrentUserId
AND usd_value IS NOT NULL';
$pdoStatement = $gDb->queryPrepared($sql, array($gCurrentUserId));
$possibleEmails = $pdoStatement->fetchColumn();
if($possibleEmails > 1)
{
$sqlData = array();
$sqlData['query'] = 'SELECT email.usd_value AS ID, email.usd_value AS email
FROM '.TBL_USERS.'
INNER JOIN '.TBL_USER_DATA.' AS email
ON email.usd_usr_id = usr_id
AND LENGTH(email.usd_value) > 0
INNER JOIN '.TBL_USER_FIELDS.' AS field
ON field.usf_id = email.usd_usf_id
AND field.usf_type = \'EMAIL\'
WHERE usr_id = ? -- $gCurrentUserId
AND usr_valid = true
GROUP BY email.usd_value, email.usd_value';
$sqlData['params'] = array($gCurrentUserId);
$form->addSelectBoxFromSql(
'mailfrom', $gL10n->get('SYS_YOUR_EMAIL'), $gDb, $sqlData,
array('maxLength' => 50, 'defaultValue' => $formValues['mailfrom'], 'showContextDependentFirstEntry' => false)
);
}
else
{
$form->addInput(
'mailfrom', $gL10n->get('SYS_YOUR_EMAIL'), $formValues['mailfrom'],
array('maxLength' => 50, 'property' => HtmlForm::FIELD_DISABLED)
);
}
$form->addCheckbox('carbon_copy', $gL10n->get('SYS_SEND_COPY'), $formValues['carbon_copy']);
// if preference is set then show a checkbox where the user can request a delivery confirmation for the email
if (( (int) $gSettingsManager->get('mail_delivery_confirmation') === 2) || (int) $gSettingsManager->get('mail_delivery_confirmation') === 1)
{
$form->addCheckbox('delivery_confirmation', $gL10n->get('SYS_DELIVERY_CONFIRMATION'), $formValues['delivery_confirmation']);
}
$form->closeGroupBox();
$form->openGroupBox('gb_mail_message', $gL10n->get('SYS_MESSAGE'));
$form->addInput('msg_subject', $gL10n->get('SYS_SUBJECT'), $formValues['msg_subject'], array('maxLength' => 77, 'property' => HtmlForm::FIELD_REQUIRED));
if (($gSettingsManager->getInt('max_email_attachment_size') > 0) && PhpIniUtils::isFileUploadEnabled())
{
$form->addFileUpload(
'btn_add_attachment', $gL10n->get('SYS_ATTACHMENT'),
array(
'enableMultiUploads' => true,
'maxUploadSize' => Email::getMaxAttachmentSize(),
'multiUploadLabel' => $gL10n->get('SYS_ADD_ATTACHMENT'),
'hideUploadField' => true,
'helpTextIdLabel' => $gL10n->get('SYS_MAX_ATTACHMENT_SIZE', array(Email::getMaxAttachmentSize(Email::SIZE_UNIT_MEBIBYTE))),
'icon' => 'fa-paperclip'
)
);
}
$form->addEditor('msg_body', '', $formValues['msg_body'], array('property' => HtmlForm::FIELD_REQUIRED));
$form->closeGroupBox();
$form->addSubmitButton('btn_send', $gL10n->get('SYS_SEND'), array('icon' => 'fa-envelope'));
$page->addHtml($form->show());
$page->show();