📄 edit_self.aspx
字号:
<%@ Page language="C#"%>
<!--
Copyright 2002-2005 Corey Trager
Distributed under the terms of the GNU General Public License
-->
<!-- #include file = "inc.aspx" -->
<script language="C#" runat="server">
int id;
String sql;
DbUtil dbutil;
Security security;
///////////////////////////////////////////////////////////////////////
void Page_Load(Object sender, EventArgs e)
{
Util.do_not_cache(Response);
dbutil = new DbUtil();
security = new Security();
security.check_security(dbutil, Request, Response, Security.ANY_USER_OK_EXCEPT_GUEST);
title.InnerText = Util.get_setting("AppTitle","BugTracker.NET") + " - "
+ "edit your settings";
msg.InnerText = "";
id = security.this_usid;
if (!IsPostBack)
{
sql = @"select qu_id, qu_desc
from queries
where isnull(qu_user,0) = 0
or isnull(qu_user,0) = $us
order by qu_desc";
sql = sql.Replace("$us",Convert.ToString(security.this_usid));
query.DataSource = dbutil.get_dataview(sql);
query.DataTextField = "qu_desc";
query.DataValueField = "qu_id";
query.DataBind();
sql = @"select pj_id, pj_name, isnull(pu_auto_subscribe,0) [pu_auto_subscribe]
from projects
left outer join project_user_xref on pj_id = pu_project and $us = pu_user
where isnull(pu_permission_level,$dpl) <> 0
order by pj_name";
sql = sql.Replace("$us", Convert.ToString(security.this_usid));
sql = sql.Replace("$dpl", Util.get_setting("DefaultPermissionLevel","2"));
DataView projects_dv = dbutil.get_dataview(sql);
project_auto_subscribe.DataSource = projects_dv;
project_auto_subscribe.DataTextField = "pj_name";
project_auto_subscribe.DataValueField = "pj_id";
project_auto_subscribe.DataBind();
// Get this entry's data from the db and fill in the form
sql = @"select
us_username [username],
isnull(us_firstname,'') [firstname],
isnull(us_lastname,'') [lastname],
isnull(us_bugs_per_page,10) [us_bugs_per_page],
isnull(us_email,'') [email],
us_enable_notifications,
us_only_new_bug_notifications,
us_send_notifications_to_self,
us_only_status_change_notifications,
us_auto_subscribe,
us_auto_subscribe_own_bugs,
us_auto_subscribe_reported_bugs,
us_default_query
from users
where us_id = $id";
sql = sql.Replace("$id", Convert.ToString(id));
DataRow dr = dbutil.get_datarow(sql);
// Fill in this form
firstname.Value = (string) dr["firstname"];
lastname.Value = (string) dr["lastname"];
bugs_per_page.Value = Convert.ToString(dr["us_bugs_per_page"]);
email.Value = (string) dr["email"];
enable_notifications.Checked = Convert.ToBoolean((int) dr["us_enable_notifications"]);
only_new_bug_notifications.Checked = Convert.ToBoolean((int) dr["us_only_new_bug_notifications"]);
send_to_self.Checked = Convert.ToBoolean((int) dr["us_send_notifications_to_self"]);
only_status_changes.Checked = Convert.ToBoolean((int) dr["us_only_status_change_notifications"]);
auto_subscribe.Checked = Convert.ToBoolean((int) dr["us_auto_subscribe"]);
auto_subscribe_own.Checked = Convert.ToBoolean((int) dr["us_auto_subscribe_own_bugs"]);
auto_subscribe_reported.Checked = Convert.ToBoolean((int) dr["us_auto_subscribe_reported_bugs"]);
foreach (ListItem li in query.Items)
{
if (Convert.ToInt32(li.Value) == (int) dr["us_default_query"])
{
li.Selected = true;
break;
}
}
// select projects
foreach (DataRowView drv in projects_dv)
{
foreach (ListItem li in project_auto_subscribe.Items)
{
if (Convert.ToInt32(li.Value) == (int) drv["pj_id"])
{
if ((int) drv["pu_auto_subscribe"] == 1)
{
li.Selected = true;
}
else
{
li.Selected = false;
}
}
}
}
}
}
void Page_Unload(Object sender, EventArgs e)
{
if (dbutil != null) {dbutil.close();}
}
///////////////////////////////////////////////////////////////////////
Boolean validate()
{
Boolean good = true;
if (confirm_pw.Value != pw.Value)
{
good = false;
confirm_pw_err.InnerText = "Confirm Password must match Password.";
}
else
{
confirm_pw_err.InnerText = "";
}
if (!Util.is_int(bugs_per_page.Value))
{
good = false;
bugs_per_page_err.InnerText = Util.get_setting("PluralBugLabel","Bugs") + " Per Page must be a number.";
}
else
{
bugs_per_page_err.InnerText = "";
}
return good;
}
///////////////////////////////////////////////////////////////////////
void on_update (Object sender, EventArgs e)
{
Boolean good = validate();
if (good)
{
string password_to_store;
if (Util.get_setting("EncryptStoredPasswords", "0") == "1")
{
password_to_store = Util.encrypt_string_using_MD5(pw.Value);
}
else
{
password_to_store = pw.Value.Replace("'","''");
}
if (pw.Value != "")
{
sql = @"update users set
us_password = N'$pw',
us_firstname = N'$fn',
us_lastname = N'$ln',
us_bugs_per_page = N'$bp',
us_email = N'$em',
us_enable_notifications = $en,
us_only_new_bug_notifications = $on,
us_send_notifications_to_self = $ss,
us_only_status_change_notifications = $os,
us_auto_subscribe = $as,
us_auto_subscribe_own_bugs = $ao,
us_auto_subscribe_reported_bugs = $ar,
us_default_query = $dq
where us_id = $id";
sql = sql.Replace("$pw", password_to_store);
}
else
{
sql = @"update users set
us_firstname = N'$fn',
us_lastname = N'$ln',
us_bugs_per_page = N'$bp',
us_email = N'$em',
us_enable_notifications = $en,
us_only_new_bug_notifications = $on,
us_send_notifications_to_self = $ss,
us_only_status_change_notifications = $os,
us_auto_subscribe = $as,
us_auto_subscribe_own_bugs = $ao,
us_auto_subscribe_reported_bugs = $ar,
us_default_query = $dq
where us_id = $id";
}
sql = sql.Replace("$fn", firstname.Value.Replace("'","''"));
sql = sql.Replace("$ln", lastname.Value.Replace("'","''"));
sql = sql.Replace("$bp", bugs_per_page.Value.Replace("'","''"));
sql = sql.Replace("$em", email.Value.Replace("'","''"));
sql = sql.Replace("$en", Util.bool_to_string(enable_notifications.Checked));
sql = sql.Replace("$on", Util.bool_to_string(only_new_bug_notifications.Checked));
sql = sql.Replace("$ss", Util.bool_to_string(send_to_self.Checked));
sql = sql.Replace("$os", Util.bool_to_string(only_status_changes.Checked));
sql = sql.Replace("$as", Util.bool_to_string(auto_subscribe.Checked));
sql = sql.Replace("$ao", Util.bool_to_string(auto_subscribe_own.Checked));
sql = sql.Replace("$ar", Util.bool_to_string(auto_subscribe_reported.Checked));
sql = sql.Replace("$dq", query.SelectedItem.Value);
sql = sql.Replace("$id", Convert.ToString(id));
// update user
dbutil.execute_nonquery(sql);
// Now update project_user_xref
// First turn everything off, then turn selected ones on.
sql = @"update project_user_xref
set pu_auto_subscribe = 0 where pu_user = $id";
sql = sql.Replace("$id", Convert.ToString(id));
dbutil.execute_nonquery(sql);
// Second see what to turn back on
string projects = "";
foreach (ListItem li in project_auto_subscribe.Items)
{
if (li.Selected)
{
if (projects != "")
{
projects += ",";
}
projects += Convert.ToInt32(li.Value);
}
}
// If we need to turn anything back on
if (projects != "")
{
sql = @"update project_user_xref
set pu_auto_subscribe = 1 where pu_user = $id and pu_project in ($projects)
insert into project_user_xref (pu_project, pu_user, pu_auto_subscribe)
select pj_id, $id, 1
from projects
where pj_id in ($projects)
and pj_id not in (select pu_project from project_user_xref where pu_user = $id)";
sql = sql.Replace("$id", Convert.ToString(id));
sql = sql.Replace("$projects", projects);
dbutil.execute_nonquery(sql);
}
msg.InnerText = "Your settings have been updated.";
}
else
{
msg.InnerText = "Your settings have not been updated.";
}
}
</script>
<html>
<head>
<title id="title" runat="server">btnet edit user</title>
<link rel="StyleSheet" href="btnet.css" type="text/css">
</head>
<body>
<% security.write_menu(Response, "settings"); %>
<div class=align><table border=0><tr><td>
<form class=frm runat="server">
<table border=0 cellpadding=3>
<tr>
<td class=lbl>Password:</td>
<td><input runat="server" type=password class=txt id="pw" maxlength=20 size=20></td>
<td runat="server" class=err id="pw_err"> </td>
</tr>
<tr>
<td class=lbl>Confirm Password:</td>
<td><input runat="server" type=password class=txt id="confirm_pw" maxlength=20 size=20></td>
<td runat="server" class=err id="confirm_pw_err"> </td>
</tr>
<tr>
<td class=lbl>First Name:</td>
<td><input runat="server" type=text class=txt id="firstname" maxlength=20 size=20></td>
<td runat="server" class=err id="firstname_err"> </td>
</tr>
<tr>
<td class=lbl>Last Name:</td>
<td><input runat="server" type=text class=txt id="lastname" maxlength=20 size=20></td>
<td runat="server" class=err id="lastname_err"> </td>
</tr>
<tr>
<td class=lbl><% Response.Write(Util.get_setting("PluralBugLabel","Bug")); %> Per Page:</td>
<td><input runat="server" type=text class=txt id="bugs_per_page" maxlength=3 size=3></td>
<td runat="server" class=err id="bugs_per_page_err"> </td>
</tr>
<tr>
<td colspan=3>
</td>
</tr>
<tr>
<td colspan=3 width=400>
<span class=smallnote>Default Query is what you see when you click on the "<% Response.Write(Util.get_setting("PluralBugLabel","bugs")); %>" link</span>
</td>
</tr>
<tr>
<td class=lbl>Default Query:</td>
<td>
<asp:DropDownList id="query" runat="server">
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td colspan=3>
</td>
</tr>
<tr>
<td colspan=3>
<span class=smallnote>
<br><br>
<div style="width: 400px;">
To receive email notifications when items are added or changed, fill in your email address, enable notifications, and then select "Auto-subscribe to all items" or the other options.<br>
<br>
</div>
</td>
</tr>
<tr>
<td class=lbl>Email:</td>
<td><input runat="server" type=text class=txt id="email" maxlength=40 size=40></td>
<td runat="server" class=err id="email_err"> </td>
</tr>
<tr>
<td class=lbl>Enable notifications:</td>
<td><asp:checkbox runat="server" class=txt id="enable_notifications"/></td>
<td> </td>
</tr>
<tr>
<td colspan=3>
<br>
<br>
<div class=smallnote style="width: 400px;">You can AUTOMATICALLY subscribe to receive notifications to items by selecting either "Auto-subscribe to all items" or by selecting the other options.<br>
</div>
</td>
</tr>
<tr>
<td class=lbl>Auto-subscribe to all items:</td>
<td><asp:checkbox runat="server" class=txt id="auto_subscribe"/></td>
<td> </td>
</tr>
<tr>
<td class=lbl nowrap>Auto-subscribe per project:</td>
<td>
<span class=smallnote>Hold down Ctrl key to select multiple items.</span>
<br>
<asp:ListBox id="project_auto_subscribe" runat="server" SelectionMode="Multiple" Rows=4>
</asp:ListBox >
</td>
<td> </td>
</tr>
<tr>
<td class=lbl>Auto-subscribe to all items ASSIGNED TO you:</td>
<td><asp:checkbox runat="server" class=txt id="auto_subscribe_own"/></td>
<td> </td>
</tr>
<tr>
<td class=lbl>Auto-subscribe to all items REPORTED BY you:</td>
<td><asp:checkbox runat="server" class=txt id="auto_subscribe_reported"/></td>
<td> </td>
</tr>
<tr>
<td colspan=3>
<br><br>
<div class=smallnote style="width: 400px;">You can REDUCE or INCREASE the amount of email you receive by selecting the following.<br>
</div>
</td>
</tr>
<tr>
<td class=lbl>New <% Response.Write(Util.get_setting("SingularBugLabel","Bug")); %> notifications only:</td>
<td><asp:checkbox runat="server" class=txt id="only_new_bug_notifications"/></td>
<td> </td>
</tr>
<tr>
<td class=lbl>Notify only when new or when status changes:</td>
<td><asp:checkbox runat="server" class=txt id="only_status_changes"/></td>
<td> </td>
</tr>
<tr>
<td class=lbl>Send notifications even for items you add or change:</td>
<td><asp:checkbox runat="server" class=txt id="send_to_self"/></td>
<td> </td>
</tr>
<tr>
<td colspan=3>
</td>
</tr>
<tr><td colspan=3 align=left>
<span runat="server" class=err id="msg"> </span>
</td></tr>
<tr>
<td colspan=2 align=center>
<input runat="server" class=btn type=submit id="sub" value="Update" OnServerClick="on_update">
<td> </td>
</td>
</tr>
</table>
</form>
</td></tr></table></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -