PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Control/Notification.php

https://bitbucket.org/onlinechessportal/onlinechessgameportal
PHP | 187 lines | 148 code | 9 blank | 30 comment | 24 complexity | 8f6ac77e90b6a623c793b20d095d0c8a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. require '../Model/Connect.php';
  3. require_once('PHPMailer/class.phpmailer.php');
  4. require_once('RegisterLogic.php');
  5. ob_start();
  6. ?>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml">
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  11. <title>Online Chess Portal </title>
  12. <!-- CSS Files -->
  13. <link href="css/sticky.full.css" rel="stylesheet" type="text/css" />
  14. <link href="css/reset.css" rel="stylesheet" type="text/css" />
  15. <link href="css/Form.css" rel="stylesheet" type="text/css" />
  16. <link href="css/style.css" rel="stylesheet" type="text/css" />
  17. <link rel="stylesheet" type="text/css" href="css/superfish.css" media="screen" />
  18. <link rel="stylesheet" type="text/css" href="css/jquery.gritter.css" />
  19. <!-- End of CSS Files -->
  20. <!-- Javascript Files -->
  21. <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
  22. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
  23. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
  24. <script type="text/javascript" src="javascript/jquery.cycle.all.js"></script>
  25. <script type="text/javascript" src="javascript/superfish.js"></script>
  26. <script type="text/javascript" src="javascript/dd.min.js"></script>
  27. <script type="text/javascript" src="javascript/popup-window.js"></script>
  28. <script type="text/javascript" src="javascript/wufoo.js"></script>
  29. <script type="text/javascript" src="js/sticky.full.js"></script>
  30. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  31. <script type="text/javascript">google.load('jquery', '1.5');</script>
  32. <script type="text/javascript" src="js/jquery.gritter.js"></script>
  33. <script type="text/javascript">
  34. function popups(x, id, type) {
  35. $.extend($.gritter.options, {
  36. class_name: 'gritter-light', // for light notifications (can be added directly to $.gritter.add too)
  37. position: 'bottom-right', // possibilities: bottom-left, bottom-right, top-left, top-right
  38. fade_in_speed: 100, // how fast notifications fade in (string or int)
  39. fade_out_speed: 100, // how fast the notices fade out
  40. time: 3000 // hang on the screen for...
  41. });
  42. $.gritter.add({
  43. // (string | mandatory) the heading of the notification
  44. title: 'Notification!',
  45. // (string | mandatory) the text inside the notification
  46. text: x,
  47. // (string | optional) the image to display on the left
  48. image: '../View/images/NotifyIcon.png',
  49. // (bool | optional) if you want it to fade out on its own or just sit there
  50. sticky: false,
  51. // (function) before the gritter notice is opened
  52. before_open: function(){
  53. if($('.gritter-item-wrapper').length == 2)
  54. {
  55. // Returning false prevents a new gritter from opening
  56. return false;
  57. }
  58. },
  59. after_open: function(e){
  60. if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  61. xmlhttp=new XMLHttpRequest();
  62. } else {// code for IE6, IE5
  63. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  64. }
  65. xmlhttp.onreadystatechange=function() {
  66. if (xmlhttp.readyState==4 && xmlhttp.status==200) {
  67. //alert(xmlhttp.responseText);
  68. }
  69. }
  70. xmlhttp.open("GET","../Control/ChangeNotifyStatus.php?Id="+id+"&Type="+type,true);
  71. xmlhttp.send();
  72. },
  73. });
  74. return false;
  75. }
  76. </script>
  77. <!-- End of Javascript Files -->
  78. </head>
  79. <body>
  80. </body>
  81. </head>
  82. <?php
  83. /*DeleteExpired();
  84. $Script = CheckNotification($Username);
  85. echo $Script;*/
  86. //echo '<script type="text/javascript"> popups() </script>';
  87. if(GameNotify($_SESSION['username']) || MsgNotify($_SESSION['username'])) {
  88. return true;
  89. } else {
  90. return false;
  91. }
  92. function GameNotify($Username) {
  93. //echo '<script language="javascript">alert("game")</script>';
  94. //echo '<script language="javascript">alert("'.$Username.'")</script>';
  95. $QueryTo = "SELECT * FROM `user` WHERE `us_username` ='".$Username."'";
  96. if($QueryToRun = mysql_query($QueryTo)) {
  97. if (mysql_num_rows($QueryToRun) == 1) {
  98. $ToId = mysql_result ($QueryToRun, 0, 'us_id');
  99. }
  100. }
  101. $Query = "SELECT *, TIMEDIFF(ADDTIME( ga_datecreated, '5:0:0' ), NOW()) AS ga_timediff FROM `games` WHERE ga_blackplayer = '".$ToId."' AND ga_notified = 1";
  102. if($QueryRun = mysql_query($Query)) {
  103. $QueryNumRows = mysql_num_rows ($QueryRun);
  104. //echo '<script language="javascript">alert("'.$QueryNumRows.'")</script>';
  105. if($QueryNumRows == 0) {
  106. return false;
  107. } else {
  108. //$Code = '';
  109. while($info = mysql_fetch_assoc($QueryRun)) {
  110. $Id = $info['ga_gameid'];
  111. $From = $info['ga_whiteplayer'];
  112. $Time = $info['ga_datecreated'];
  113. $TimeDiff = $info['ga_timediff'];
  114. $Query1 = "SELECT * FROM `memberprofile`, `user` WHERE mp_username = us_username AND us_id = '".$info['ga_whiteplayer']."'";
  115. if($Query1Run = mysql_query($Query1)) {
  116. while($info1 = mysql_fetch_assoc($Query1Run)) {
  117. $From = $info1['mp_fullname'];
  118. }
  119. }
  120. $Text = '<li><a href="../View/Play.php">From '.$From.' </br>Sent at '.$Time.'</a></li>';
  121. //$Code .= $Text;
  122. //echo $Text;
  123. //echo '<script type="text/javascript"> popups('.json_encode($Text).') </script>';
  124. ?>
  125. <script type="text/javascript">
  126. text = <?php echo json_encode($Text); ?>;
  127. id = <?php echo json_encode($Id); ?>;
  128. popups(text,id, 'Game');
  129. </script>
  130. <?php
  131. //ChangeNotifyStatus($Id);
  132. }
  133. //echo $Code;
  134. //echo '<script type="text/javascript"> popups('.$Code.') </script>';
  135. }
  136. } else {
  137. return false;
  138. }
  139. }
  140. function MsgNotify($Username) {
  141. //echo '<script language="javascript">alert("msg")</script>';
  142. $Query1 = "SELECT * FROM `notify` WHERE no_to = '".$Username."' AND no_notified = 1";
  143. if($Query1Run = mysql_query($Query1)) {
  144. $Query1NumRows = mysql_num_rows ($Query1Run);
  145. //echo '<script language="javascript">alert("'.$Query1NumRows.'")</script>';
  146. if($Query1NumRows == 0) {
  147. return false;
  148. } else {
  149. //$Code = '';
  150. while($info = mysql_fetch_assoc($Query1Run)) {
  151. $Id = $info['no_id'];
  152. $Query1 = "SELECT * FROM `memberprofile` WHERE mp_username = '".$info['no_from']."'";
  153. if($Query1Run = mysql_query($Query1)) {
  154. while($info1 = mysql_fetch_assoc($Query1Run)) {
  155. $From = $info1['mp_fullname'];
  156. }
  157. }
  158. $Text = '<li><a href="../View/Inbox.php">You have received a new message.</br> From '.$From.'</a></li>';
  159. //$Code .= $Text;
  160. //echo $Text;
  161. //echo '<script type="text/javascript"> popups('.json_encode($Text).') </script>';
  162. ?>
  163. <script type="text/javascript">
  164. text = <?php echo json_encode($Text); ?>;
  165. id = <?php echo json_encode($Id); ?>;
  166. popups(text,id, 'Msg');
  167. </script>
  168. <?php
  169. //ChangeNotifyStatus($Id);
  170. }
  171. //echo $Code;
  172. //echo '<script type="text/javascript"> popups('.$Code.') </script>';
  173. }
  174. } else {
  175. return false;
  176. }
  177. }
  178. ?>