forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email-templates.php
448 lines (410 loc) · 19.9 KB
/
email-templates.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
<?php
/**
* Allows the administrator to customize the emails
* sent by the system.
*
* @package ProjectSend
* @subpackage Options
*/
$allowed_levels = array(9);
require_once('sys.includes.php');
$section = ( !empty( $_GET['section'] ) ) ? $_GET['section'] : $_POST['section'];
switch ( $section ) {
case 'header_footer':
$section_title = __('Header / footer','cftp_admin');
$checkboxes = array(
'email_header_footer_customize',
);
break;
case 'new_files_for_client':
$section_title = __('New file by user','cftp_admin');
$checkboxes = array(
'email_new_file_by_user_customize',
'email_new_file_by_user_subject_customize',
);
break;
case 'new_file_by_client':
$section_title = __('New file by client','cftp_admin');
$checkboxes = array(
'email_new_file_by_client_customize',
'email_new_file_by_client_subject_customize',
);
break;
case 'new_client':
$section_title = __('New client (welcome)','cftp_admin');
$checkboxes = array(
'email_new_client_by_user_customize',
'email_new_client_by_user_subject_customize',
);
break;
case 'new_client_self':
$section_title = __('New client (self-registered)','cftp_admin');
$checkboxes = array(
'email_new_client_by_self_customize',
'email_new_client_by_self_subject_customize',
);
break;
case 'client_approve':
$section_title = __('Approve client account','cftp_admin');
$checkboxes = array(
'email_account_approve_subject_customize',
'email_account_approve_customize',
);
break;
case 'client_deny':
$section_title = __('Deny client account','cftp_admin');
$checkboxes = array(
'email_account_deny_subject_customize',
'email_account_deny_customize',
);
break;
case 'new_user':
$section_title = __('New user (welcome)','cftp_admin');
$checkboxes = array(
'email_new_user_customize',
'email_new_user_subject_customize',
);
break;
case 'password_reset':
$section_title = __('Password reset','cftp_admin');
$checkboxes = array(
'email_pass_reset_customize',
'email_pass_reset_subject_customize',
);
break;
default:
$location = BASE_URI . 'email-templates.php?section=header_footer';
header("Location: $location");
die();
break;
}
$page_title = $section_title;
$active_nav = 'emails';
include('header.php');
if ($_POST) {
foreach ($checkboxes as $checkbox) {
$_POST[$checkbox] = (empty($_POST[$checkbox]) || !isset($_POST[$checkbox])) ? 0 : 1;
}
/**
* Escape all the posted values on a single function.
* Defined on functions.php
*/
$keys = array_keys($_POST);
$options_total = count($keys);
$updated = 0;
for ($j = 0; $j < $options_total; $j++) {
$save = $dbh->prepare( "UPDATE " . TABLE_OPTIONS . " SET value=:value WHERE name=:name" );
$save->bindParam(':value', $_POST[$keys[$j]]);
$save->bindParam(':name', $keys[$j]);
$save->execute();
$updated++;
}
if ($updated > 0){
$query_state = '1';
}
else {
$query_state = '2';
}
/** Redirect so the options are reflected immediatly */
while (ob_get_level()) ob_end_clean();
$section_redirect = html_output($_POST['section']);
$location = BASE_URI . 'email-templates.php?section=' . $section_redirect;
if ( !empty( $query_state ) ) {
$location .= '&status=' . $query_state;
}
header("Location: $location");
die();
}
?>
<div class="col-xs-12 col-sm-12 col-lg-6">
<?php
if (isset($_GET['status'])) {
switch ($_GET['status']) {
case '1':
$msg = __('Options updated succesfuly.','cftp_admin');
echo system_message('ok',$msg);
break;
case '2':
$msg = __('There was an error. Please try again.','cftp_admin');
echo system_message('error',$msg);
break;
}
}
?>
<div class="white-box">
<div class="white-box-interior">
<?php
$href_string = ' ' . __('(to be used as href on a link tag)','cftp_admin');
$options_groups = array(
'new_files_for_client' => array(
'subject_checkbox' => 'email_new_file_by_user_subject_customize',
'subject' => 'email_new_file_by_user_subject',
'body_checkbox' => 'email_new_file_by_user_customize',
'body_textarea' => 'email_new_file_by_user_text',
'description' => __('This email will be sent to a client whenever a new file has been assigned to his account.','cftp_admin'),
'subject_check' => EMAILS_FILE_BY_USER_USE_SUBJECT_CUSTOM,
'subject_text' => EMAILS_FILE_BY_USER_SUBJECT,
'body_check' => EMAILS_FILE_BY_USER_USE_CUSTOM,
'body_text' => EMAILS_FILE_BY_USER_TEXT,
'tags' => array(
'%FILES%' => __('Shows the list of files','cftp_admin'),
'%URI%' => __('The login link','cftp_admin') . $href_string,
),
'default_text' => EMAIL_TEMPLATE_NEW_FILE_BY_USER,
),
'new_file_by_client' => array(
'subject_checkbox' => 'email_new_file_by_client_subject_customize',
'subject' => 'email_new_file_by_client_subject',
'body_checkbox' => 'email_new_file_by_client_customize',
'body_textarea' => 'email_new_file_by_client_text',
'description' => __('This email will be sent to the system administrator whenever a client uploads a new file.','cftp_admin'),
'subject_check' => EMAILS_FILE_BY_CLIENT_USE_SUBJECT_CUSTOM,
'subject_text' => EMAILS_FILE_BY_CLIENT_SUBJECT,
'body_check' => EMAILS_FILE_BY_CLIENT_USE_CUSTOM,
'body_text' => EMAILS_FILE_BY_CLIENT_TEXT,
'tags' => array(
'%FILES%' => __('Shows the list of files','cftp_admin'),
'%URI%' => __('The login link','cftp_admin') . $href_string,
),
'default_text' => EMAIL_TEMPLATE_NEW_FILE_BY_CLIENT,
),
'new_client' => array(
'subject_checkbox' => 'email_new_client_by_user_subject_customize',
'subject' => 'email_new_client_by_user_subject',
'body_checkbox' => 'email_new_client_by_user_customize',
'body_textarea' => 'email_new_client_by_user_text',
'description' => __('This email will be sent to the new client after an administrator has created his new account. It would be best to include the log in details (username and password).','cftp_admin'),
'subject_check' => EMAILS_CLIENT_BY_USER_USE_SUBJECT_CUSTOM,
'subject_text' => EMAILS_CLIENT_BY_USER_SUBJECT,
'body_check' => EMAILS_CLIENT_BY_USER_USE_CUSTOM,
'body_text' => EMAILS_CLIENT_BY_USER_TEXT,
'tags' => array(
'%USERNAME%' => __('The new username for this account','cftp_admin'),
'%PASSWORD%' => __('The new password for this account','cftp_admin'),
'%URI%' => __('The login link','cftp_admin') . $href_string,
),
'default_text' => EMAIL_TEMPLATE_NEW_CLIENT,
),
'new_client_self' => array(
'subject_checkbox' => 'email_new_client_by_self_subject_customize',
'subject' => 'email_new_client_by_self_subject',
'body_checkbox' => 'email_new_client_by_self_customize',
'body_textarea' => 'email_new_client_by_self_text',
'description' => __('This email will be sent to the system administrator after a new client has created a new account for himself.','cftp_admin'),
'subject_check' => EMAILS_CLIENT_BY_SELF_USE_SUBJECT_CUSTOM,
'subject_text' => EMAILS_CLIENT_BY_SELF_SUBJECT,
'body_check' => EMAILS_CLIENT_BY_SELF_USE_CUSTOM,
'body_text' => EMAILS_CLIENT_BY_SELF_TEXT,
'tags' => array(
'%FULLNAME%' => __('The full name the client registered with','cftp_admin'),
'%USERNAME%' => __('The new username for this account','cftp_admin'),
'%URI%' => __('The login link','cftp_admin') . $href_string,
'%GROUPS_REQUESTS%' => __('List of groups that the client requests membership to','cftp_admin'),
),
'default_text' => EMAIL_TEMPLATE_NEW_CLIENT_SELF,
),
'client_approve' => array(
'subject_checkbox' => 'email_account_approve_subject_customize',
'subject' => 'email_account_approve_subject',
'body_checkbox' => 'email_account_approve_customize',
'body_textarea' => 'email_account_approve_text',
'description' => __('This email will be sent to a client that requested an account if it gets approved. Group membership requests are also mentioned on the email, separated by their approval status.','cftp_admin'),
'subject_check' => EMAILS_ACCOUNT_APPROVE_USE_SUBJECT_CUSTOM,
'subject_text' => EMAILS_ACCOUNT_APPROVE_SUBJECT,
'body_check' => EMAILS_ACCOUNT_APPROVE_USE_CUSTOM,
'body_text' => EMAILS_ACCOUNT_APPROVE_TEXT,
'tags' => array(
'%GROUPS_APPROVED%' => __('List of approved group memberships','cftp_admin'),
'%GROUPS_DENIED%' => __('List of denied group memberships','cftp_admin'),
'%URI%' => __('The login link','cftp_admin') . $href_string,
),
'default_text' => EMAIL_TEMPLATE_ACCOUNT_APPROVE,
),
'client_deny' => array(
'subject_checkbox' => 'email_account_deny_subject_customize',
'subject' => 'email_account_deny_subject',
'body_checkbox' => 'email_account_deny_customize',
'body_textarea' => 'email_account_deny_text',
'description' => __('This email will be sent to a client that requested an account if it gets denied. All group membership requests for this account are denied automatically.','cftp_admin'),
'subject_check' => EMAILS_ACCOUNT_DENY_USE_SUBJECT_CUSTOM,
'subject_text' => EMAILS_ACCOUNT_DENY_SUBJECT,
'body_check' => EMAILS_ACCOUNT_DENY_USE_CUSTOM,
'body_text' => EMAILS_ACCOUNT_DENY_TEXT,
'tags' => array(
),
'default_text' => EMAIL_TEMPLATE_ACCOUNT_DENY,
),
'new_user' => array(
'subject_checkbox' => 'email_new_user_subject_customize',
'subject' => 'email_new_user_subject',
'body_checkbox' => 'email_new_user_customize',
'body_textarea' => 'email_new_user_text',
'description' => __('This email will be sent to the new system user after an administrator has created his new account. It would be best to include the log in details (username and password).','cftp_admin'),
'subject_check' => EMAILS_NEW_USER_USE_SUBJECT_CUSTOM,
'subject_text' => EMAILS_NEW_USER_SUBJECT,
'body_check' => EMAILS_NEW_USER_USE_CUSTOM,
'body_text' => EMAILS_NEW_USER_TEXT,
'tags' => array(
'%USERNAME%' => __('The new username for this account','cftp_admin'),
'%PASSWORD%' => __('The new password for this account','cftp_admin'),
'%URI%' => __('The login link','cftp_admin') . $href_string,
),
'default_text' => EMAIL_TEMPLATE_NEW_USER,
),
'password_reset' => array(
'subject_checkbox' => 'email_pass_reset_subject_customize',
'subject' => 'email_pass_reset_subject',
'body_checkbox' => 'email_pass_reset_customize',
'body_textarea' => 'email_pass_reset_text',
'description' => __('This email will be sent to a user or client when they try to reset their password.','cftp_admin'),
'subject_check' => EMAILS_PASS_RESET_USE_SUBJECT_CUSTOM,
'subject_text' => EMAILS_PASS_RESET_SUBJECT,
'body_check' => EMAILS_PASS_RESET_USE_CUSTOM,
'body_text' => EMAILS_PASS_RESET_TEXT,
'tags' => array(
'%USERNAME%' => __('The username for this account','cftp_admin'),
'%TOKEN%' => __('The text string unique to this request. Must be included somewhere.','cftp_admin'),
'%URI%' => __('The link to continue the process','cftp_admin') . $href_string,
),
'default_text' => EMAIL_TEMPLATE_PASSWORD_RESET,
),
);
?>
<form action="email-templates.php" name="templatesform" method="post" enctype="multipart/form-data" class="form-horizontal">
<input type="hidden" name="section" value="<?php echo $section; ?>">
<?php
/** Header and footer options */
if ( $section == 'header_footer' ) {
?>
<p class="text-warning"><?php _e('Here you set up the header and footer of every email, or use the default ones available with the system. Use this to customize each part and include, for example, your own logo and markup.','cftp_admin'); ?></p>
<p class="text-warning"><?php _e("Do not forget to also include -and close accordingly- the basic structural HTML tags (DOCTYPE, HTML, HEADER, BODY).",'cftp_admin'); ?></p>
<div class="options_divide"></div>
<div class="form-group">
<div class="col-sm-12">
<label for="email_header_footer_customize">
<input type="checkbox" value="1" id="email_header_footer_customize" name="email_header_footer_customize" <?php echo (EMAILS_HEADER_FOOTER_CUSTOM == 1) ? 'checked="checked"' : ''; ?> /> <?php _e('Use custom header / footer','cftp_admin'); ?>
</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label for="email_header_text"><?php _e('Header','cftp_admin'); ?></label>
<textarea name="email_header_text" id="email_header_text" class="form-control textarea_high"><?php echo EMAILS_HEADER_TEXT; ?></textarea>
<p class="field_note"><?php _e('You can use HTML tags here.','cftp_admin'); ?></p>
</div>
</div>
<div class="preview_button">
<button type="button" class="btn btn-default load_default" data-textarea="email_header_text" data-file="<?php echo EMAIL_TEMPLATE_HEADER; ?>"><?php _e('Replace with default','cftp_admin'); ?></button>
</div>
<hr />
<div class="form-group">
<div class="col-sm-12">
<label for="email_footer_text"><?php _e('Footer','cftp_admin'); ?></label>
<textarea name="email_footer_text" id="email_footer_text" class="form-control textarea_high"><?php echo EMAILS_FOOTER_TEXT; ?></textarea>
<p class="field_note"><?php _e('You can use HTML tags here.','cftp_admin'); ?></p>
</div>
</div>
<div class="preview_button">
<button type="button" class="btn btn-default load_default" data-textarea="email_footer_text" data-file="<?php echo EMAIL_TEMPLATE_FOOTER; ?>"><?php _e('Replace with default','cftp_admin'); ?></button>
</div>
<?php
}
/** All other templates */
if ( array_key_exists( $section, $options_groups ) ) {
$group = $options_groups[$section];
?>
<p class="text-warning"><?php echo $group['description']; ?></p>
<div class="options_divide"></div>
<div class="form-group">
<div class="col-sm-12">
<label for="<?php echo $group['subject_checkbox']; ?>">
<input type="checkbox" value="1" name="<?php echo $group['subject_checkbox']; ?>" id="<?php echo $group['subject_checkbox']; ?>" class="checkbox_options" <?php echo ($group['subject_check'] == 1) ? 'checked="checked"' : ''; ?> /> <?php _e('Use custom subject','cftp_admin'); ?>
</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input type="text" name="<?php echo $group['subject']; ?>" id="<?php echo $group['subject']; ?>" class="form-control" placeholder="<?php _e('Add your custom subject','cftp_admin'); ?>" value="<?php echo $group['subject_text']; ?>" />
</div>
</div>
<div class="options_divide"></div>
<div class="form-group">
<div class="col-sm-12">
<label for="<?php echo $group['body_checkbox']; ?>">
<input type="checkbox" value="1" name="<?php echo $group['body_checkbox']; ?>" id="<?php echo $group['body_checkbox']; ?>" class="checkbox_options" <?php echo ($group['body_check'] == 1) ? 'checked="checked"' : ''; ?> /> <?php _e('Use custom template','cftp_admin'); ?>
</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label for="<?php echo $group['body_textarea']; ?>"><?php _e('Template text','cftp_admin'); ?></label>
<textarea name="<?php echo $group['body_textarea']; ?>" id="<?php echo $group['body_textarea']; ?>" class="form-control textarea_high"><?php echo $group['body_text']; ?></textarea>
<p class="field_note"><?php _e('You can use HTML tags here.','cftp_admin'); ?></p>
</div>
</div>
<?php
if (!empty($group['tags'])) {
?>
<p><strong><?php _e("The following tags can be used on this e-mails' body.",'cftp_admin'); ?></strong></p>
<ul>
<?php
foreach ($group['tags'] as $tag => $description) {
?>
<li><i class="icon-ok"></i> <strong><?php echo $tag; ?></strong>: <?php echo $description; ?></li>
<?php
}
?>
</ul>
<?php
}
?>
<hr />
<div class="preview_button">
<button type="button" class="btn btn-default load_default" data-textarea="<?php echo $group['body_textarea']; ?>" data-file="<?php echo $group['default_text']; ?>"><?php _e('Replace with default','cftp_admin'); ?></button>
<button type="button" data-preview="<?php echo $section; ?>" class="btn btn-wide btn-primary preview"><?php _e('Preview this template','cftp_admin'); ?></button>
<?php
$message = __("Before trying this function, please save your changes to see them reflected on the preview.",'cftp_admin');
echo system_message('info', $message);
?>
</div>
<?php
}
?>
<div class="after_form_buttons">
<button type="submit" name="submit" class="btn btn-wide btn-primary empty"><?php _e('Save options','cftp_admin'); ?></button>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(e) {
$('.load_default').click(function(e) {
e.preventDefault();
var file = jQuery(this).data('file');
var textarea = '#'+jQuery(this).data('textarea');
var accept = confirm('<?php _e('Please confirm: replace the custom template text with the default one?','cftp_admin'); ?>');
if ( accept ) {
$.ajax({
url: "emails/"+file,
async: false,
cache: false,
success: function (data){
$(textarea).text(data);
},
error: function() {
alert("<?php _e('Error: the content could not be loaded','cftp_admin'); ?>");
}
});
}
});
$('.preview').click(function(e) {
e.preventDefault();
var type = jQuery(this).data('preview');
var url = '<?php echo BASE_URI; ?>email-preview.php?t=' + type;
window.open(url, "previewWindow", "width=800,height=600,scrollbars=yes");
});
});
</script>
<?php
include('footer.php');