PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/mybookbag/messages.php

https://bitbucket.org/s2223902/mybookbag
PHP | 147 lines | 144 code | 0 blank | 3 comment | 1 complexity | 24f33854566f73d321a2e2dad8722d80 MD5 | raw file
  1. <?php
  2. session_start();
  3. include('db_connection.php');
  4. include('functions.php');
  5. //We check if the user is logged in
  6. if(isset($_SESSION['username']))
  7. {
  8. //We list his messages in a table
  9. //Two queries are executes, one for the unread messages and another for read messages
  10. $req1 = mysql_query('select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['id'].'" and m1.user1read="no" and users.id=m1.user2) or (m1.user2="'.$_SESSION['id'].'" and m1.user2read="no" and users.id=m1.user1)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc') or die ("fetch1:".mysql_error());
  11. $req2 = mysql_query('select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['id'].'" and m1.user1read="yes" and users.id=m1.user2) or (m1.user2="'.$_SESSION['id'].'" and m1.user2read="yes" and users.id=m1.user1)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc') or die ("fetch2:".mysql_error());
  12. ?>
  13. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  14. <html xmlns="http://www.w3.org/1999/xhtml">
  15. <head>
  16. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  17. <link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
  18. <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
  19. <link rel="stylesheet" href="css/formstyles.css" type="text/css" />
  20. <script type="text/javascript" src="js/Placeholders.js"></script>
  21. <script type="text/javascript">
  22. Placeholders.init({
  23. live: true,
  24. hideOnFocus: true});
  25. </script>
  26. <link href="css/toolbar.css" rel="stylesheet" type="text/css" />
  27. <title><?php echo $_SESSION['username'];?>'s Messages</title>
  28. </head>
  29. <body>
  30. <?php include ("php/random-bg.php"); ?>
  31. <div id="mainContainer">
  32. <div id="carbonForm2">
  33. <div id="logo2">
  34. <img src="img/logo.png" />
  35. <p>Welcome <b><?php echo $_SESSION['username'];?></b></p>
  36. </div>
  37. <ul id="nav">
  38. <li><a href="page.php">Home</a></li>
  39. <li><a href="mybooks.php">MyBookBag</a>
  40. <ul>
  41. <li><a href="mybooks.php">My Books</a></li>
  42. <li><a href="myebooks.php">My eBooks</a></li>
  43. <li><a href="myjournals.php">My journals</a></li>
  44. <li><a href="adddoc.php">Add Books</a></li>
  45. </ul>
  46. </li>
  47. <li class="current"><a href="friends.php">My Friends</a>
  48. <ul>
  49. <li><a href="friends.php">My Friends</a></li>
  50. <li><a href="messages.php">Messages (<?php echo checkMessages();?>)</a></li>
  51. <li><a href="addfriend.php">Add friends</a></li>
  52. <li><a href="requests.php">Friend Requests</a></li>
  53. </ul>
  54. </li>
  55. <li><a href="settings.php">Settings</a>
  56. <ul>
  57. <li><a href="passreset.php">Change Password</a></li>
  58. </ul>
  59. </li>
  60. <li><a href="contact.php">Contact</a></li>
  61. <li><a href="logout.php">Log Out</a></li>
  62. </ul>
  63. <div class="fieldContainer">
  64. <p>This is the list of your messages:</p><br/>
  65. <p><a href="newmsg.php" class="link_new_pm">New Message</a><br /></p>
  66. <h3>Unread Messages(<?php echo intval(mysql_num_rows($req1)); ?>):</h3>
  67. <table>
  68. <tr>
  69. <th class="title_cell">Title</th>
  70. <th>Nb. Replies</th>
  71. <th>Participant</th>
  72. <th>Date of creation</th>
  73. </tr>
  74. <?php
  75. //We display the list of unread messages
  76. while($dn1 = mysql_fetch_array($req1))
  77. {
  78. ?>
  79. <tr>
  80. <td class="left"><a href="readmsg.php?id=<?php echo $dn1['id']; ?>"><?php echo htmlentities($dn1['title'], ENT_QUOTES, 'UTF-8'); ?></a></td>
  81. <td><?php echo $dn1['reps']-1; ?></td>
  82. <td><?php echo htmlentities($dn1['username'], ENT_QUOTES, 'UTF-8'); ?></td>
  83. <td><?php echo date('Y/m/d H:i:s' ,$dn1['timestamp']); ?></td>
  84. </tr>
  85. <?php
  86. }
  87. //If there is no unread message we notice it
  88. if(intval(mysql_num_rows($req1))==0)
  89. {
  90. ?>
  91. <tr>
  92. <td colspan="4" class="center">You have no unread message.</td>
  93. </tr>
  94. <?php
  95. }
  96. ?>
  97. </table>
  98. <br />
  99. <h3>Read Messages(<?php echo intval(mysql_num_rows($req2)); ?>):</h3>
  100. <table>
  101. <tr>
  102. <th class="title_cell">Title</th>
  103. <th>Nb. Replies</th>
  104. <th>Participant</th>
  105. <th>Date or creation</th>
  106. </tr>
  107. <?php
  108. //We display the list of read messages
  109. while($dn2 = mysql_fetch_array($req2))
  110. {
  111. ?>
  112. <tr>
  113. <td class="left"><a href="readmsg.php?id=<?php echo $dn2['id']; ?>"><?php echo htmlentities($dn2['title'], ENT_QUOTES, 'UTF-8'); ?></a></td>
  114. <td><?php echo $dn2['reps']-1; ?></td>
  115. <td><?php echo htmlentities($dn2['username'], ENT_QUOTES, 'UTF-8'); ?></td>
  116. <td><?php echo date('Y/m/d H:i:s' ,$dn2['timestamp']); ?></td>
  117. </tr>
  118. <?php
  119. }
  120. //If there is no read message we notice it
  121. if(intval(mysql_num_rows($req2))==0)
  122. {
  123. ?>
  124. <tr>
  125. <td colspan="4" class="center">You have no read message.</td>
  126. </tr>
  127. <?php
  128. }
  129. ?>
  130. </table>
  131. </div>
  132. </div>
  133. <?php
  134. }
  135. else
  136. {
  137. echo 'You must be logged to access this page.';
  138. }
  139. ?>
  140. </div>
  141. </div>
  142. </body>
  143. </html>