]>
Commit | Line | Data |
---|---|---|
66665fba | 1 | <?php |
46da73c2 | 2 | class Pref_Users extends Protected_Handler { |
66665fba AD |
3 | |
4 | function before() { | |
5 | if (parent::before()) { | |
6 | if ($_SESSION["access_level"] < 10) { | |
7 | print __("Your access level is insufficient to open this tab."); | |
8 | return false; | |
9 | } | |
10 | return true; | |
11 | } | |
12 | return false; | |
13 | } | |
14 | ||
15 | function userdetails() { | |
16 | ||
17 | header("Content-Type: text/xml"); | |
18 | print "<dlg>"; | |
19 | ||
20 | $uid = sprintf("%d", $_REQUEST["id"]); | |
21 | ||
22 | print "<title>".__('User details')."</title>"; | |
23 | ||
24 | print "<content><![CDATA["; | |
25 | ||
26 | $result = db_query($this->link, "SELECT login, | |
27 | ".SUBSTRING_FOR_DATE."(last_login,1,16) AS last_login, | |
28 | access_level, | |
29 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
30 | WHERE owner_uid = id) AS stored_articles, | |
31 | ".SUBSTRING_FOR_DATE."(created,1,16) AS created | |
32 | FROM ttrss_users | |
33 | WHERE id = '$uid'"); | |
34 | ||
35 | if (db_num_rows($result) == 0) { | |
36 | print "<h1>".__('User not found')."</h1>"; | |
37 | return; | |
38 | } | |
39 | ||
40 | // print "<h1>User Details</h1>"; | |
41 | ||
42 | $login = db_fetch_result($result, 0, "login"); | |
43 | ||
44 | print "<table width='100%'>"; | |
45 | ||
46 | $last_login = make_local_datetime($this->link, | |
47 | db_fetch_result($result, 0, "last_login"), true); | |
48 | ||
49 | $created = make_local_datetime($this->link, | |
50 | db_fetch_result($result, 0, "created"), true); | |
51 | ||
52 | $access_level = db_fetch_result($result, 0, "access_level"); | |
53 | $stored_articles = db_fetch_result($result, 0, "stored_articles"); | |
54 | ||
55 | print "<tr><td>".__('Registered')."</td><td>$created</td></tr>"; | |
56 | print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>"; | |
57 | ||
58 | $result = db_query($this->link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds | |
59 | WHERE owner_uid = '$uid'"); | |
60 | ||
61 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
62 | ||
63 | print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>"; | |
64 | ||
65 | print "</table>"; | |
66 | ||
67 | print "<h1>".__('Subscribed feeds')."</h1>"; | |
68 | ||
69 | $result = db_query($this->link, "SELECT id,title,site_url FROM ttrss_feeds | |
70 | WHERE owner_uid = '$uid' ORDER BY title"); | |
71 | ||
72 | print "<ul class=\"userFeedList\">"; | |
73 | ||
74 | $row_class = "odd"; | |
75 | ||
76 | while ($line = db_fetch_assoc($result)) { | |
77 | ||
78 | $icon_file = ICONS_URL."/".$line["id"].".ico"; | |
79 | ||
80 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
81 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">"; | |
82 | } else { | |
83 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
84 | } | |
85 | ||
86 | print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>"; | |
87 | ||
88 | $row_class = $row_class == "even" ? "odd" : "even"; | |
89 | ||
90 | } | |
91 | ||
92 | if (db_num_rows($result) < $num_feeds) { | |
93 | // FIXME - add link to show ALL subscribed feeds here somewhere | |
94 | print "<li><img | |
95 | class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>"; | |
96 | } | |
97 | ||
98 | print "</ul>"; | |
99 | ||
100 | print "<div align='center'> | |
101 | <button onclick=\"closeInfoBox()\">".__("Close this window"). | |
102 | "</button></div>"; | |
103 | ||
104 | print "]]></content></dlg>"; | |
105 | ||
106 | return; | |
107 | } | |
108 | ||
109 | function edit() { | |
110 | global $access_level_names; | |
111 | ||
112 | header("Content-Type: text/xml"); | |
113 | ||
114 | $id = db_escape_string($_REQUEST["id"]); | |
115 | ||
116 | print "<dlg id=\"$method\">"; | |
117 | print "<title>".__('User Editor')."</title>"; | |
118 | print "<content><![CDATA["; | |
119 | ||
120 | print "<form id=\"user_edit_form\" onsubmit='return false'>"; | |
121 | ||
122 | print "<input type=\"hidden\" name=\"id\" value=\"$id\">"; | |
123 | print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">"; | |
124 | print "<input type=\"hidden\" name=\"method\" value=\"editSave\">"; | |
125 | ||
126 | $result = db_query($this->link, "SELECT * FROM ttrss_users WHERE id = '$id'"); | |
127 | ||
128 | $login = db_fetch_result($result, 0, "login"); | |
129 | $access_level = db_fetch_result($result, 0, "access_level"); | |
130 | $email = db_fetch_result($result, 0, "email"); | |
131 | ||
132 | $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : ""; | |
133 | ||
134 | print "<div class=\"dlgSec\">".__("User")."</div>"; | |
135 | print "<div class=\"dlgSecCont\">"; | |
136 | ||
137 | if ($sel_disabled) { | |
138 | print "<input type=\"hidden\" name=\"login\" value=\"$login\">"; | |
139 | print "<input size=\"30\" style=\"font-size : 16px\" | |
140 | onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled | |
141 | value=\"$login\">"; | |
142 | } else { | |
143 | print "<input size=\"30\" style=\"font-size : 16px\" | |
144 | onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled | |
145 | name=\"login\" value=\"$login\">"; | |
146 | } | |
147 | ||
148 | print "</div>"; | |
149 | ||
150 | print "<div class=\"dlgSec\">".__("Authentication")."</div>"; | |
151 | print "<div class=\"dlgSecCont\">"; | |
152 | ||
153 | print __('Access level: ') . " "; | |
154 | ||
155 | if (!$sel_disabled) { | |
156 | print_select_hash("access_level", $access_level, $access_level_names, | |
157 | $sel_disabled); | |
158 | } else { | |
159 | print_select_hash("", $access_level, $access_level_names, | |
160 | $sel_disabled); | |
161 | print "<input type=\"hidden\" name=\"access_level\" value=\"$access_level\">"; | |
162 | } | |
163 | ||
164 | print "<br/>"; | |
165 | ||
166 | print __('Change password to') . | |
167 | " <input size=\"20\" onkeypress=\"return filterCR(event, userEditSave)\" | |
168 | name=\"password\">"; | |
169 | ||
170 | print "</div>"; | |
171 | ||
172 | print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
173 | print "<div class=\"dlgSecCont\">"; | |
174 | ||
175 | print __('E-mail: '). | |
176 | " <input size=\"30\" name=\"email\" onkeypress=\"return filterCR(event, userEditSave)\" | |
177 | value=\"$email\">"; | |
178 | ||
179 | print "</div>"; | |
180 | ||
181 | print "</table>"; | |
182 | ||
183 | print "</form>"; | |
184 | ||
185 | print "<div class=\"dlgButtons\"> | |
186 | <button onclick=\"return userEditSave()\">". | |
187 | __('Save')."</button> | |
188 | <button onclick=\"return userEditCancel()\">". | |
189 | __('Cancel')."</button></div>"; | |
190 | ||
191 | print "]]></content></dlg>"; | |
192 | ||
193 | return; | |
194 | } | |
195 | ||
196 | function editSave() { | |
197 | $login = db_escape_string(trim($_REQUEST["login"])); | |
198 | $uid = db_escape_string($_REQUEST["id"]); | |
199 | $access_level = (int) $_REQUEST["access_level"]; | |
200 | $email = db_escape_string(trim($_REQUEST["email"])); | |
201 | $password = db_escape_string(trim($_REQUEST["password"])); | |
202 | ||
203 | if ($password) { | |
204 | $pwd_hash = encrypt_password($password, $login); | |
205 | $pass_query_part = "pwd_hash = '$pwd_hash', "; | |
206 | } else { | |
207 | $pass_query_part = ""; | |
208 | } | |
209 | ||
210 | db_query($this->link, "UPDATE ttrss_users SET $pass_query_part login = '$login', | |
211 | access_level = '$access_level', email = '$email' WHERE id = '$uid'"); | |
212 | ||
213 | } | |
214 | ||
215 | function remove() { | |
216 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
217 | ||
218 | foreach ($ids as $id) { | |
219 | if ($id != $_SESSION["uid"] && $id != 1) { | |
220 | db_query($this->link, "DELETE FROM ttrss_tags WHERE owner_uid = '$id'"); | |
221 | db_query($this->link, "DELETE FROM ttrss_feeds WHERE owner_uid = '$id'"); | |
222 | db_query($this->link, "DELETE FROM ttrss_users WHERE id = '$id'"); | |
223 | } | |
224 | } | |
225 | } | |
226 | ||
227 | function add() { | |
228 | ||
229 | $login = db_escape_string(trim($_REQUEST["login"])); | |
230 | $tmp_user_pwd = make_password(8); | |
231 | $pwd_hash = encrypt_password($tmp_user_pwd, $login); | |
232 | ||
233 | $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE | |
234 | login = '$login'"); | |
235 | ||
236 | if (db_num_rows($result) == 0) { | |
237 | ||
238 | db_query($this->link, "INSERT INTO ttrss_users | |
239 | (login,pwd_hash,access_level,last_login,created) | |
240 | VALUES ('$login', '$pwd_hash', 0, null, NOW())"); | |
241 | ||
242 | ||
243 | $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE | |
244 | login = '$login' AND pwd_hash = '$pwd_hash'"); | |
245 | ||
246 | if (db_num_rows($result) == 1) { | |
247 | ||
248 | $new_uid = db_fetch_result($result, 0, "id"); | |
249 | ||
250 | print format_notice(T_sprintf("Added user <b>%s</b> with password <b>%s</b>", | |
251 | $login, $tmp_user_pwd)); | |
252 | ||
253 | initialize_user($this->link, $new_uid); | |
254 | ||
255 | } else { | |
256 | ||
257 | print format_warning(T_sprintf("Could not create user <b>%s</b>", $login)); | |
258 | ||
259 | } | |
260 | } else { | |
261 | print format_warning(T_sprintf("User <b>%s</b> already exists.", $login)); | |
262 | } | |
263 | } | |
264 | ||
265 | function resetPass() { | |
266 | ||
267 | $uid = db_escape_string($_REQUEST["id"]); | |
268 | ||
269 | $result = db_query($this->link, "SELECT login,email | |
270 | FROM ttrss_users WHERE id = '$uid'"); | |
271 | ||
272 | $login = db_fetch_result($result, 0, "login"); | |
273 | $email = db_fetch_result($result, 0, "email"); | |
274 | $tmp_user_pwd = make_password(8); | |
275 | $pwd_hash = encrypt_password($tmp_user_pwd, $login); | |
276 | ||
277 | db_query($this->link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' | |
278 | WHERE id = '$uid'"); | |
279 | ||
280 | print T_sprintf("Changed password of user <b>%s</b> | |
281 | to <b>%s</b>", $login, $tmp_user_pwd); | |
282 | ||
283 | require_once 'lib/phpmailer/class.phpmailer.php'; | |
284 | ||
285 | if ($email) { | |
286 | print " "; | |
287 | print T_sprintf("Notifying <b>%s</b>.", $email); | |
288 | ||
289 | require_once "lib/MiniTemplator.class.php"; | |
290 | ||
291 | $tpl = new MiniTemplator; | |
292 | ||
293 | $tpl->readTemplateFromFile("templates/resetpass_template.txt"); | |
294 | ||
295 | $tpl->setVariable('LOGIN', $login); | |
296 | $tpl->setVariable('NEWPASS', $tmp_user_pwd); | |
297 | ||
298 | $tpl->addBlock('message'); | |
299 | ||
300 | $message = ""; | |
301 | ||
302 | $tpl->generateOutputToString($message); | |
303 | ||
304 | $mail = new PHPMailer(); | |
305 | ||
306 | $mail->PluginDir = "lib/phpmailer/"; | |
307 | $mail->SetLanguage("en", "lib/phpmailer/language/"); | |
308 | ||
309 | $mail->CharSet = "UTF-8"; | |
310 | ||
09e8bdfd AD |
311 | $mail->From = SMTP_FROM_ADDRESS; |
312 | $mail->FromName = SMTP_FROM_NAME; | |
66665fba AD |
313 | $mail->AddAddress($email, $login); |
314 | ||
09e8bdfd AD |
315 | if (SMTP_HOST) { |
316 | $mail->Host = SMTP_HOST; | |
66665fba | 317 | $mail->Mailer = "smtp"; |
09e8bdfd AD |
318 | $mail->SMTPAuth = SMTP_LOGIN != ''; |
319 | $mail->Username = SMTP_LOGIN; | |
320 | $mail->Password = SMTP_PASSWORD; | |
66665fba AD |
321 | } |
322 | ||
323 | $mail->IsHTML(false); | |
324 | $mail->Subject = __("[tt-rss] Password change notification"); | |
325 | $mail->Body = $message; | |
326 | ||
327 | $rc = $mail->Send(); | |
328 | ||
329 | if (!$rc) print_error($mail->ErrorInfo); | |
330 | } | |
331 | ||
332 | print "</div>"; | |
333 | } | |
334 | ||
335 | function index() { | |
336 | ||
337 | global $access_level_names; | |
338 | ||
339 | print "<div id=\"pref-user-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">"; | |
340 | print "<div id=\"pref-user-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">"; | |
341 | ||
342 | print "<div id=\"pref-user-toolbar\" dojoType=\"dijit.Toolbar\">"; | |
343 | ||
344 | $user_search = db_escape_string($_REQUEST["search"]); | |
345 | ||
346 | if (array_key_exists("search", $_REQUEST)) { | |
347 | $_SESSION["prefs_user_search"] = $user_search; | |
348 | } else { | |
349 | $user_search = $_SESSION["prefs_user_search"]; | |
350 | } | |
351 | ||
352 | print "<div style='float : right; padding-right : 4px;'> | |
353 | <input dojoType=\"dijit.form.TextBox\" id=\"user_search\" size=\"20\" type=\"search\" | |
354 | value=\"$user_search\"> | |
355 | <button dojoType=\"dijit.form.Button\" onclick=\"javascript:updateUsersList()\">". | |
356 | __('Search')."</button> | |
357 | </div>"; | |
358 | ||
359 | $sort = db_escape_string($_REQUEST["sort"]); | |
360 | ||
361 | if (!$sort || $sort == "undefined") { | |
362 | $sort = "login"; | |
363 | } | |
364 | ||
365 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
366 | "<span>" . __('Select')."</span>"; | |
367 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
368 | print "<div onclick=\"selectTableRows('prefUserList', 'all')\" | |
369 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
370 | print "<div onclick=\"selectTableRows('prefUserList', 'none')\" | |
371 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
372 | print "</div></div>"; | |
373 | ||
374 | print "<button dojoType=\"dijit.form.Button\" onclick=\"javascript:addUser()\">".__('Create user')."</button>"; | |
375 | ||
376 | print " | |
377 | <button dojoType=\"dijit.form.Button\" onclick=\"javascript:selectedUserDetails()\">". | |
378 | __('Details')."</button dojoType=\"dijit.form.Button\"> | |
379 | <button dojoType=\"dijit.form.Button\" onclick=\"javascript:editSelectedUser()\">". | |
380 | __('Edit')."</button dojoType=\"dijit.form.Button\"> | |
381 | <button dojoType=\"dijit.form.Button\" onclick=\"javascript:removeSelectedUsers()\">". | |
382 | __('Remove')."</button dojoType=\"dijit.form.Button\"> | |
383 | <button dojoType=\"dijit.form.Button\" onclick=\"javascript:resetSelectedUserPass()\">". | |
384 | __('Reset password')."</button dojoType=\"dijit.form.Button\">"; | |
385 | ||
386 | print "</div>"; #toolbar | |
387 | print "</div>"; #pane | |
388 | print "<div id=\"pref-user-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; | |
389 | ||
390 | print "<div id=\"sticky-status-msg\"></div>"; | |
391 | ||
392 | if ($user_search) { | |
393 | ||
394 | $user_search = split(" ", $user_search); | |
395 | $tokens = array(); | |
396 | ||
397 | foreach ($user_search as $token) { | |
398 | $token = trim($token); | |
399 | array_push($tokens, "(UPPER(login) LIKE UPPER('%$token%'))"); | |
400 | } | |
401 | ||
402 | $user_search_query = "(" . join($tokens, " AND ") . ") AND "; | |
403 | ||
404 | } else { | |
405 | $user_search_query = ""; | |
406 | } | |
407 | ||
408 | $result = db_query($this->link, "SELECT | |
409 | id,login,access_level,email, | |
410 | ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login, | |
411 | ".SUBSTRING_FOR_DATE."(created,1,16) as created | |
412 | FROM | |
413 | ttrss_users | |
414 | WHERE | |
415 | $user_search_query | |
416 | id > 0 | |
417 | ORDER BY $sort"); | |
418 | ||
419 | if (db_num_rows($result) > 0) { | |
420 | ||
421 | print "<p><table width=\"100%\" cellspacing=\"0\" | |
422 | class=\"prefUserList\" id=\"prefUserList\">"; | |
423 | ||
424 | print "<tr class=\"title\"> | |
425 | <td align='center' width=\"5%\"> </td> | |
426 | <td width=''><a href=\"#\" onclick=\"updateUsersList('login')\">".__('Login')."</a></td> | |
427 | <td width='20%'><a href=\"#\" onclick=\"updateUsersList('access_level')\">".__('Access Level')."</a></td> | |
428 | <td width='20%'><a href=\"#\" onclick=\"updateUsersList('created')\">".__('Registered')."</a></td> | |
429 | <td width='20%'><a href=\"#\" onclick=\"updateUsersList('last_login')\">".__('Last login')."</a></td></tr>"; | |
430 | ||
431 | $lnum = 0; | |
432 | ||
433 | while ($line = db_fetch_assoc($result)) { | |
434 | ||
435 | $class = ($lnum % 2) ? "even" : "odd"; | |
436 | ||
437 | $uid = $line["id"]; | |
438 | ||
439 | print "<tr class=\"$class\" id=\"UMRR-$uid\">"; | |
440 | ||
441 | $line["login"] = htmlspecialchars($line["login"]); | |
442 | ||
443 | $line["created"] = make_local_datetime($this->link, $line["created"], false); | |
444 | $line["last_login"] = make_local_datetime($this->link, $line["last_login"], false); | |
445 | ||
446 | print "<td align='center'><input onclick='toggleSelectRow(this);' | |
447 | type=\"checkbox\" id=\"UMCHK-$uid\"></td>"; | |
448 | ||
449 | $onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'"; | |
450 | ||
451 | print "<td $onclick>" . $line["login"] . "</td>"; | |
452 | ||
453 | if (!$line["email"]) $line["email"] = " "; | |
454 | ||
455 | print "<td $onclick>" . $access_level_names[$line["access_level"]] . "</td>"; | |
456 | print "<td $onclick>" . $line["created"] . "</td>"; | |
457 | print "<td $onclick>" . $line["last_login"] . "</td>"; | |
458 | ||
459 | print "</tr>"; | |
460 | ||
461 | ++$lnum; | |
462 | } | |
463 | ||
464 | print "</table>"; | |
465 | ||
466 | } else { | |
467 | print "<p>"; | |
468 | if (!$user_search) { | |
469 | print_warning(__('No users defined.')); | |
470 | } else { | |
471 | print_warning(__('No matching users found.')); | |
472 | } | |
473 | print "</p>"; | |
474 | ||
475 | } | |
476 | ||
477 | print "</div>"; #pane | |
478 | print "</div>"; #container | |
479 | ||
480 | } | |
481 | ||
482 | } | |
483 | ?> |