-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathgo_mail.php
143 lines (134 loc) · 4.6 KB
/
go_mail.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
<?php
//Shortcode for Email input
add_shortcode( 'go_upload','go_file_input' );
function go_file_input( $atts, $content = null ) {
global $wpdb;
global $post;
$atts = shortcode_atts(
array(
'is_uploaded' => '0',
'status' => '1',
'user_id' => null,
'post_id' => null
),
$atts
);
$is_uploaded = (int) $atts['is_uploaded'];
$status = (int) $atts['status'];
$user_id = (int) $atts['user_id'];
$post_id = (int) $atts['post_id'];
if ( get_current_user_id() !== $user_id ) {
$user_id = get_current_user_id();
}
$table_go = "{$wpdb->prefix}go";
switch ( $status ) {
case ( 0 ):
$db_task_stage_upload_var = 'e_uploaded';
break;
case ( 1 ):
$db_task_stage_upload_var = 'a_uploaded';
break;
case ( 2 ):
$db_task_stage_upload_var = 'c_uploaded';
break;
case ( 3 ):
$db_task_stage_upload_var = 'm_uploaded';
break;
case ( 4 ):
$db_task_stage_upload_var = 'r_uploaded';
break;
}
if ( empty( $post_id ) || is_null( $post_id ) ) {
$post_id = $post->ID;
}
$allow_full_name = get_option( 'go_full_student_name_switch' );
if ( isset( $_FILES['go_attachment'] ) ) {
$user_info = get_userdata( $user_id );
$user_login = $user_info->user_login;
$first_name = trim( $user_info->first_name );
$last_name = trim( $user_info->last_name );
if ( $allow_full_name == 'On' ) {
$user_name = "{$first_name} {$last_name}";
} else {
$last_initial = substr( $last_name, 0, 1 );
$user_name = "{$first_name} {$last_initial}.";
}
$user_email = $user_info->user_email;
$user_role = $user_info->roles;
$task_title = $post->post_title;
$task_name = go_return_options( 'go_tasks_name' );
$to = get_option( 'go_admin_email', '' );
require( 'mail/class.phpmailer.php' );
$mail = new PHPMailer();
$mail->From = get_option( 'go_email_from', '[email protected]' );
$mail->FromName = $user_name;
$mail->AddAddress( $to );
$mail->Subject = "Upload: {$task_title} | {$user_name} {$user_login}";
$mail->Body = "{$user_email}\n\nUser comments: \n\t{$_POST['go_attachment_com']}";
$mail->WordWrap = 50;
// This loop will upload all the files you have attached to your email.
for ( $i = 0; $i < count( $_FILES['go_attachment'] ); $i++ ) {
if ( empty( $_FILES['go_attachment']['name'][ $i ] ) || empty( $_FILES['go_attachment']['tmp_name'][ $i ] ) ) {
continue;
}
$name = $_FILES['go_attachment']['name'][ $i ];
$path = $_FILES['go_attachment']['tmp_name'][ $i ];
// And attach it using attachment method of PHPmailer.
$mail->AddAttachment( $path, $name );
}
if( ! $mail->Send() ) {
if ( ( is_array( $user_role ) && in_array( 'administrator', $user_role ) ) || $user_role === 'administrator' ) {
return "<div id='go_mailer_error_msg'>{$mail->ErrorInfo}</div>";
} else {
return "
<div id='go_mailer_error_msg'>Message was not sent.</div>
<form id='go_upload_form' action='' method='post' enctype='multipart/form-data' uploaded='0'>
<div id='go_uploader'>
<input type='file' name='go_attachment[]'/>
<br/>
</div>
<button type='button' onClick='go_add_uploader();'>Attach More</button><br/>
Comments:
<br/>
<textarea name='go_attachment_com' style='width: 50%; height: 100px; resize: vertical;' placeholder='Enter any comments you have...'></textarea>
<br/>
<input type='submit' value='Submit'/>
</form>
";
}
} else {
$wpdb->update( $table_go, array( $db_task_stage_upload_var => 1), array( 'uid' => $user_id, 'post_id' => $post_id ) );
return "
<div id='go_mailer_confirm_msg'>Message was sent.</div>
<form id='go_upload_form' action='' method='post' enctype='multipart/form-data' uploaded='1'>
<div id='go_uploader'>
<input type='file' name='go_attachment[]'/>
<br/>
</div>
<button type='button' onClick='go_add_uploader();'>Attach More</button><br/>
Comments:
<br/>
<textarea name='go_attachment_com' style='width: 50%; height: 100px; resize: vertical;' placeholder='Enter any comments you have...'></textarea>
<br/>
<input type='submit' value='Submit'/>
</form>
";
}
} else {
return "
<form id='go_upload_form' action='' method='post' enctype='multipart/form-data' uploaded='{$is_uploaded}'>
<div id='go_uploader'>
<input type='file' name='go_attachment[]'/>
<br/>
</div>
<button type='button' onClick='go_add_uploader();'>Attach More</button><br/>
Comments:
<br/>
<textarea name='go_attachment_com' style='width: 50%; height: 100px; resize: vertical;' placeholder='Enter any comments you have...'></textarea>
<br/>
<input type='submit' value='Submit'/>
</form>
";
}
}
?>