PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/ajax/previewarchives.php

https://github.com/steveworkman/Uni-Sport
PHP | 183 lines | 164 code | 11 blank | 8 comment | 14 complexity | 3972ea6e38ec2efa3af607f49c6e637e MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1
  1. <?php
  2. include("../inc/connect.inc.php");
  3. // This is the AJAX function for searching people.
  4. header("Content-Type: text/xml; charset=UTF-8");
  5. $str = trim($_POST['str']);
  6. $user = $_POST['uid'];
  7. // Construct the dates
  8. $fromdate = date("Y-m-d G:i:s",mktime(0,0,0,$_POST['fmon'], $_POST['fday'], $_POST['fyr']));
  9. $todate = date("Y-m-d G:i:s",mktime(0,0,0,$_POST['tmon'], $_POST['tday'], $_POST['tyr']));
  10. if (!empty($str))
  11. {
  12. echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
  13. echo "<root>";
  14. switch($_POST['type'])
  15. {
  16. case 'events':
  17. // Events
  18. $eq = "SELECT event_id, name, description FROM events WHERE eventdatetime BETWEEN '".$fromdate."' AND '".$todate."'";
  19. $eres = mysql_query($eq)
  20. or die(mysql_error());
  21. while($erow = mysql_fetch_array($eres))
  22. {
  23. if(stristr($erow['description'], $str) || stristr($erow['name'], $str))
  24. {
  25. echo "<event>";
  26. echo "<id>".$erow['event_id']."</id>";
  27. echo "<name>".$erow['name']."</name>";
  28. echo "<desc>".stripslashes(substr(str_replace('</em>', '',str_replace('<em>', '',str_replace('<br />', '',$erow['description']))),0, 35))."...</desc>";
  29. echo "</event>";
  30. }
  31. }
  32. break;
  33. case 'news':
  34. // News
  35. $nq = "SELECT article_id, heading, text FROM newsarticles WHERE submittedon BETWEEN '".$fromdate."' AND '".$todate."'";
  36. $nres = mysql_query($nq)
  37. or die(mysql_error());
  38. while($nrow = mysql_fetch_array($nres))
  39. {
  40. if(stristr($nrow['heading'], $str))
  41. {
  42. echo "<news>";
  43. echo "<id>".$nrow['article_id']."</id>";
  44. echo "<heading>".$nrow['heading']."</heading>";
  45. echo "<text>".stripslashes(substr(str_replace('</em>', '',str_replace('<em>', '',str_replace('<br />', '',$nrow['text']))),0, 35))."...</text>";
  46. echo "</news>";
  47. }
  48. }
  49. break;
  50. case 'nletter':
  51. // Newsletters
  52. $nq = "SELECT newsletter_id, title, path FROM newsletters WHERE submittedon BETWEEN '".$fromdate."' AND '".$todate."'";
  53. $nres = mysql_query($nq)
  54. or die(mysql_error());
  55. while($nrow = mysql_fetch_array($nres))
  56. {
  57. if(stristr($nrow['title'], $str))
  58. {
  59. echo "<nletter>";
  60. echo "<id>".$nrow['newsletter_id']."</id>";
  61. echo "<title>".$nrow['title']."</title>";
  62. echo "<path>".$nrow['path']."</path>";
  63. echo "</nletter>";
  64. }
  65. }
  66. break;
  67. case 'match':
  68. // Matches with current squads
  69. $mq = "SELECT report_id, opposition, name, home_score, opp_score FROM playedmatches, squads ".
  70. "WHERE date BETWEEN '".$fromdate."' AND '".$todate."' ".
  71. "AND playedmatches.squad_id = squads.squad_id";
  72. $mres = mysql_query($mq)
  73. or die(mysql_error());
  74. while($mrow = mysql_fetch_array($mres))
  75. {
  76. if(stristr($mrow['opposition'], $str) || stristr($mrow['name'], $str))
  77. {
  78. echo "<match>";
  79. echo "<id>".$mrow['report_id']."</id>";
  80. echo "<title>".stripslashes($mrow['name'])." ".$mrow['home_score']. " - ".$mrow['opp_score']." ".stripslashes($mrow['opposition'])."</title>";
  81. echo "</match>";
  82. }
  83. }
  84. // Matches with history squads
  85. $mhq = "SELECT report_id, opposition, name, home_score, opp_score FROM playedmatches, squadhistory ".
  86. "WHERE date '".$fromdate."' AND '".$todate."' ".
  87. "AND playedmatches.squad_id = squadhistory.squad_id";
  88. $mhres = mysql_query($mhq)
  89. or die(mysql_error());
  90. while($mhrow = mysql_fetch_array($mhres))
  91. {
  92. if(stristr($mhrow['opposition'], $str) || stristr($mhrow['name'], $str))
  93. {
  94. echo "<match>";
  95. echo "<id>".$mhrow['report_id']."</id>";
  96. echo "<title>".$mhrow['name']." ".$mhrow['home_score']. " - ".$mhrow['opp_score']." ".$mhrow['opposition']."</title>";
  97. echo "</match>";
  98. }
  99. }
  100. break;
  101. //Pictures
  102. case 'picbyu':
  103. echo "<type>picbyu</type>";
  104. echo "<uid>".$user."</uid>";
  105. $uq = "SELECT picture_id, comment, thumb FROM pictures ".
  106. "WHERE user_id = '".$user."' ".
  107. "AND date BETWEEN '".$fromdate."' AND '".$todate."' ".
  108. "LIMIT 9";
  109. $ures = mysql_query($uq)
  110. or die(mysql_error());
  111. while ($urow = mysql_fetch_array($ures))
  112. {
  113. echo "<pic>";
  114. echo "<id>".$urow['picture_id']."</id>";
  115. echo "<caption>".htmlspecialchars($urow['comment'])."</caption>";
  116. echo "<thumb>".$urow['thumb']."</thumb>";
  117. echo "</pic>";
  118. }
  119. break;
  120. case 'picofu':
  121. echo "<type>picofu</type>";
  122. echo "<uid>".$user."</uid>";
  123. $uq = "SELECT pictures.picture_id, comment, thumb FROM pictures, user_picture ".
  124. "WHERE user_picture.user_id = '".$user."' ".
  125. "AND pictures.picture_id = user_picture.picture_id ".
  126. "AND date BETWEEN '".$fromdate."' AND '".$todate."' ".
  127. "LIMIT 9";
  128. $ures = mysql_query($uq)
  129. or die(mysql_error());
  130. while ($urow = mysql_fetch_array($ures))
  131. {
  132. echo "<pic>";
  133. echo "<id>".$urow['picture_id']."</id>";
  134. echo "<caption>".htmlspecialchars($urow['comment'])."</caption>";
  135. echo "<thumb>".$urow['thumb']."</thumb>";
  136. echo "</pic>";
  137. }
  138. break;
  139. case 'caption':
  140. echo "<type>caption</type>";
  141. echo "<uid>".$user."</uid>";
  142. $pq3 = "SELECT picture_id, comment, thumb FROM pictures ".
  143. "WHERE date BETWEEN '".$fromdate."' AND '".$todate."' ";
  144. $pres3 = mysql_query($pq3)
  145. or die(mysql_error());
  146. $counter = 0;
  147. while ($prow3 = mysql_fetch_array($pres3))
  148. {
  149. if (stristr($prow3['comment'], $str))
  150. {
  151. if ($counter < 9)
  152. {
  153. echo "<pic>";
  154. echo "<id>".$prow3['picture_id']."</id>";
  155. echo "<caption>".htmlspecialchars($prow3['comment'])."</caption>";
  156. echo "<thumb>".$prow3['thumb']."</thumb>";
  157. echo "</pic>";
  158. $counter++;
  159. }
  160. }
  161. }
  162. break;
  163. }
  164. echo "</root>";
  165. }
  166. else
  167. {
  168. echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
  169. echo "<root>";
  170. echo "</root>";
  171. }
  172. ?>