phpBB
Statistics
| Revision:

root / tags / release_2_0_2 / phpBB / includes / usercp_email.php

History | View | Annotate | Download (6.2 kB)

1
<?php
2
/***************************************************************************
3
 *                             usercp_email.php 
4
 *                            -------------------
5
 *   begin                : Saturday, Feb 13, 2001
6
 *   copyright            : (C) 2001 The phpBB Group
7
 *   email                : support@phpbb.com
8
 *
9
 *   $Id: usercp_email.php 2815 2002-08-03 22:24:13Z psotfx $
10
 *
11
 *
12
 ***************************************************************************/
13
14
/***************************************************************************
15
 *
16
 *   This program is free software; you can redistribute it and/or modify
17
 *   it under the terms of the GNU General Public License as published by
18
 *   the Free Software Foundation; either version 2 of the License, or
19
 *   (at your option) any later version.
20
 *
21
 *
22
 ***************************************************************************/
23
24
if ( !defined('IN_PHPBB') )
25
{
26
        die("Hacking attempt");
27
        exit;
28
}
29
30
if ( !empty($HTTP_GET_VARS[POST_USERS_URL]) || !empty($HTTP_POST_VARS[POST_USERS_URL]) )
31
{
32
        $user_id = ( !empty($HTTP_GET_VARS[POST_USERS_URL]) ) ? intval($HTTP_GET_VARS[POST_USERS_URL]) : intval($HTTP_POST_VARS[POST_USERS_URL]);
33
}
34
else
35
{
36
        message_die(GENERAL_MESSAGE, $lang['No_user_specified']);
37
}
38
39
if ( !$userdata['session_logged_in'] )
40
{
41
        header('Location: ' . append_sid("login.$phpEx?redirect=profile.$phpEx&mode=email&" . POST_USERS_URL . "=$user_id", true));
42
        exit;
43
}
44
45
$sql = "SELECT username, user_email, user_viewemail, user_lang  
46
        FROM " . USERS_TABLE . " 
47
        WHERE user_id = $user_id";
