1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-01-15 13:45:42 +0000 (Sun, 15 Jan 2006) $ |
---|
10 | // | last modifier : $Author: nikrou $ |
---|
11 | // | revision : $Revision: 1004 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | // +-----------------------------------------------------------------------+ |
---|
29 | // | initialization | |
---|
30 | // +-----------------------------------------------------------------------+ |
---|
31 | |
---|
32 | define('PHPWG_ROOT_PATH','./'); |
---|
33 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | functions | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | |
---|
39 | /** |
---|
40 | * sends an email, using PhpWebGallery specific informations |
---|
41 | */ |
---|
42 | function pwg_mail($to, $from, $infos = '') |
---|
43 | { |
---|
44 | global $conf; |
---|
45 | |
---|
46 | $headers = 'From: <'.$from.'>'."\n"; |
---|
47 | $headers.= 'Reply-To: '.$from."\n"; |
---|
48 | |
---|
49 | $options = '-f '.$from; |
---|
50 | |
---|
51 | $subject = l10n('password updated'); |
---|
52 | |
---|
53 | $content = $infos; |
---|
54 | $content.= "\n\n-- \nPhpWebGallery ".PHPWG_VERSION; |
---|
55 | |
---|
56 | if ($conf['mail_options']) |
---|
57 | { |
---|
58 | return mail($to, $subject, $content, $headers, $options); |
---|
59 | } |
---|
60 | else |
---|
61 | { |
---|
62 | return mail($to, $subject, $content, $headers); |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | // +-----------------------------------------------------------------------+ |
---|
67 | // | send a new password | |
---|
68 | // +-----------------------------------------------------------------------+ |
---|
69 | |
---|
70 | $page['errors'] = array(); |
---|
71 | $page['infos'] = array(); |
---|
72 | |
---|
73 | if (isset($_POST['submit'])) |
---|
74 | { |
---|
75 | // in case of error, creation of mailto link |
---|
76 | $query = ' |
---|
77 | SELECT '.$conf['user_fields']['email'].' |
---|
78 | FROM '.USERS_TABLE.' |
---|
79 | WHERE '.$conf['user_fields']['id'].' = '.$conf['webmaster_id'].' |
---|
80 | ;'; |
---|
81 | list($mail_webmaster) = mysql_fetch_array(pwg_query($query)); |
---|
82 | |
---|
83 | $mailto = |
---|
84 | '<a href="mailto:'.$mail_webmaster.'">' |
---|
85 | .l10n('Contact webmaster') |
---|
86 | .'</a>' |
---|
87 | ; |
---|
88 | |
---|
89 | if (isset($_POST['no_mail_address']) and $_POST['no_mail_address'] == 1) |
---|
90 | { |
---|
91 | array_push($page['infos'], l10n('Email address is missing')); |
---|
92 | array_push($page['infos'], $mailto); |
---|
93 | } |
---|
94 | else if (isset($_POST['mail_address']) and !empty($_POST['mail_address'])) |
---|
95 | { |
---|
96 | $mail_address = mysql_escape_string($_POST['mail_address']); |
---|
97 | |
---|
98 | $query = ' |
---|
99 | SELECT '.$conf['user_fields']['id'].' AS id |
---|
100 | , '.$conf['user_fields']['username'].' AS username |
---|
101 | , '.$conf['user_fields']['email'].' AS email |
---|
102 | FROM '.USERS_TABLE.' |
---|
103 | WHERE '.$conf['user_fields']['email'].' = \''.$mail_address.'\' |
---|
104 | ;'; |
---|
105 | $result = pwg_query($query); |
---|
106 | |
---|
107 | if (mysql_num_rows($result) > 0) |
---|
108 | { |
---|
109 | $error_on_mail = false; |
---|
110 | $datas = array(); |
---|
111 | |
---|
112 | while ($row = mysql_fetch_array($result)) |
---|
113 | { |
---|
114 | $new_password = generate_key(6); |
---|
115 | |
---|
116 | $infos = |
---|
117 | l10n('Username').': '.$row['username'] |
---|
118 | ."\n".l10n('Password').': '.$new_password |
---|
119 | ; |
---|
120 | |
---|
121 | if (pwg_mail($row['email'], $mail_webmaster, $infos)) |
---|
122 | { |
---|
123 | $data = |
---|
124 | array( |
---|
125 | $conf['user_fields']['id'] |
---|
126 | => $row['id'], |
---|
127 | |
---|
128 | $conf['user_fields']['password'] |
---|
129 | => $conf['pass_convert']($new_password) |
---|
130 | ); |
---|
131 | |
---|
132 | array_push($datas, $data); |
---|
133 | } |
---|
134 | else |
---|
135 | { |
---|
136 | $error_on_mail = true; |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | if ($error_on_mail) |
---|
141 | { |
---|
142 | array_push($page['errors'], l10n('Error sending email')); |
---|
143 | array_push($page['errors'], $mailto); |
---|
144 | } |
---|
145 | else |
---|
146 | { |
---|
147 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
148 | mass_updates( |
---|
149 | USERS_TABLE, |
---|
150 | array( |
---|
151 | 'primary' => array($conf['user_fields']['id']), |
---|
152 | 'update' => array($conf['user_fields']['password']) |
---|
153 | ), |
---|
154 | $datas |
---|
155 | ); |
---|
156 | |
---|
157 | array_push($page['infos'], l10n('New password sent by email')); |
---|
158 | } |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | array_push($page['errors'], l10n('No user matches this email address')); |
---|
163 | array_push($page['errors'], $mailto); |
---|
164 | } |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | // +-----------------------------------------------------------------------+ |
---|
169 | // | template initialization | |
---|
170 | // +-----------------------------------------------------------------------+ |
---|
171 | |
---|
172 | $title = l10n('Forgot your password?'); |
---|
173 | $page['body_id'] = 'thePasswordPage'; |
---|
174 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
175 | $template->set_filenames(array('password'=>'password.tpl')); |
---|
176 | |
---|
177 | $template->assign_vars( |
---|
178 | array( |
---|
179 | 'U_HOME' => PHPWG_ROOT_PATH.'category.php' |
---|
180 | ) |
---|
181 | ); |
---|
182 | |
---|
183 | // +-----------------------------------------------------------------------+ |
---|
184 | // | infos & errors display | |
---|
185 | // +-----------------------------------------------------------------------+ |
---|
186 | |
---|
187 | if (count($page['errors']) != 0) |
---|
188 | { |
---|
189 | $template->assign_block_vars('errors', array()); |
---|
190 | |
---|
191 | foreach ($page['errors'] as $error) |
---|
192 | { |
---|
193 | $template->assign_block_vars( |
---|
194 | 'errors.error', |
---|
195 | array( |
---|
196 | 'ERROR' => $error |
---|
197 | ) |
---|
198 | ); |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | if (count($page['infos']) != 0) |
---|
203 | { |
---|
204 | $template->assign_block_vars('infos', array()); |
---|
205 | |
---|
206 | foreach ($page['infos'] as $info) |
---|
207 | { |
---|
208 | $template->assign_block_vars( |
---|
209 | 'infos.info', |
---|
210 | array( |
---|
211 | 'INFO' => $info |
---|
212 | ) |
---|
213 | ); |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | // +-----------------------------------------------------------------------+ |
---|
218 | // | html code display | |
---|
219 | // +-----------------------------------------------------------------------+ |
---|
220 | |
---|
221 | $template->parse('password'); |
---|
222 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
223 | |
---|
224 | ?> |
---|