YaWK  24.1
Yet another WebKit
friendslist.php
Go to the documentation of this file.
1 <script type="text/javascript">
2  $(document).ready(function() {
3  $('#table-sort').dataTable( {
4  "bPaginate": false,
5  "bLengthChange": false,
6  "bFilter": true,
7  "bSort": true,
8  "bInfo": true,
9  "bAutoWidth": false
10  } );
11 
12  } );
13 </script>
14 <?php
15 use YAWK\backend;
16 use YAWK\sys;
17 use YAWK\user;
18 use YAWK\db;
19 use YAWK\language;
20 
21 /** @var $db db */
22 /** @var $lang language */
23 
24 echo "<script type=\"text/javascript\">
25 
26  function acceptFriend(id, uid, requestUsername, sessionUID) {
27  // var uid = $('#acceptBtn').attr('data-requestUsername');//Attribut auslesen und in variable speichern
28  $.ajax({ // do ajax request
29  url:'js/accept-friend.php',
30  type:'post',
31  data:'uid='+uid+'&requestUsername='+requestUsername+'&sessionUID='+sessionUID,
32  success:function(data){
33  if(! data ){
34  alert('Something went wrong!');
35  return false;
36  }
37  else {
38  $(data).hide().prependTo('#btnRow');
39  requestRow = '#requestRow'+id;
40  disconnectBtn = '#disconnectBtn'+id;
41  declineBtn = '#declineBtn'+id;
42  acceptBtn = '#acceptBtn'+id;
43  $(acceptBtn).fadeOut(320);
44  $(declineBtn).fadeOut(320);
45  $(disconnectBtn).fadeIn(820);
46  }
47  }
48  });
49  }
50 
51  function declineFriend(id, uid, requestUsername, sessionUID) {
52  // var uid = $('#acceptBtn').attr('data-requestUsername');//Attribut auslesen und in variable speichern
53  $.ajax({ // do ajax request
54  url:'js/decline-friend.php',
55  type:'post',
56  data:'id='+id+'&uid='+uid+'&requestUsername='+requestUsername+'&sessionUID='+sessionUID,
57  success:function(data){
58  if(! data ){
59  alert('Something went wrong!');
60  return false;
61  }
62  else {
63  $(data).hide().prependTo('#btnRow');
64  requestRow = '#requestRow'+id;
65  disconnectBtn = '#disconnectBtn'+id;
66  declineBtn = '#declineBtn'+id;
67  acceptBtn = '#acceptBtn'+id;
68  $('#acceptBtn').fadeOut(320);
69  $('#declineBtn').fadeOut(320);
70  $('#disconnectBtn').fadeIn(820);
71  $(requestRow).fadeOut(420);
72  }
73  }
74  });
75  }
76 
77  function disconnectFriend(id, friendUID, requestUsername, sessionUID)
78  {
79  $.ajax({ // do ajax request
80  url:'js/disconnect-friend.php',
81  type:'post',
82  // data:'name='+name+'&comment='+comment+'&id='+id,
83  data:'id='+id+'&friendUID='+friendUID+'&requestUsername='+requestUsername+'&sessionUID='+sessionUID,
84  success:function(data){
85  if(! data ){
86  alert('Something went wrong!');
87  return false;
88  }
89  else {
90  $(data).hide().prependTo('#friendBtn');
91  $('#unfriendBtn').hide(800);
92  $('#friendBtn').show();
93  }
94  }
95  });
96  $('#friendsRow'+friendUID).fadeOut(420);
97  }
98 
99  </script>";
100 ?>
101 <?php
102 // TEMPLATE WRAPPER - HEADER & breadcrumbs
103 echo "
104  <!-- Content Wrapper. Contains page content -->
105  <div class=\"content-wrapper\" id=\"content-FX\">
106  <!-- Content Header (Page header) -->
107  <section class=\"content-header\">";
108 /* draw Title on top */
109 echo backend::getTitle($lang['FRIENDS'], $lang['FRIENDS_SUBTEXT']);
110 echo"<ol class=\"breadcrumb\">
111  <li><a href=\"index.php\" title=\"$lang[DASHBOARD]\"><i class=\"fa fa-dashboard\"></i> $lang[DASHBOARD]</a></li>
112  <li><a href=\"index.php?page=users\" title=\"$lang[USERS]\"> $lang[USERS]</a></li>
113  <li><a href=\"index.php?page=friendslist\" class=\"active\" title=\"$lang[FRIENDS]\"> $lang[FRIENDS]</a></li>
114  </ol>
115  </section>
116  <!-- Main content -->
117  <section class=\"content\">";
118 /* page content start here */
119 
120 // check if parameter UID is set
121 if (isset($_GET['uid']))
122 { // if it's set load friends for given user id
123  $my_friends = user::getMyFriends($db, $_GET['uid'], 1, $lang);
124  $param_uid = 1;
125  $user = user::getUserNameFromID($db, $_GET['uid']);
126  $friends_title = "$lang[FRIENDS_OF] $user";
127 }
128 else
129 { // otherwise, load friendlist for logged-in user
130  $my_friends = user::getMyFriends($db, $_SESSION['uid'], 1, $lang);
132  $friends_title = $lang['FRIENDS_YOURS'];
133 }
134 ?>
135 <!-- btn clear log -->
136 <a class="btn btn-success pull-right" href="index.php?page=syslog&clear=1">
137  <i class="fa fa-trash-o"></i> &nbsp;<?php print $lang['SYSLOG_CLEAR']; ?></a>
138 
139 <div class="box box-default">
140  <div class="box-header with-border">
141  <h3 class="box-title"><?php echo $friends_title; ?></h3>
142  </div>
143  <div class="box-body">
144  <table style="width=100%;" class="table table-striped table-hover table-responsive" id="table-sort">
145  <thead>
146  <tr>
147  <td style="width=5%;" class="text-right">&nbsp;</td>
148  <td style="width=20%;"><strong><?php echo $lang['MY_FRIEND']; ?></strong></td>
149  <td style="width=5%;" class="text-center"><strong><?php echo $lang['FRIENDSHIP']; ?></strong></td>
150  <td style="width=10%;" id="since" class="text-center"><strong><?php echo $lang['SINCE']; ?></strong></td>
151  </tr>
152  </thead>
153  <tbody>
154  <?php
155 
156  // select friend requests
157  $request_friends = user::getMyFriends($db, $_SESSION['uid'], 0, $lang);
158  // prepare vars
159  $friend = '';
160  $friendB = '';
162 
163  // SHOW REQUESTS
164  // loop through friendship requests array
165  foreach ($request_friends AS $request)
166  { // format datetime
167  $time_ago = sys::time_ago($request['requestDate'], $lang);
168  if ($request['friendA'] !== $_SESSION['uid'])
169  {
170  $friendUID = $request['friendA'];
171  }
172  if ($request['friendB'] !== $_SESSION['uid'])
173  {
174  $friendUID = $request['friendB'];
175  }
176  $friend_username = user::getUserNameFromID($db, $friendUID);
177 
178  // prepare social buttons (accept, decline, disconnect)
179  if ($request['confirmed'] === '0')
180  {
181  $acceptBtn = "<button id=\"acceptBtn$request[id]\" onclick=\"acceptFriend('$request[id]','$friendUID', '$friend_username', '$_SESSION[uid]')\" class=\"btn btn-success\" title=\"accept\"><i class=\"fa fa-check\"></i> </button>";
182  $declineBtn = "<button id=\"declineBtn$request[id]\" onclick=\"declineFriend('$request[id]', '$friendUID', '$friend_username', '$_SESSION[uid]')\" class=\"btn btn-warning\" title=\"decline\"><i class=\"fa fa-ban\"></i> </button>";
183  $disconnectBtn = "<button id=\"disconnectBtn$request[id]\" data-requestUID=\"$friendUID\" style=\"display: none;\" class=\"btn btn-danger\" title=\"disconnect friendship\"><i class=\"fa fa-times-circle\"></i> </button>";
184 
185  if ($_SESSION['uid'] == $request['friendA'])
186  { // request sent info btn
187  $acceptBtn = "<button id=\"acceptBtn$request[id]\" class=\"btn btn-default\" disabled aria-disabled='true'>$lang[REQUEST_SENT]</button>";
188  // $declineBtn = '';
189  }
190  }
191  else
192  {
193  $friendBtn = '';
194  }
195 
196  if ($request['aborted'] != '1')
197  {
198  echo "<tr id=\"requestRow$request[id]\">
199  <td style=\"display:block; text-align: right\"><a href=\"index.php?page=user-edit&user=$friend_username\">"; echo user::getUserImage("backend", $friend_username, "img-circle", 50, 50); echo "</a></td>
200  <td style=\"display:block;\"><b><a href=\"index.php?page=user-edit&user=$friend_username\">".$friend_username."</a></b></td>
201  <td id=\"btnRow\" class=\"text-center\">".$acceptBtn."&nbsp;".$disconnectBtn."&nbsp;".$declineBtn."</td>
202  <td id=\"since\" class=\"text-center\">".$time_ago."</td>
203  </tr>";
204  }
205  }
206 
207  // SHOW FRIENDS
208  // loop through friends array
209  foreach ($my_friends AS $friend)
210  { // calculate time ago view
211  $time_ago = sys::time_ago($friend['confirmDate'], $lang);
212  // PREPARE FRIENDS FOR LIST
213  if (isset($param_uid) && $param_uid === 1)
214  { // prepare friendslist for given UID
215  if ($friend['friendA'] !== $_GET['uid'])
216  {
217  $friendUID = $friend['friendA'];
218  }
219  if ($friend['friendB'] !== $_GET['uid'])
220  {
221  $friendUID = $friend['friendB'];
222  }
223  }
224  else
225  { // preprare friendslist for logged in user (session uid)
226  if ($friend['friendA'] !== $_SESSION['uid'])
227  {
228  $friendUID = $friend['friendA'];
229  }
230  if ($friend['friendB'] !== $_SESSION['uid'])
231  {
232  $friendUID = $friend['friendB'];
233  }
234  }
235 
236  $friend_username = user::getUserNameFromID($db, $friendUID);
237 
238  if ($friend['confirmed'] === '1')
239  { // check if this is YOUR friendslist (logged in user)
240  // hide control button if its NOT your list
241  if (isset($_GET['uid']) && (!empty($_GET['uid'])))
242  { // GET UID is sent, that means this is NOT logged in users friendslist
243  $disconnectBtn = ''; // display no button
244  }
245  else if ($friendUID != $_SESSION['uid'])
246  { // otherwise: disconnect control button
247  $disconnectBtn = "<button id=\"disconnectFriendBtn$friend[id]\" onclick=\"disconnectFriend('$friend[id]', '$friendUID', '$friend_username', '$_SESSION[uid]')\" class=\"btn btn-danger\" title=\"disconnect friendship\"><i class=\"fa fa-times-circle\"></i> </button>";
248  }
249  else
250  { // in any other case, no controls.
251  $disconnectBtn = '';
252  }
253  }
254  else
255  {
256  $disconnectBtn = '';
257  }
258 
259  echo "<tr id=\"friendsRow$friendUID\">
260  <td class=\"text-right\"><a href=\"index.php?page=user-edit&user=$friend_username\"><div style=\"width:100%\"> "; echo user::getUserImage("backend", $friend_username, "img-circle", 50, 50); echo "</a></div></td>
261  <td><b><a href=\"index.php?page=user-edit&user=$friend_username\"><div style=\"width:100%\">".$friend_username."</div></a></b></td>
262  <td class=\"text-center\">".$disconnectBtn."</td>
263  <td id=\"since\" class=\"text-center\">".$time_ago."</td>
264  </tr>";
265  }
266  ?>
267  </tbody>
268  </table>
269  </div></div>
Backend class serves a few useful functions for the admin backend.
Definition: backend.php:27
Mysqli database class; returns db connection object.
Definition: db.php:16
The language class - support multilingual backend.
Definition: language.php:17
The sys class - handles yawk's system core functions.
Definition: sys.php:17
The default user class. Provide all functions to handle the user object.
Definition: user.php:17
$friendB
$friendUID
$friend
$request_friends
print $lang['SYSLOG_CLEAR']
$param_uid
$friends_title
function a
Definition: browser.js:14
type
Definition: menu-new.php:35
print $_GET['id']
Definition: page-edit.php:357
function i(e, t)
Definition: plyr.js:1
<!-- backend language -->< h3 >< i class="fa fa-language"></i > & nbsp
document ready(function() { $('a[data-confirm]').click(function(ev) { modal='#dataConfirmModal';var href=$(this).attr('href');var title=$(this).attr('title');var icon=$(this).attr('data-icon');if(!icon) { icon='fa fa-trash-o';} if(!$(modal).length) { $('body').append('< div id="dataConfirmModal" class="modal fade" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true">< div class="modal-dialog">< div class="modal-content">< div class="modal-header">< button type="button" class="close" data-dismiss="modal" aria-hidden="true">< i class="fa fa-times"></i ></button >< br >< div class="col-md-1">< h3 class="modal-title">< i class="'+icon+'"></i ></h3 ></div >< div class="col-md-11">< h3 class="modal-title" id="dataConfirmLabel">'+title+'</h3 ></div ></h3 ></div >< div class="modal-body"></div >< div class="modal-footer">< button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Abbrechen</button >< a type="button" class="btn btn-danger" id="dataConfirmOK">< i class="'+icon+'"></i > L &ouml;schen</a ></div ></div ></div ></div >');} $(modal).find('.modal-body').text($(this).attr('data-confirm'));$('#dataConfirmOK').attr('href', href);$(modal).modal({show:true});return false;});$('#terminateUser').click(function() { var terminate=window.confirm("ACHTUNG!\nDas wird Deinen Account permanent deaktivieren.\n"+"Bist Du Dir sicher, dass Du das tun willst?");if(terminate===true) { var terminateUser=window.confirm("Bist Du Dir wirklich ganz sicher?\n"+"Diese Aktion kann nicht rueckgaengig gemacht werden.");if(terminateUser===true) { $.get('system/templates/YaWK-bootstrap3/js/terminate-user.php', function(data) { if(data==="true") { setTimeout("window.location='logout.html'", 0);} else { alert("Fehler: "+data);} });} } });function dismissNotifications() { $.ajax({ url:'js/dismiss-notifications.php', type:'POST', success:function(data) { if(!data) { alert('Something went wrong!');return false;} } });$("#bell-label").fadeOut();$('#notification-header').html('You have 0 notifications');$('#notification-menu').fadeOut();} $("#dismiss").click(function() { dismissNotifications();});function disableButtons(delay) { $('#loginButton').removeClass().addClass('btn btn-success disabled').attr('id', 'LOGIN_FORBIDDEN');$('#resetPasswordButton').removeClass().addClass('btn btn-danger disabled');setTimeout(function() { $('#LOGIN_FORBIDDEN').attr('id', 'loginButton').removeClass().addClass('btn btn-success');$('#resetPasswordButton').removeClass().addClass('btn btn-danger');}, delay);} $("#loginButton").click(function(){ if($('#loginButton').length > 0) { if($('#loginButton').hasClass('btn') &&$('#loginButton').hasClass('btn-success') &&$('#loginButton').hasClass('disabled')) { } else { $("#loginForm").submit();disableButtons(10000);} } else if($('#LOGIN_FORBIDDEN').length > 0) { if($('#LOGIN_FORBIDDEN').hasClass('btn') &&$('#LOGIN_FORBIDDEN').hasClass('btn-success') &&$('#LOGIN_FORBIDDEN').hasClass('disabled')) { } else { } } });$("#blockedBtn").hover(function() { $("#blockedBtn").hide();$("#askBtn").fadeIn(820);});})