]>
git.wh0rd.org - tt-rss.git/blob - modules/pref-users.php
b75d5b76fb5101529cc62d4101cee2fe07a052e7
2 function module_pref_users($link) {
4 global $access_level_names;
6 if (!SINGLE_USER_MODE
&& $_SESSION["access_level"] < 10) {
7 print __("Your access level is insufficient to open this tab.");
11 $subop = $_REQUEST["subop"];
13 if ($subop == "user-details") {
15 header("Content-Type: text/xml");
16 print "<dlg id=\"$subop\">";
18 $uid = sprintf("%d", $_REQUEST["id"]);
20 print "<title>".__('User details')."</title>";
22 print "<content><![CDATA[";
24 $result = db_query($link, "SELECT login,
25 ".SUBSTRING_FOR_DATE
."(last_login,1,16) AS last_login,
27 (SELECT COUNT(int_id) FROM ttrss_user_entries
28 WHERE owner_uid = id) AS stored_articles,
29 ".SUBSTRING_FOR_DATE
."(created,1,16) AS created
33 if (db_num_rows($result) == 0) {
34 print "<h1>".__('User not found')."</h1>";
38 // print "<h1>User Details</h1>";
40 $login = db_fetch_result($result, 0, "login");
42 print "<table width='100%'>";
44 $last_login = make_local_datetime($link,
45 db_fetch_result($result, 0, "last_login"), true);
47 $created = make_local_datetime($link,
48 db_fetch_result($result, 0, "created"), true);
50 $access_level = db_fetch_result($result, 0, "access_level");
51 $stored_articles = db_fetch_result($result, 0, "stored_articles");
53 print "<tr><td>".__('Registered')."</td><td>$created</td></tr>";
54 print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>";
56 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
57 WHERE owner_uid = '$uid'");
59 $num_feeds = db_fetch_result($result, 0, "num_feeds");
61 print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>";
65 print "<h1>".__('Subscribed feeds')."</h1>";
67 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
68 WHERE owner_uid = '$uid' ORDER BY title");
70 print "<ul class=\"userFeedList\">";
74 while ($line = db_fetch_assoc($result)) {
76 $icon_file = ICONS_URL
."/".$line["id"].".ico";
78 if (file_exists($icon_file) && filesize($icon_file) > 0) {
79 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
81 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
84 print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
86 $row_class = toggleEvenOdd($row_class);
90 if (db_num_rows($result) < $num_feeds) {
91 // FIXME - add link to show ALL subscribed feeds here somewhere
93 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
98 print "<div align='center'>
99 <button onclick=\"closeInfoBox()\">".__("Close this window").
102 print "]]></content></dlg>";
107 if ($subop == "edit") {
109 header("Content-Type: text/xml");
111 $id = db_escape_string($_REQUEST["id"]);
113 print "<dlg id=\"$subop\">";
114 print "<title>".__('User Editor')."</title>";
115 print "<content><![CDATA[";
117 print "<form id=\"user_edit_form\" onsubmit='return false'>";
119 print "<input type=\"hidden\" name=\"id\" value=\"$id\">";
120 print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">";
121 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
123 $result = db_query($link, "SELECT * FROM ttrss_users WHERE id = '$id'");
125 $login = db_fetch_result($result, 0, "login");
126 $access_level = db_fetch_result($result, 0, "access_level");
127 $email = db_fetch_result($result, 0, "email");
129 $sel_disabled = ($id == $_SESSION["uid"]) ?
"disabled" : "";
131 print "<div class=\"dlgSec\">".__("User")."</div>";
132 print "<div class=\"dlgSecCont\">";
135 print "<input type=\"hidden\" name=\"login\" value=\"$login\">";
136 print "<input size=\"30\" style=\"font-size : 16px\"
137 onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled
140 print "<input size=\"30\" style=\"font-size : 16px\"
141 onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled
142 name=\"login\" value=\"$login\">";
147 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
148 print "<div class=\"dlgSecCont\">";
150 print __('Access level: ') . " ";
152 if (!$sel_disabled) {
153 print_select_hash("access_level", $access_level, $access_level_names,
156 print_select_hash("", $access_level, $access_level_names,
158 print "<input type=\"hidden\" name=\"access_level\" value=\"$access_level\">";
163 print __('Change password to') .
164 " <input size=\"20\" onkeypress=\"return filterCR(event, userEditSave)\"
169 print "<div class=\"dlgSec\">".__("Options")."</div>";
170 print "<div class=\"dlgSecCont\">";
172 print __('E-mail: ').
173 " <input size=\"30\" name=\"email\" onkeypress=\"return filterCR(event, userEditSave)\"
182 print "<div class=\"dlgButtons\">
183 <button onclick=\"return userEditSave()\">".
184 __('Save')."</button>
185 <button onclick=\"return userEditCancel()\">".
186 __('Cancel')."</button></div>";
188 print "]]></content></dlg>";
193 if ($subop == "editSave") {
195 if ($_SESSION["access_level"] >= 10) {
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"]));
204 $pwd_hash = encrypt_password($password, $login);
205 $pass_query_part = "pwd_hash = '$pwd_hash', ";
206 $status_msg = format_notice(T_sprintf('Changed password of user <b>%s</b>.', $login));
208 $pass_query_part = "";
211 db_query($link, "UPDATE ttrss_users SET $pass_query_part login = '$login',
212 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
215 } else if ($subop == "remove") {
217 if ($_SESSION["access_level"] >= 10) {
219 $ids = split(",", db_escape_string($_REQUEST["ids"]));
221 foreach ($ids as $id) {
222 if ($id != $_SESSION["uid"] && $id != 1) {
223 db_query($link, "DELETE FROM ttrss_tags WHERE owner_uid = '$id'");
224 db_query($link, "DELETE FROM ttrss_feeds WHERE owner_uid = '$id'");
225 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id'");
229 } else if ($subop == "add") {
231 if ($_SESSION["access_level"] >= 10) {
233 $login = db_escape_string(trim($_REQUEST["login"]));
234 $tmp_user_pwd = make_password(8);
235 $pwd_hash = encrypt_password($tmp_user_pwd, $login);
237 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
240 if (db_num_rows($result) == 0) {
242 db_query($link, "INSERT INTO ttrss_users
243 (login,pwd_hash,access_level,last_login,created)
244 VALUES ('$login', '$pwd_hash', 0, null, NOW())");
247 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
248 login = '$login' AND pwd_hash = '$pwd_hash'");
250 if (db_num_rows($result) == 1) {
252 $new_uid = db_fetch_result($result, 0, "id");
254 $status_msg = format_notice(T_sprintf("Added user <b>%s</b> with password <b>%s</b>",
255 $login, $tmp_user_pwd));
257 initialize_user($link, $new_uid);
261 $status_msg = format_warning(T_sprintf("Could not create user <b>%s</b>", $login));
265 $status_msg = format_warning(T_sprintf("User <b>%s</b> already exists.", $login));
268 } else if ($subop == "resetPass") {
270 if ($_SESSION["access_level"] >= 10) {
272 $uid = db_escape_string($_REQUEST["id"]);
274 $result = db_query($link, "SELECT login,email
275 FROM ttrss_users WHERE id = '$uid'");
277 $login = db_fetch_result($result, 0, "login");
278 $email = db_fetch_result($result, 0, "email");
279 $tmp_user_pwd = make_password(8);
280 $pwd_hash = encrypt_password($tmp_user_pwd, $login);
282 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
285 $status_msg = format_notice(T_sprintf("Changed password of user <b>%s</b>
286 to <b>%s</b>", $login, $tmp_user_pwd));
289 $status_msg +
= format_notice(T_sprintf("Notifying <b>%s</b>.", $email));
291 require_once "lib/MiniTemplator.class.php";
293 $tpl = new MiniTemplator
;
295 $tpl->readTemplateFromFile("templates/resetpass_template.txt");
297 $tpl->setVariable('LOGIN', $login);
298 $tpl->setVariable('NEWPASS', $tmp_user_pwd);
300 $tpl->addBlock('message');
304 $tpl->generateOutputToString($message);
306 $mail = new PHPMailer();
308 $mail->PluginDir
= "lib/phpmailer/";
309 $mail->SetLanguage("en", "lib/phpmailer/language/");
311 $mail->CharSet
= "UTF-8";
313 $mail->From
= DIGEST_FROM_ADDRESS
;
314 $mail->FromName
= DIGEST_FROM_NAME
;
315 $mail->AddAddress($email, $login);
317 if (DIGEST_SMTP_HOST
) {
318 $mail->Host
= DIGEST_SMTP_HOST
;
319 $mail->Mailer
= "smtp";
320 $mail->SMTPAuth
= DIGEST_SMTP_LOGIN
!= '';
321 $mail->Username
= DIGEST_SMTP_LOGIN
;
322 $mail->Password
= DIGEST_SMTP_PASSWORD
;
325 $mail->IsHTML(false);
326 $mail->Subject
= __("[tt-rss] Password change notification");
327 $mail->Body
= $message;
331 if (!$rc) print_error($mail->ErrorInfo
);
333 /* mail("$login <$email>", "Password reset notification",
336 "Your password for this TT-RSS installation was reset by".
337 " an administrator.\n".
339 "Your new password is $tmp_user_pwd, please remember".
340 " it for later reference.\n".
342 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM); */
350 print "<div id=\"pref-user-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
351 print "<div id=\"pref-user-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
353 print "<div id=\"pref-user-toolbar\" dojoType=\"dijit.Toolbar\">";
355 $user_search = db_escape_string($_REQUEST["search"]);
357 if (array_key_exists("search", $_REQUEST)) {
358 $_SESSION["prefs_user_search"] = $user_search;
360 $user_search = $_SESSION["prefs_user_search"];
363 print "<div style='float : right; padding-right : 4px;'>
364 <input dojoType=\"dijit.form.TextBox\" id=\"user_search\" size=\"20\" type=\"search\"
365 onfocus=\"javascript:disableHotkeys();\"
366 onblur=\"javascript:enableHotkeys();\"
367 onchange=\"javascript:updateUsersList()\" value=\"$user_search\">
368 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:updateUsersList()\">".
369 __('Search')."</button>
372 $sort = db_escape_string($_REQUEST["sort"]);
374 if (!$sort ||
$sort == "undefined") {
378 print "<div dojoType=\"dijit.form.DropDownButton\">".
379 "<span>" . __('Select')."</span>";
380 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
381 print "<div onclick=\"selectTableRows('prefUserList', 'all')\"
382 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
383 print "<div onclick=\"selectTableRows('prefUserList', 'none')\"
384 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
385 print "</div></div>";
387 print "<button dojoType=\"dijit.form.Button\" onclick=\"javascript:addUser()\">".__('Create user')."</button>";
390 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:selectedUserDetails()\">".
391 __('Details')."</button dojoType=\"dijit.form.Button\">
392 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:editSelectedUser()\">".
393 __('Edit')."</button dojoType=\"dijit.form.Button\">
394 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:removeSelectedUsers()\">".
395 __('Remove')."</button dojoType=\"dijit.form.Button\">
396 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:resetSelectedUserPass()\">".
397 __('Reset password')."</button dojoType=\"dijit.form.Button\">";
399 print "</div>"; #toolbar
400 print "</div>"; #pane
401 print "<div id=\"pref-user-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
402 print "<p>$status_msg";
406 $user_search = split(" ", $user_search);
409 foreach ($user_search as $token) {
410 $token = trim($token);
411 array_push($tokens, "(UPPER(login) LIKE UPPER('%$token%'))");
414 $user_search_query = "(" . join($tokens, " AND ") . ") AND ";
417 $user_search_query = "";
420 $result = db_query($link, "SELECT
421 id,login,access_level,email,
422 ".SUBSTRING_FOR_DATE
."(last_login,1,16) as last_login,
423 ".SUBSTRING_FOR_DATE
."(created,1,16) as created
431 if (db_num_rows($result) > 0) {
433 print "<p><table width=\"100%\" cellspacing=\"0\"
434 class=\"prefUserList\" id=\"prefUserList\">";
436 print "<tr class=\"title\">
437 <td align='center' width=\"5%\"> </td>
438 <td width=''><a href=\"#\" onclick=\"updateUsersList('login')\">".__('Login')."</a></td>
439 <td width='20%'><a href=\"#\" onclick=\"updateUsersList('access_level')\">".__('Access Level')."</a></td>
440 <td width='20%'><a href=\"#\" onclick=\"updateUsersList('created')\">".__('Registered')."</a></td>
441 <td width='20%'><a href=\"#\" onclick=\"updateUsersList('last_login')\">".__('Last login')."</a></td></tr>";
445 while ($line = db_fetch_assoc($result)) {
447 $class = ($lnum %
2) ?
"even" : "odd";
450 $edit_uid = $_REQUEST["id"];
452 if ($subop == "edit" && $uid != $edit_uid) {
456 $this_row_id = "id=\"UMRR-$uid\"";
459 print "<tr class=\"$class\" $this_row_id>";
461 $line["login"] = htmlspecialchars($line["login"]);
463 $line["created"] = make_local_datetime($link, $line["created"], false);
464 $line["last_login"] = make_local_datetime($link, $line["last_login"], false);
466 print "<td align='center'><input onclick='toggleSelectRow(this);'
467 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
469 $onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'";
471 print "<td $onclick>" . $line["login"] . "</td>";
473 if (!$line["email"]) $line["email"] = " ";
475 print "<td $onclick>" . $access_level_names[$line["access_level"]] . "</td>";
476 print "<td $onclick>" . $line["created"] . "</td>";
477 print "<td $onclick>" . $line["last_login"] . "</td>";
489 print_warning(__('No users defined.'));
491 print_warning(__('No matching users found.'));
497 print "</div>"; #pane
498 print "</div>"; #container