48
if ( $result = $db->sql_query($sql) )
49
{
50
        $row = $db->sql_fetchrow($result);
51
52
        $username = $row['username'];
53
        $user_email = $row['user_email']; 
54
        $user_lang = $row['user_lang'];
55
56
        if ( $row['user_viewemail'] || $userdata['user_level'] == ADMIN )
57
        {
58
                if ( time() - $userdata['user_emailtime'] < $board_config['flood_interval'] )
59
                {
60
                        message_die(GENERAL_MESSAGE, $lang['Flood_email_limit']);
61
                }
62
63
                if ( isset($HTTP_POST_VARS['submit']) )
64
                {
65
                        $error = FALSE;
66
67
                        if ( !empty($HTTP_POST_VARS['subject']) )
68
                        {
69
                                $subject = trim(stripslashes($HTTP_POST_VARS['subject']));
70
                        }
71
                        else
72
                        {
73
                                $error = TRUE;
74
                                $error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Empty_subject_email'] : $lang['Empty_subject_email'];
75
                        }
76
77
                        if ( !empty($HTTP_POST_VARS['message']) )
78
                        {
79
                                $message = trim(stripslashes($HTTP_POST_VARS['message']));
80
                        }
81
                        else
82
                        {
83
                                $error = TRUE;
84
                                $error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Empty_message_email'] : $lang['Empty_message_email'];
85
                        }
86
87
                        if ( !$error )
88
                        {
89
                                $sql = "UPDATE " . USERS_TABLE . " 
90
                                        SET user_emailtime = " . time() . " 
91
                                        WHERE user_id = " . $userdata['user_id'];
92
                                if ( $result = $db->sql_query($sql) )
93
                                {
94
                                        include($phpbb_root_path . 'includes/emailer.'.$phpEx);
95
                                        $emailer = new emailer($board_config['smtp_delivery']);
96
97
                                        $email_headers = 'Return-Path: ' . $userdata['user_email'] . "\nFrom: " . $userdata['user_email'] . "\n";
98
                                        $email_headers .= 'X-AntiAbuse: Board servername - ' . $server_name . "\n";
99
                                        $email_headers .= 'X-AntiAbuse: User_id - ' . $userdata['user_id'] . "\n";
100
                                        $email_headers .= 'X-AntiAbuse: Username - ' . $userdata['username'] . "\n";
101
                                        $email_headers .= 'X-AntiAbuse: User IP - ' . decode_ip($user_ip) . "\n";
102
103
                                        $emailer->use_template('profile_send_email', $user_lang);
104
                                        $emailer->email_address($user_email);
105
                                        $emailer->set_subject($subject);
106
                                        $emailer->extra_headers($email_headers);
107
108
                                        $emailer->assign_vars(array(
109
                                                'SITENAME' => $board_config['sitename'], 
110
                                                'BOARD_EMAIL' => $board_config['board_email'], 
111
                                                'FROM_USERNAME' => $userdata['username'], 
112
                                                'TO_USERNAME' => $username, 
113
                                                'MESSAGE' => $message)
114
                                        );
115
                                        $emailer->send();
116
                                        $emailer->reset();
117
118
                                        if ( !empty($HTTP_POST_VARS['cc_email']) )
119
                                        {
120
                                                $email_headers = 'Return-Path: ' . $userdata['user_email'] . "\nFrom: " . $userdata['user_email'] . "\n";
121
                                                $emailer->use_template('profile_send_email');
122
                                                $emailer->email_address($userdata['user_email']);
123
                                                $emailer->set_subject($subject);
124
                                                $emailer->extra_headers($email_headers);
125
126
                                                $emailer->assign_vars(array(
127
                                                        'SITENAME' => $board_config['sitename'], 
128
                                                        'BOARD_EMAIL' => $board_config['board_email'], 
129
                                                        'FROM_USERNAME' => $userdata['username'], 
130
                                                        'TO_USERNAME' => $username, 
131
                                                        'MESSAGE' => $message)
132
                                                );
133
                                                $emailer->send();
134
                                                $emailer->reset();
135
                                        }
136
137
                                        $template->assign_vars(array(
138
                                                'META' => '<meta http-equiv="refresh" content="5;url=' . append_sid("index.$phpEx") . '">')
139
                                        );
140
141
                                        $message = $lang['Email_sent'] . '<br /><br />' . sprintf($lang['Click_return_index'],  '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
142
143
                                        message_die(GENERAL_MESSAGE, $message);
144
                                }
145
                                else
146
                                {
147
                                        message_die(GENERAL_ERROR, 'Could not update last email time', '', __LINE__, __FILE__, $sql);
148
                                }
149
                        }
150
                }
151
152
                include($phpbb_root_path . 'includes/page_header.'.$phpEx);
153
154
                $template->set_filenames(array(
155
                        'body' => 'profile_send_email.tpl')
156
                );
157
                make_jumpbox('viewforum.'.$phpEx);
158
159
                if ( $error )
160
                {
161
                        $template->set_filenames(array(
162
                                'reg_header' => 'error_body.tpl')
163
                        );
164
                        $template->assign_vars(array(
165
                                'ERROR_MESSAGE' => $error_msg)
166
                        );
167
                        $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
168
                }
169
170
                $template->assign_vars(array(
171
                        'USERNAME' => $username,
172
173
                        'S_POST_ACTION' => append_sid("profile.$phpEx?&amp;mode=email&amp;" . POST_USERS_URL . "=$user_id"), 
174
175
                        'L_SEND_EMAIL_MSG' => $lang['Send_email_msg'], 
176
                        'L_RECIPIENT' => $lang['Recipient'], 
177
                        'L_SUBJECT' => $lang['Subject'],
178
                        'L_MESSAGE_BODY' => $lang['Message_body'], 
179
                        'L_MESSAGE_BODY_DESC' => $lang['Email_message_desc'], 
180
                        'L_EMPTY_SUBJECT_EMAIL' => $lang['Empty_subject_email'],
181
                        'L_EMPTY_MESSAGE_EMAIL' => $lang['Empty_message_email'],
182
                        'L_OPTIONS' => $lang['Options'],
183
                        'L_CC_EMAIL' => $lang['CC_email'], 
184
                        'L_SPELLCHECK' => $lang['Spellcheck'],
185
                        'L_SEND_EMAIL' => $lang['Send_email'])
186
                );
187
188
                $template->pparse('body');
189
190
                include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
191
        }
192
        else
193
        {
194
                message_die(GENERAL_MESSAGE, $lang['User_prevent_email']);
195
        }
196
}
197
else
198
{
199
        message_die(GENERAL_MESSAGE, $lang['User_not_exist']);
200
}
201
202
?>