global $access_level_names;
+ if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
+ print __("Your access level is insufficient to open this tab.");
+ return;
+ }
+
$subop = $_GET["subop"];
+ if ($subop == "user-details") {
+
+ $uid = sprintf("%d", $_GET["id"]);
+
+ print "<div id=\"infoBoxTitle\">User details</div>";
+
+ print "<div class='infoBoxContents'>";
+
+ $result = db_query($link, "SELECT login,
+ ".SUBSTRING_FOR_DATE."(last_login,1,16) AS last_login,
+ access_level,
+ (SELECT COUNT(int_id) FROM ttrss_user_entries
+ WHERE owner_uid = id) AS stored_articles,
+ ".SUBSTRING_FOR_DATE."(created,1,16) AS created
+ FROM ttrss_users
+ WHERE id = '$uid'");
+
+ if (db_num_rows($result) == 0) {
+ print "<h1>User not found</h1>";
+ return;
+ }
+
+ // print "<h1>User Details</h1>";
+
+ $login = db_fetch_result($result, 0, "login");
+
+ // print "<h1>$login</h1>";
+
+ print "<table width='100%'>";
+
+ $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
+ strtotime(db_fetch_result($result, 0, "last_login")));
+
+ $created = date(get_pref($link, 'LONG_DATE_FORMAT'),
+ strtotime(db_fetch_result($result, 0, "created")));
+
+ $access_level = db_fetch_result($result, 0, "access_level");
+ $stored_articles = db_fetch_result($result, 0, "stored_articles");
+
+ // print "<tr><td>Username</td><td>$login</td></tr>";
+ // print "<tr><td>Access level</td><td>$access_level</td></tr>";
+ print "<tr><td>".__('Registered')."</td><td>$created</td></tr>";
+ print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>";
+
+/* $result = db_query($link, "SELECT
+ SUM(LENGTH(content)) AS db_size
+ FROM ttrss_user_entries,ttrss_entries
+ WHERE owner_uid = '$uid' AND ref_id = id");
+
+ $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
+
+ print "<tr><td>".__('Stored articles').
+ "</td><td>$stored_articles (${db_size}K)</td></tr>"; */
+
+ $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
+ WHERE owner_uid = '$uid'");
+
+ $num_feeds = db_fetch_result($result, 0, "num_feeds");
+
+ print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>";
+
+ print "</table>";
+
+ print "<h1>".__('Subscribed feeds')."</h1>";
+
+ $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
+ WHERE owner_uid = '$uid' ORDER BY title");
+
+ print "<ul class=\"userFeedList\">";
+
+ $row_class = "odd";
+
+ while ($line = db_fetch_assoc($result)) {
+
+ $icon_file = ICONS_URL."/".$line["id"].".ico";
+
+ if (file_exists($icon_file) && filesize($icon_file) > 0) {
+ $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
+ } else {
+ $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
+ }
+
+ print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
+
+ $row_class = toggleEvenOdd($row_class);
+
+ }
+
+ if (db_num_rows($result) < $num_feeds) {
+ // FIXME - add link to show ALL subscribed feeds here somewhere
+ print "<li><img
+ class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
+ }
+
+ print "</ul>";
+
+ print "<div align='center'>
+ <input type='submit' class='button'
+ onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
+
+ print "</div>";
+
+ return;
+ }
+
if ($subop == "edit") {
$id = db_escape_string($_GET["id"]);
- print "<div id=\"infoBoxTitle\">".__('User editor')."</div>";
+ print "<div id=\"infoBoxTitle\">".__('User Editor')."</div>";
print "<div class=\"infoBoxContents\">";
$access_level = db_fetch_result($result, 0, "access_level");
$email = db_fetch_result($result, 0, "email");
- print "<table width='100%'>";
- print "<tr><td>".__('Login:')."</td><td>
- <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
- name=\"login\" value=\"$login\"></td></tr>";
+ $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : "";
- print "<tr><td>Change password:</td><td>
- <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
- name=\"password\"></td></tr>";
+ print "<div class=\"dlgSec\">".__("User")."</div>";
+ print "<div class=\"dlgSecCont\">";
- print "<tr><td>".__('E-mail:')."</td><td>
- <input class=\"iedit\" name=\"email\" onkeypress=\"return filterCR(event)\"
- value=\"$email\"></td></tr>";
+ print "<input size=\"30\" style=\"font-size : 16px\"
+ onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled
+ name=\"login\" value=\"$login\">";
+
+ print "</div>";
+
+ print "<div class=\"dlgSec\">".__("Authentication")."</div>";
+ print "<div class=\"dlgSecCont\">";
+
+ print __('Access level: ') . " ";
- $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : "";
-
- print "<tr><td>".__('Access level:')."</td><td>";
print_select_hash("access_level", $access_level, $access_level_names,
$sel_disabled);
- print "</td></tr>";
+
+ print "<br/>";
+
+ print __('Change password to') .
+ " <input size=\"20\" onkeypress=\"return filterCR(event, userEditSave)\"
+ name=\"password\">";
+
+ print "</div>";
+
+ print "<div class=\"dlgSec\">".__("Options")."</div>";
+ print "<div class=\"dlgSecCont\">";
+
+ print __('E-mail: ').
+ " <input size=\"30\" name=\"email\" onkeypress=\"return filterCR(event, userEditSave)\"
+ value=\"$email\">";
+
+ print "</div>";
print "</table>";
print "</form>";
- print "<div align='right'>
+ print "<div class=\"dlgButtons\">
<input class=\"button\"
type=\"submit\" onclick=\"return userEditSave()\"
value=\"".__('Save')."\">
$login = db_escape_string(trim($_GET["login"]));
$uid = db_escape_string($_GET["id"]);
- $access_level = sprintf("%d", $_GET["access_level"]);
+ $access_level = (int) $_GET["access_level"];
$email = db_escape_string(trim($_GET["email"]));
$password = db_escape_string(trim($_GET["password"]));
if ($password) {
- $pwd_hash = 'SHA1:' . sha1($password);
+ $pwd_hash = encrypt_password($password, $login);
$pass_query_part = "pwd_hash = '$pwd_hash', ";
- print format_notice(sprintf(__('Changed password of user <b>%s</b>.'), $login));
+ print_notice(T_sprintf('Changed password of user <b>%s</b>.', $login));
} else {
$pass_query_part = "";
}
}
} else if ($subop == "remove") {
- if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
+ if ($_SESSION["access_level"] >= 10) {
$ids = split(",", db_escape_string($_GET["ids"]));
foreach ($ids as $id) {
- db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
-
+ if ($id != $_SESSION["uid"]) {
+ db_query($link, "DELETE FROM ttrss_tags WHERE owner_uid = '$id'");
+ db_query($link, "DELETE FROM ttrss_feeds WHERE owner_uid = '$id'");
+ db_query($link, "DELETE FROM ttrss_users WHERE id = '$id'");
+ }
}
}
} else if ($subop == "add") {
- if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
+ if ($_SESSION["access_level"] >= 10) {
$login = db_escape_string(trim($_GET["login"]));
$tmp_user_pwd = make_password(8);
- $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
+ $pwd_hash = encrypt_password($tmp_user_pwd, $login);
$result = db_query($link, "SELECT id FROM ttrss_users WHERE
login = '$login'");
if (db_num_rows($result) == 0) {
db_query($link, "INSERT INTO ttrss_users
- (login,pwd_hash,access_level,last_login)
- VALUES ('$login', '$pwd_hash', 0, NOW())");
+ (login,pwd_hash,access_level,last_login,created)
+ VALUES ('$login', '$pwd_hash', 0, null, NOW())");
$result = db_query($link, "SELECT id FROM ttrss_users WHERE
$new_uid = db_fetch_result($result, 0, "id");
- print format_notice(sprintf(__("Added user <b>%s</b>
- with password <b>%s</b>"), $login, $tmp_user_pwd));
+ print_notice(T_sprintf("Added user <b>%s</b> with password <b>%s</b>",
+ $login, $tmp_user_pwd));
initialize_user($link, $new_uid);
} else {
- print format_warning(sprintf(__("Could not create user <b>%s</b>"),
- $login));
+ print_warning(T_sprintf("Could not create user <b>%s</b>", $login));
}
} else {
- print format_warning(sprintf(__("User <b>%s</b> already exists."),
- $login));
-
+ print_warning(T_sprintf("User <b>%s</b> already exists.", $login));
}
}
} else if ($subop == "resetPass") {
$login = db_fetch_result($result, 0, "login");
$email = db_fetch_result($result, 0, "email");
$tmp_user_pwd = make_password(8);
- $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
+ $pwd_hash = encrypt_password($tmp_user_pwd, $login);
db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
WHERE id = '$uid'");
- print format_notice(sprintf(__("Changed password of user <b>%s</b>
- to <b>%s</b>"), $login, $tmp_user_pwd));
+ print_notice(T_sprintf("Changed password of user <b>%s</b>
+ to <b>%s</b>", $login, $tmp_user_pwd));
+
+ if ($email) {
+ print_notice(T_sprintf("Notifying <b>%s</b>.", $email));
+
+ require_once "MiniTemplator.class.php";
+
+ $tpl = new MiniTemplator;
+
+ $tpl->readTemplateFromFile("templates/resetpass_template.txt");
+
+ $tpl->setVariable('LOGIN', $login);
+ $tpl->setVariable('NEWPASS', $tmp_user_pwd);
+
+ $tpl->addBlock('message');
+
+ $message = "";
+
+ $tpl->generateOutputToString($message);
+
+ $mail = new PHPMailer();
+
+ $mail->PluginDir = "lib/phpmailer/";
+ $mail->SetLanguage("en", "lib/phpmailer/language/");
+
+ $mail->CharSet = "UTF-8";
+
+ $mail->From = DIGEST_FROM_ADDRESS;
+ $mail->FromName = DIGEST_FROM_NAME;
+ $mail->AddAddress($email, $login);
+
+ if (DIGEST_SMTP_HOST) {
+ $mail->Host = DIGEST_SMTP_HOST;
+ $mail->Mailer = "smtp";
+ $mail->SMTPAuth = DIGEST_SMTP_LOGIN != '';
+ $mail->Username = DIGEST_SMTP_LOGIN;
+ $mail->Password = DIGEST_SMTP_PASSWORD;
+ }
+
+ $mail->IsHTML(false);
+ $mail->Subject = __("[tt-rss] Password change notification");
+ $mail->Body = $message;
- if (MAIL_RESET_PASS && $email) {
- print " Notifying <b>$email</b>.";
+ $rc = $mail->Send();
- mail("$login <$email>", "Password reset notification",
+ if (!$rc) print_error($mail->ErrorInfo);
+
+/* mail("$login <$email>", "Password reset notification",
"Hi, $login.\n".
"\n".
"Your password for this TT-RSS installation was reset by".
"Your new password is $tmp_user_pwd, please remember".
" it for later reference.\n".
"\n".
- "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
+ "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM); */
}
print "</div>";
}
}
+ set_pref($link, "_PREFS_ACTIVE_TAB", "userConfig");
+
+ $user_search = db_escape_string($_GET["search"]);
+
+ if (array_key_exists("search", $_GET)) {
+ $_SESSION["prefs_user_search"] = $user_search;
+ } else {
+ $user_search = $_SESSION["prefs_user_search"];
+ }
+
+ print "<div class=\"feedEditSearch\">
+ <input id=\"user_search\" size=\"20\" type=\"search\"
+ onfocus=\"javascript:disableHotkeys();\"
+ onblur=\"javascript:enableHotkeys();\"
+ onchange=\"javascript:updateUsersList()\" value=\"$user_search\">
+ <input type=\"submit\" class=\"button\"
+ onclick=\"javascript:updateUsersList()\" value=\"".__('Search')."\">
+ </div>";
+
$sort = db_escape_string($_GET["sort"]);
if (!$sort || $sort == "undefined") {
<input id=\"uadd_box\"
onkeyup=\"toggleSubmitNotEmpty(this, 'user_add_btn')\"
onchange=\"toggleSubmitNotEmpty(this, 'user_add_btn')\"
- size=\"40\"> ";
+ size=\"15\"> ";
print "<input type=\"submit\" class=\"button\"
id=\"user_add_btn\" disabled=\"true\"
onclick=\"javascript:addUser()\" value=\"".__('Create user')."\"></div>";
+ if ($user_search) {
+ $user_search_query = "UPPER(login) LIKE UPPER('%$user_search%') AND";
+ } else {
+ $user_search_query = "";
+ }
+
$result = db_query($link, "SELECT
id,login,access_level,email,
- SUBSTRING(last_login,1,16) as last_login
+ ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login,
+ ".SUBSTRING_FOR_DATE."(created,1,16) as created
FROM
ttrss_users
+ WHERE
+ $user_search_query
+ id > 0
ORDER BY $sort");
+ if (db_num_rows($result) > 0) {
+
// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
print "<p><table width=\"100%\" cellspacing=\"0\"
class=\"prefUserList\" id=\"prefUserList\">";
print "<tr><td class=\"selectPrompt\" colspan=\"8\">
- Select:
- <a href=\"javascript:selectPrefRows('user', true)\">All</a>,
- <a href=\"javascript:selectPrefRows('user', false)\">None</a>
+ ".__('Select:')."
+ <a href=\"javascript:selectPrefRows('user', true)\">".__('All')."</a>,
+ <a href=\"javascript:selectPrefRows('user', false)\">".__('None')."</a>
</td</tr>";
print "<tr class=\"title\">
<td align='center' width=\"5%\"> </td>
- <td width='40%'><a href=\"javascript:updateUsersList('login')\">Login</a></td>
- <td width='40%'><a href=\"javascript:updateUsersList('access_level')\">Access Level</a></td>
- <td width='30%'><a href=\"javascript:updateUsersList('last_login')\">Last login</a></td></tr>";
+ <td width=''><a href=\"javascript:updateUsersList('login')\">".__('Login')."</a></td>
+ <td width='20%'><a href=\"javascript:updateUsersList('access_level')\">".__('Access Level')."</a></td>
+ <td width='20%'><a href=\"javascript:updateUsersList('created')\">".__('Registered')."</a></td>
+ <td width='20%'><a href=\"javascript:updateUsersList('last_login')\">".__('Last login')."</a></td></tr>";
$lnum = 0;
if (get_pref($link, 'HEADLINES_SMART_DATE')) {
$line["last_login"] = smart_date_time(strtotime($line["last_login"]));
+ $line["created"] = smart_date_time(strtotime($line["created"]));
} else {
$line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
strtotime($line["last_login"]));
+ $line["created"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
+ strtotime($line["created"]));
}
- $access_level_names = array(0 => "User", 10 => "Administrator");
-
-// if (!$edit_uid || $subop != "edit") {
-
- print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"user\");'
+ print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"user\");'
type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
- print "<td><a href=\"javascript:editUser($uid);\">" .
- $line["login"] . "</td>";
-
- if (!$line["email"]) $line["email"] = " ";
-
- print "<td><a href=\"javascript:editUser($uid);\">" .
- $access_level_names[$line["access_level"]] . "</td>";
-
-/* } else if ($uid != $edit_uid) {
-
- if (!$line["email"]) $line["email"] = " ";
+ $onclick = "onclick='editUser($uid)' title='".__('Click to edit')."'";
- print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
- id=\"UMCHK-".$line["id"]."\"></td>";
+ print "<td $onclick>" . $line["login"] . "</td>";
- print "<td>".$line["login"]."</td>";
- print "<td>".$line["email"]."</td>";
- print "<td>".$access_level_names[$line["access_level"]]."</td>";
+ if (!$line["email"]) $line["email"] = " ";
- } else {
-
- print "<td align='center'>
- <input disabled=\"true\" type=\"checkbox\" checked></td>";
-
- print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
- "\"></td>";
-
- print "<td><input id=\"iedit_email\" value=\"".$line["email"].
- "\"></td>";
-
- print "<td>";
- print "<select id=\"iedit_ulevel\">";
- foreach (array_keys($access_level_names) as $al) {
- if ($al == $line["access_level"]) {
- $selected = "selected";
- } else {
- $selected = "";
- }
- print "<option $selected id=\"$al\">" .
- $access_level_names[$al] . "</option>";
- }
- print "</select>";
- print "</td>";
-
- } */
-
- print "<td>".$line["last_login"]."</td>";
+ print "<td $onclick>" . $access_level_names[$line["access_level"]] . "</td>";
+ print "<td $onclick>" . $line["created"] . "</td>";
+ print "<td $onclick>" . $line["last_login"] . "</td>";
print "</tr>";
<input type=\"submit\" class=\"button\" disabled=\"true\"
onclick=\"javascript:resetSelectedUserPass()\" value=\"".__('Reset password')."\">";
+ } else {
+ print "<p>";
+ if (!$user_search) {
+ print __('No users defined.');
+ } else {
+ print __('No matching users found.');
+ }
+ print "</p>";
+
+ }
+
}
?>