-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuserFriends.aspx.cs
More file actions
195 lines (179 loc) · 5.75 KB
/
userFriends.aspx.cs
File metadata and controls
195 lines (179 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class userFriends : System.Web.UI.Page
{
bool myProfile = false;
int friendsQtd;
string profileId;
DataRow user;
protected void Page_Load(object sender, EventArgs e)
{
//testa pra ver se ta logado, se não tiver, volta pro login
if(Session["myemail"] == null)
Response.Redirect(FileName.Login);
// testa se tem querystring user, se não tiver, não faz nada...
if (Request.QueryString["user"] != null)
profileId = Request.QueryString["user"];
else
profileId = (string)Session["myemail"];
if (profileId == (string)Session["myemail"])
myProfile = true;
Load_friends();
try
{
user = Sqlds1.QueryToTable("SELECT name, img, bio FROM users WHERE email = '" + profileId + "';").Rows[0];
}
catch (IndexOutOfRangeException)
{
Response.Redirect("error/404");
}
Load_infos();
}
public void Load_infos()
{
//Opções que vão aparecer para todos, independente se é o perfil é meu ou não
lblName.Text = user["name"].ToString();
imgProfilePicture.ImageUrl = FileName.ImgFolder + user["img"].ToString();
lblBio.Text = "Este usuario nao tem bio";
if (user["bio"].ToString() != "")
lblBio.Text = user["bio"].ToString();
//controla o que aparece se o perfil for meu ou não
if (!myProfile)
{
//btnFollow.Visible = true;
//updateFeedBtn();
btnAddFriend.Visible = true;
updateFriendBtn();
}
}
public void Load_friends()
{
string command = "select if(f.id_target = '" + profileId + "', ur.name, ut.name) as 'fr_name', "
+ "if(f.id_target = '" + profileId + "', ur.img, ut.img) as 'fr_img', "
+ "if(f.id_target = '" + profileId + "', ur.email, ut.email) as 'fr_email'" +
"from friends f inner join users ur on ur.email = f.id_request inner join users ut on ut.email = f.id_target " +
"where status = 'a' and '" + profileId + "' in (f.id_target, f.id_request);";
//sets the query to a Table, witch can be used to list all the friends
DataTable friends = Sqlds1.QueryToTable(command);
friendsQtd = friends.Rows.Count;
//locates the div with id friends_facename
Control div = FindControl("friends_facename");
//creates an entry of each friend, entry with img and the name
foreach(DataRow friend in friends.Rows)
{
//create the objects that will be put in the page
WebControl entry = new WebControl(HtmlTextWriterTag.Div),
pic = new WebControl(HtmlTextWriterTag.Img),
a = new WebControl(HtmlTextWriterTag.A),
name = new WebControl(HtmlTextWriterTag.H5);
//set the attributes to the objects
entry.CssClass = "friends_entry";
pic.Attributes["src"] = FileName.ImgFolder + friend["fr_img"].ToString();
a.Attributes["href"] = FileName.Profile+"?user=" + friend["fr_email"];
name.Controls.Add(new LiteralControl(friend["fr_name"].ToString()));
//adds each control to it's parent and so
entry.Controls.Add(new LiteralControl("<div class='profile_img_wrapper pic_small'>"));
entry.Controls.Add(pic);
entry.Controls.Add(new LiteralControl("</div>"));
entry.Controls.Add(name);
a.Controls.Add(entry);
div.Controls.Add(a);
}
}
#region encapsulated
public DataRow CurUser {get { return user; } }
public int FriendsQtd { get { return friendsQtd; } }
#endregion
// daqui em diante é copiado do userProfile.aspx.cs
public void logout(object sender, EventArgs e)
{
this.Logout();
}
public void showFriends(object sender, EventArgs e)
{
Response.Redirect(FileName.FriendList+"?user=" + profileId);
}
public void btnPesq_Click(object sender, EventArgs e)
{
if (txtSearchBox.Text != "")
Response.Redirect(FileName.PesqPage+"?q="+txtSearchBox.Text);
}
#region "othersProfile"/*{{{*/
#region "Friend Request"/*{{{*/
public void friendRequest(object sender, EventArgs e)
{
string res = testForFriendship("status");
if (res == null || res == "d")
{
Sqlds1.InsertCommand = "insert into friends(id_request, id_target, date_sent) values "+
"('"+Session["myemail"]+"', '"+profileId+"', now());";
Sqlds1.Insert();
//if (!testForFeed())
//addFeed(e,e);
//Send Notification
}
else if (res == "p")
{
if (testForFriendship("id_request") == (string)Session["myemail"])
{
//opens lightbox asking if want to send another notification
}
else
{
Sqlds1.UpdateCommand = "UPDATE friends SET `status` = 'a', date_anwser = NOW() WHERE '"+
Session["myemail"]+"' in (id_target, id_request) AND '"+
profileId+"' in (id_target, id_request) ORDER BY id DESC LIMIT 1;";
Sqlds1.Update();
}
}
else if (res == "a")
{
//opens lightbox asking if want to cancel friendship
Sqlds1.UpdateCommand = "UPDATE friends SET `status` = 'd' WHERE '"+
Session["myemail"]+"' in (id_target, id_request) AND '"+
profileId+"' in (id_target, id_request)";
Sqlds1.Update();
}
updateFriendBtn();
}
public string testForFriendship(string column)
{
DataTable dt = Sqlds1.QueryToTable("select `status` as 'status', id_request "+
"from friends "+
"where '"+Session["myemail"]+"' in (id_target, id_request) AND '"+profileId+"' in (id_target, id_request) ORDER BY id DESC;");
if(dt.Rows.Count == 0)
return null;
else
return dt.Rows[0][column].ToString();
}
public void updateFriendBtn()
{
string res = testForFriendship("status");
if(res == null || res == "d")
{
btnAddFriend.Text = "Adicionar amigo?";
}
else if (res == "p")
{
if (testForFriendship("id_request") == (string)Session["myemail"])
{
btnAddFriend.Text = "Solicitacao enviada";
}
else
{
btnAddFriend.Text = "Aceitar Solicitacao?";
}
}
else if (res == "a")
{
btnAddFriend.Text = "Desfazer amizade?";
}
}
#endregion/*}}}*/
#endregion/*}}}*/
}