PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/View/Inbox.php

https://bitbucket.org/onlinechessportal/onlinechessgameportal
PHP | 503 lines | 428 code | 62 blank | 13 comment | 69 complexity | 43e98444494655a8870b0a008f203ea1 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. require '../Model/Connect.php';
  3. require '../Control/RegisterLogic.php';
  4. require '../Control/LoginLogic.php';
  5. require '../Control/SendNotification.php';
  6. require '../Control/CreateClubLogic.php';
  7. require '../Control/DBCreate.php';
  8. ob_start();
  9. $UserNm=$_SESSION['username'];
  10. $Role = $_SESSION['role'];
  11. if(isset($_GET['id'])) {
  12. $SearchName = $_GET['id'];
  13. $SearchID = GetSearchID($SearchName);
  14. } else {
  15. $SearchID = $UserNm;
  16. }
  17. function GetSearchID($SearchName) {
  18. $GetID = "SELECT mp_username FROM memberprofile WHERE mp_fullname = '".$SearchName."' ";
  19. $ResultID = mysql_query($GetID);
  20. if ($ResultID) {
  21. $rows = mysql_num_rows($ResultID);
  22. while($info = mysql_fetch_assoc( $ResultID)) {
  23. return $info['mp_username'];
  24. }
  25. }
  26. }
  27. ?>
  28. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  29. <html xmlns="http://www.w3.org/1999/xhtml">
  30. <head>
  31. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  32. <title>Online Chess Portal </title>
  33. <!-- CSS Files -->
  34. <link href="css/reset.css" rel="stylesheet" type="text/css" />
  35. <link href="css/screen.css" rel="stylesheet" type="text/css" />
  36. <link href="css/style.css" rel="stylesheet" type="text/css" />
  37. <link rel="stylesheet" type="text/css" href="css/superfish.css" media="screen" />
  38. <link rel="stylesheet" href="css/ToolTip.css" type="text/css" />
  39. <link rel="stylesheet" type="text/css" href="css/jquery.gritter.css" />
  40. <!-- End of CSS Files -->
  41. <!-- Javascript Files -->
  42. <script type="text/javascript" src="javascript/jquery1.3.2.js"></script>
  43. <script type="text/javascript" src="javascript/jquery.cycle.all.js"></script>
  44. <script type="text/javascript" src="javascript/popup-window.js"></script>
  45. <script type="text/javascript" src="javascript/jquery.js"></script>
  46. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  47. <script type="text/javascript">google.load('jquery', '1.5');</script>
  48. <script type="text/javascript" src="js/jquery.gritter.js"></script>
  49. <script type="text/javascript">
  50. $(document).ready(function(){
  51. $(".menu2 a").append("<em></em>");
  52. $(".menu2 a").hover(function() {
  53. $(this).find("em").animate({opacity: "show", top: "-75"}, "slow");
  54. var hoverText = $(this).attr("title");
  55. $(this).find("em").text(hoverText);
  56. }, function() {
  57. $(this).find("em").animate({opacity: "hide", top: "-85"}, "fast");
  58. });
  59. });
  60. <!--popup-->
  61. var time_interval = setInterval(
  62. function ()
  63. {
  64. $('#popup').load('../Control/Notification.php').fadeIn("slow");
  65. }, 5000); // refresh every 5000 milliseconds
  66. </script>
  67. <script type="text/javascript">
  68. function CheckMessage() {
  69. MID=document.forms[0].MessageID
  70. //if(MID.length == undefined) {
  71. //MID.length = 1;
  72. //}
  73. //alert(MID.length);
  74. AlertFlag = 0
  75. for (i=0;i<MID.length;++i){
  76. //alert('i is '+i);
  77. //alert(MID[i].checked);
  78. if (MID[i].checked){
  79. //alert(MID[i].value);
  80. if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  81. xmlhttp=new XMLHttpRequest();
  82. } else {// code for IE6, IE5
  83. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  84. }
  85. xmlhttp.onreadystatechange=function() {
  86. if (xmlhttp.readyState==4 && xmlhttp.status==200) {
  87. //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  88. //alert(xmlhttp.responseText);
  89. location.href = "Inbox.php";
  90. }
  91. }
  92. var s = confirm('delete this message ?');
  93. if(s) {
  94. xmlhttp.open("GET","../Control/DeleteMessage.php?q="+MID[i].value,true);
  95. xmlhttp.send();
  96. //location.href = "Inbox.php";
  97. } else {
  98. alert ('deletion canceled');
  99. }
  100. AlertFlag = 1;
  101. }
  102. }
  103. if(AlertFlag != 1) {
  104. alert("You must select at least one message to Delete");
  105. }
  106. }
  107. </script>
  108. <!--popup-->
  109. <style type="text/css">
  110. table{
  111. border:1px solid white;
  112. }
  113. th
  114. {
  115. background-color:#CCCCCC;
  116. color:Black;
  117. background-image: url(images/dropdowntop.jpg);
  118. }
  119. td {
  120. font-family: Calibri;
  121. border: thin #CCCCCC;
  122. }
  123. #footer {
  124. background-color: #CCCCCC;
  125. color: #000000;
  126. font-family: Arial,Helvetica,sans-serif;
  127. font-size: 10px;
  128. height: 50px;
  129. margin-top: 0;
  130. text-transform: capitalize;
  131. width: 100%;
  132. }
  133. </style>
  134. <!-- End of Javascript Files -->
  135. </head>
  136. <body>
  137. <!-- Wrapper --><div id="mainPage" >
  138. <div id="wrapper">
  139. <div id="topbar"> <img src="images/icon1.png" alt="logo" width="42" height="41" class="logo" id='test' /><img src="images/logo.gif" alt="logo" width="322" height="41" class="logo1" id='test' />
  140. <div id="secnav">
  141. <ul>
  142. <li> <a href="../Control/LogoutLogic.php">Logout</a> </li>
  143. <li class="noimg"></li>
  144. </ul>
  145. </div>
  146. <div class="menu">
  147. <ul class="sf-menu">
  148. <li> <a class="on" href="Home_Login.php">HOME</a></li>
  149. <li> <?php if($_SESSION['role'] == 'SiteAdmin') {
  150. ?> <a href="SiteAdminProfile.php">
  151. <?php } else { ?>
  152. <a href="MemberProfile.php">
  153. <?php }
  154. $result = mysql_query("SELECT mp_fullname FROM memberprofile WHERE mp_username='".$_SESSION['username']."' ");
  155. $row = mysql_fetch_array($result);
  156. $Rows = mysql_num_rows($result);
  157. if($_SESSION['role'] == 'SiteAdmin' || $Rows == 0) {
  158. echo 'Profile';
  159. } else {
  160. echo $row['mp_fullname'];
  161. }?></a>
  162. </li>
  163. <li> <a href="SearchClub.php">Clubs</a> </li>
  164. <li> <a href="Inbox.php">Messages</a> </li>
  165. </ul>
  166. </div> </div><!-- menu end-->
  167. <div id="content">
  168. <div class="froms">
  169. <span id="popup"></span><form >
  170. <?php
  171. $result = mysql_query("SELECT * FROM notify WHERE no_to='".$UserNm."' GROUP BY no_ID ORDER BY `no_timestamp` DESC ");
  172. echo "<table width='100%' table border='2' style='border:#999999'>";
  173. $QueryNumRows = mysql_num_rows ($result);
  174. if ($QueryNumRows == 0) {
  175. echo '<script language="javascript">alert("No messages to display")</script>';
  176. } else {
  177. while($row = mysql_fetch_array($result))
  178. {
  179. $To = $row['no_to'];
  180. $FromEmail = $row['no_from'];
  181. $Message = $row['no_message'];
  182. $MID = $row['no_id'];
  183. $Inbox_Timestamp = date('d-M-Y @ h:i:s',$row['no_timestamp']);
  184. $From = '';
  185. $GetNameFrom = "SELECT mp_fullname FROM memberprofile WHERE mp_username = '".$FromEmail."' ";
  186. $ResultNameFrom = mysql_query($GetNameFrom);
  187. if ($ResultNameFrom) {
  188. $rows = mysql_num_rows($ResultNameFrom);
  189. while($info = mysql_fetch_assoc( $ResultNameFrom)) {
  190. $From = $info['mp_fullname'];
  191. }
  192. }?>
  193. <div><?php
  194. echo "<tr> ";?>
  195. <td><input type="checkbox" name="MessageID" value="<?php echo $MID ?>"/>
  196. <?php
  197. //get the profile picture , name, home town
  198. $GetDetails = mysql_query("SELECT mp_currentcity, mp_imagename FROM memberprofile WHERE mp_fullname = '".$From."' ");
  199. $HomeTown = mysql_result($GetDetails, 0, 'mp_currentcity');
  200. $ImgName = mysql_result($GetDetails, 0, 'mp_imagename');
  201. ?>
  202. <strong><a href="MemberProfile.php?id=<?php echo $From?>" class="tooltip"><?php echo $From?><span class="help"><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="UserImages/<?php echo $ImgName?>" height="48" width="48" /><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $From?></em><?php echo $HomeTown?></span></a></strong> <?php echo " ".$Inbox_Timestamp?><br/><?php echo $Message ?><hr/>
  203. <?php
  204. echo "</td><td><a href=\"InboxDetails.php?mid=$MID\" >Read More...</a></td></tr>";
  205. echo "</tr></div>";
  206. }
  207. }
  208. echo "</table>";
  209. ?>
  210. </form>
  211. <form method="post">
  212. <input type="hidden" name="step1" value="3"/>
  213. <?php if($QueryNumRows > 0) {?>
  214. <input type="button" value="Delete" name="Delete" onclick="CheckMessage()" class="Buttonview" />
  215. <?php } ?>
  216. </form>
  217. </div>
  218. </div>
  219. <div id="sidebar">
  220. <li>
  221. <!--------------------------------------------------------------->
  222. <h2>Up Coming Events </h2>
  223. <ul>
  224. <li class="noimg"> <a href="#" class="content" onclick="popup_show('popup_messageMember', 'popup_drag_messageMember', 'popup_exit_messageMember', 'screen-center', 0, 0);">New Message</a> </li>
  225. <li class="noimg"> <a href="#" class="content" onclick="popup_show('popup_messageClub', 'popup_drag', 'popup_exit', 'screen-center', 0, 0);">New Message-Club</a> </li>
  226. </ul>
  227. </li>
  228. </div>
  229. <!-- topbar-->
  230. <layer>
  231. <ul id="navigation">
  232. <li class="home"><a href="Home_Login.php" title="Home"></a></li>
  233. <li class="play"><a href="Play.php" title="Play Chess"></a></li>
  234. <li class="photos"><a href="Inbox.php" title="Inbox"></a></li>
  235. <li class="club"><a href="SearchClub.php" title="Clubs"></a></li>
  236. <li class="settings"><a href="Settings.php" title="Settings"></a></li>
  237. </ul>
  238. </layer>
  239. <script type="text/javascript">
  240. $(function() {
  241. $('#navigation a').stop().animate({'marginLeft':'-90px'},100);
  242. $('#navigation > li').hover(
  243. function () {
  244. $('a',$(this)).stop().animate({'marginLeft':'-70px'},100);
  245. },
  246. function () {
  247. $('a',$(this)).stop().animate({'marginLeft':'-90px'},100);
  248. }
  249. );
  250. });
  251. </script>
  252. <div class="clear"></div>
  253. <div id="footers">
  254. <div style="float:right"><div class="fotterlast">
  255. <a href="#" title="About Us">About Us</a>
  256. |
  257. <a href="#" title="Terms of Service">Terms of Service</a>
  258. |
  259. <a href="#" title="Privacy Statement">Privacy</a>
  260. |
  261. <a href="Contact.php" title="Contact Us">Contact Us</a>
  262. </div></div>
  263. <div style="float:Left"><div class="fotterlastdesing">Designed by SEP_WE_05 Team.</div></div>
  264. </div>
  265. </div></div>
  266. <div class="sample_popup" id="popup_messageClub" style="display: none;">
  267. <div class="menu_form_header" id="popup_drag">
  268. <img class="menu_form_exit" id="popup_exit" src="images/form_exit.png" alt="exit" />
  269. &nbsp;&nbsp;&nbsp;New Message Club
  270. </div>
  271. <div class="menu_form_body">
  272. <form action="" method="post">
  273. <table>
  274. <tr>To:</tr><br />
  275. <tr><input type="text" class="" name="to" id="to" placeholder="Type the club name here"/>
  276. <div class="">
  277. <ul class="">
  278. </ul>
  279. </div>
  280. <script src="js/primary1.js"></script>
  281. <script src="js/primaryClub.js"></script>
  282. </tr><br />
  283. <tr>Message:</tr><br />
  284. <tr><textarea rows="5" cols="40" class="fillmessage" placeholder="Type the message here" name="message" id="message"></textarea></tr><br /><br />
  285. <tr>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  286. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  287. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  288. <input type="submit" id="send" name="send" value="Send" class="Buttonview" />&nbsp;&nbsp;&nbsp;
  289. <a href="Inbox.php" class="Buttonview">Cancel</a><input type="hidden" id="step" name="step" value="2" /></tr>
  290. </table>
  291. </form>
  292. </div> </div>
  293. <div class="sample_popup" id="popup_messageMember" style="display: none;">
  294. <div class="menu_form_header" id="popup_drag_messageMember">
  295. <img class="menu_form_exit" id="popup_exit_messageMember" src="images/form_exit.png" alt="exit" />
  296. &nbsp;&nbsp;&nbsp;New Message
  297. </div>
  298. <div class="menu_form_body">
  299. <form action="" method="post">
  300. <table>
  301. <tr><label class="contentHeading">To:</tr><br />
  302. <tr><input type="text" class="autosuggest" name="to" id="to" placeholder="Type the name here" onblur="this.value=removeSpaces(this.value);/>
  303. <div class="dropdown">
  304. <ul class="result">
  305. </ul>
  306. </div>
  307. <script src="js/primary1.js"></script>
  308. <script src="js/primary.js"></script>
  309. </tr><br />
  310. <tr><label class="contentHeading">Message:</tr><br />
  311. <tr><textarea rows="5" cols="40" class="fillmessage" placeholder="Type the message here" name="message" id="message"></textarea></tr><br /><br />
  312. <tr>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  313. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  314. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  315. <input type="submit" id="send" name="send" value="Send" class="Buttonview" />&nbsp;&nbsp;&nbsp;
  316. <a href="Inbox.php" class="Buttonview">Cancel</a>
  317. <input type="hidden" id="step" name="step" value="1" /></tr>
  318. </table>
  319. </form>
  320. </div> </div>
  321. </body>
  322. </html>
  323. <?php
  324. if(isset($_POST['step'])) {
  325. if($_POST['step'] == 1) {
  326. $Notify = new Notification();
  327. $MsgTo1 = $_POST['to'];
  328. $MsgTo = substr($MsgTo1,8);
  329. echo $Message = $_POST['message'];
  330. echo $User = $_SESSION['username'];
  331. echo $time = time();
  332. if(isset($_POST['club'])) {
  333. $Club = $_POST['club'];
  334. }
  335. $GetUsernameTo = "SELECT mp_username FROM memberprofile WHERE mp_fullname = '".$MsgTo."' ";
  336. $ResultUsernameTo = mysql_query($GetUsernameTo);
  337. if ($ResultUsernameTo) {
  338. $rows = mysql_num_rows($ResultUsernameTo);
  339. while($info = mysql_fetch_assoc( $ResultUsernameTo)) {
  340. echo $To = $info['mp_username'];
  341. }
  342. }
  343. $sql = "SELECT max(no_ID)+1 AS x FROM notify ";
  344. $ResultSql = mysql_query($sql);
  345. if ($ResultSql) {
  346. $rows = mysql_num_rows($ResultSql);
  347. while($info = mysql_fetch_assoc( $ResultSql)) {
  348. echo $MsgID = $info['x'];
  349. }
  350. } else {
  351. echo $MsgID = 1;
  352. }
  353. if(!$To || !$Message ) {
  354. echo 'Please enter the required details';
  355. } else {
  356. $Result = $Notify->SendMessage($To,$User,$Message,$MsgID,$time);
  357. if($Result) {
  358. echo '<script language="javascript">alert("Message sent successfully")</script>';
  359. if($QueryNumRows > 0) {
  360. echo '<script type="text/javascript"> window.location = "Inbox.php"</script>';
  361. } else {
  362. echo '<script type="text/javascript"> window.location = "MemberProfile.php"</script>';
  363. }
  364. } else {
  365. echo '<script language="javascript">alert("Message sending error. Try again later")</script>';
  366. if($QueryNumRows > 0) {
  367. echo '<script type="text/javascript"> window.location = "Inbox.php"</script>';
  368. } else {
  369. echo '<script type="text/javascript"> window.location = "MemberProfile.php"</script>';
  370. }
  371. }
  372. }
  373. }
  374. if($_POST['step'] == 2) {
  375. $Notify = new Notification();
  376. $Message = $_POST['message'];
  377. $User = $_SESSION['username'];
  378. $time = time();
  379. $GetNameFrom = "SELECT mp_fullname FROM memberprofile WHERE mp_username = '".$User."' ";
  380. $ResultNameFrom = mysql_query($GetNameFrom);
  381. if ($ResultNameFrom) {
  382. $rows = mysql_num_rows($ResultNameFrom);
  383. while($info = mysql_fetch_assoc( $ResultNameFrom)) {
  384. $From = $info['mp_fullname'];
  385. }
  386. }
  387. $sql = "SELECT max(no_ID)+1 AS x FROM notify ";
  388. $ResultSql = mysql_query($sql);
  389. if ($ResultSql) {
  390. $rows = mysql_num_rows($ResultSql);
  391. while($info = mysql_fetch_assoc( $ResultSql)) {
  392. $MsgID = $info['x'];
  393. }
  394. }
  395. $Club = $_POST['to'];
  396. if(!$Club || !$Message ) {
  397. echo 'Please enter the required details';
  398. } else {
  399. //send message to the club members
  400. $ClubId = GetClubId($Club);
  401. $sql = "SELECT cm_member FROM clubmember WHERE cm_clubid = '".$ClubId."'";
  402. if ($result = mysql_query($sql)) {
  403. $rows = mysql_num_rows($result);
  404. $storeArray = Array();
  405. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  406. $storeArray[] = $row['cm_member'];
  407. }
  408. for ( $i=0 ; $i<$rows ; $i++ )
  409. {
  410. $To = $storeArray[$i];
  411. $send = $Notify->SendMessage($To,$From,$Message,$MsgID,$time);
  412. if ($send) {
  413. $done = 1;
  414. }
  415. }
  416. } else {
  417. echo 'OOOPPPSSS';
  418. }
  419. if ($done == 1) {
  420. echo '<script language="javascript">alert("Message sent successfully")</script>';
  421. if($_SESSION['role'] == 'member' || $_SESSION['role'] == 'clubAdmin') {
  422. echo '<script type="text/javascript"> window.location = "../View/MemberProfile.php"</script>';
  423. } else {
  424. echo '<script type="text/javascript"> window.location = "../View/SiteAdminProfile.php"</script>';
  425. }
  426. } else {
  427. echo '<script language="javascript">alert("Message sending error. Try again later")</script>';
  428. if($_SESSION['role'] == 'member' || $_SESSION['role'] == 'clubAdmin') {
  429. echo '<script type="text/javascript"> window.location = "../View/MemberProfile.php"</script>';
  430. } else {
  431. echo '<script type="text/javascript"> window.location = "../View/SiteAdminProfile.php"</script>';
  432. }
  433. }
  434. }
  435. }
  436. }
  437. if(isset($_POST['Delete'])) {
  438. if(isset($_POST['step1'])) {
  439. }
  440. }
  441. ?>