PageRenderTime 57ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/normal.php

https://github.com/jaynathan79/CFAT-March-Madness
PHP | 299 lines | 229 code | 57 blank | 13 comment | 29 complexity | 76c4378a0060f6716e5b01d9393e6e75 MD5 | raw file
  1. <?php
  2. include("cfatheader.php");
  3. include("menu.php");
  4. function getRankFormat ($original, $hypothetical)
  5. {
  6. if( $hypothetical < $original )
  7. {
  8. $change = "<span class='right'>+".($original-$hypothetical)."</span>";
  9. }
  10. else if( $hypothetical > $original )
  11. {
  12. $change = "<span class='wrong'>-".($hypothetical-$original)."</span>";
  13. }
  14. else
  15. {
  16. $change = "+0";
  17. }
  18. return $change."&nbsp;(".$hypothetical.")";
  19. }
  20. // get sort style
  21. if( $_GET['sort'] != NULL )
  22. {
  23. $sortStyle = $_GET['sort'];
  24. }
  25. else
  26. {
  27. $sortStyle = 'main';
  28. }
  29. // get info about scoring systems
  30. $scoringInfo = array();
  31. $scoringDescriptions = "";
  32. $scoringTables = array();
  33. $scoringTypeNames = array();
  34. $scoringTypesQuery = "SELECT scoring_type name, scoring_info.display_name, description ".
  35. "FROM scores, scoring_info WHERE scores.scoring_type = scoring_info.type GROUP BY scoring_type ORDER BY display_name";
  36. $scoringTypes = mysql_query($scoringTypesQuery,$db) or die(mysql_error());
  37. $j = 0;
  38. while($scoringType = mysql_fetch_array($scoringTypes))
  39. {
  40. // store scoring system ids
  41. $scoringSystem = $scoringType['name'];
  42. $scoringTypeNames[$j] = $scoringSystem;
  43. // store display names and descriptions
  44. $scoringInfo[$scoringType['name']]['name'] = $scoringType['display_name'];
  45. $scoringInfo[$scoringType['name']]['description'] = $scoringType['description'];
  46. if( $scoringSystem != 'main' && $scoringSystem == $sortStyle )
  47. {
  48. // create a select list for each scoring type for sorting purposes
  49. $additionalSortingSources .= ", (SELECT id, score FROM scores WHERE scoring_type = '".$scoringSystem."' ) ".$scoringSystem."";
  50. // create a where condition for each scoring type for sorting purposes
  51. $additionalSortingConditions .= "AND ".$scoringSystem.".id = brackets.id ";
  52. }
  53. // create html descriptions of each scoring system
  54. // just get this from descriptions since the html is already generated
  55. $scoringTables[$j] = $scoringInfo[$scoringType['name']]['description'];
  56. $scoringDescriptions .= "\"".$scoringTables[$j]."\",";
  57. // get rankings for each scoring system
  58. $rankingQuery = "SELECT id, score FROM scores WHERE scoring_type = '".$scoringSystem."' ORDER BY score DESC";
  59. $ranking = mysql_query($rankingQuery,$db) or die(mysql_error());
  60. $i = 0;
  61. $rankCounter = 0;
  62. while($entry = mysql_fetch_array($ranking))
  63. {
  64. if( $rankCounter == 0 )
  65. {
  66. $topScore = $entry['score'];
  67. $prevScore = $topScore;
  68. $rankCounter =1;
  69. $i=1;
  70. }
  71. if( $entry['score'] != $prevScore )
  72. {
  73. $prevScore = $entry['score'];
  74. $rankCounter = $i;
  75. }
  76. $rankings[$scoringSystem][$entry['id']] = $rankCounter;
  77. $i++;
  78. }
  79. $j++;
  80. }
  81. $scoringDescriptions .= "\"\"";
  82. ?>
  83. <script type="text/javascript" src="js/wz_tooltip/wz_tooltip.js"></script>
  84. <script type="text/javascript">
  85. scoringDescriptions = new Array( <?php echo $scoringDescriptions; ?> );
  86. hideTip = true;
  87. lastVal = -1;
  88. function showScoring( e, val, delay )
  89. {
  90. hideTip = false;
  91. if( lastVal != val )
  92. {
  93. if(!e)
  94. {
  95. Tip(scoringDescriptions[val],DELAY,delay, FADEIN, 200, FADEOUT, 200);
  96. }
  97. else
  98. {
  99. // firefox and safari
  100. Tip(scoringDescriptions[val],DELAY,delay, FADEIN, 200, FADEOUT, 200);
  101. }
  102. lastVal = val;
  103. return true;
  104. }
  105. }
  106. function clearScoring()
  107. {
  108. hideTip = true;
  109. setTimeout( 'closeTip()', 500 );
  110. return true;
  111. }
  112. function closeTip()
  113. {
  114. if( hideTip == true )
  115. {
  116. UnTip();
  117. lastVal = -1;
  118. }
  119. }
  120. </script>
  121. <div class="full">
  122. <h2>The Standings </h2>
  123. <h3>WHERE DO YOU RANK?</h3>
  124. </div>
  125. <table class='scoredetail' align="center" width='100%'>
  126. <tr>
  127. <th><strong>Rank</strong></th>
  128. <th><strong>Name</strong></th>
  129. <th><strong>Score</strong></th>
  130. <th><strong>PPR</strong></th>
  131. <th><strong>Best</strong></th>
  132. <!--<th><strong><a href="standings.php?type=best">Best</a></strong></th>-->
  133. <th><strong>Tiebreaker</strong></th>
  134. <?php
  135. for( $i=0; $i<count($scoringTypeNames); $i++ )
  136. {
  137. echo "<th onmouseover='showScoring( event, ".$i.",0);' onmouseout='clearScoring();' >";
  138. if( $scoringTypeNames[$i] == $sortStyle )
  139. {
  140. echo "<div align=\"center\" class='selected_sort'>";
  141. }
  142. else
  143. {
  144. echo "<div align=\"center\">";
  145. }
  146. echo "<strong><a href=\"standings.php?type=normal&sort=".$scoringTypeNames[$i]."\">";
  147. echo $scoringInfo[$scoringTypeNames[$i]]['name']."</a></strong></div></th>";
  148. }
  149. ?>
  150. </tr>
  151. <?php
  152. $query = "SELECT
  153. main.id,
  154. main.name,
  155. main.score,
  156. best_main.score AS b_score,
  157. brackets.tiebreaker,
  158. brackets.63,
  159. brackets.userid,
  160. brackets.eliminated,
  161. ifnull((select supportedCharity from users where users.userid = brackets.userid), \"Feeding America\") as supportedCharity,
  162. (select paid from users u where u.userid = brackets.userid) as paid,
  163. (select userlevel from users u where u.userid = brackets.userid) as userlevel
  164. FROM
  165. scores main,
  166. best_scores best_main,
  167. brackets
  168. ".$additionalSortingSources."
  169. WHERE
  170. main.scoring_type = best_main.scoring_type AND
  171. main.id = best_main.id AND
  172. main.scoring_type = 'main' AND
  173. main.id = brackets.id
  174. ".$additionalSortingConditions."
  175. ORDER BY
  176. ".$sortStyle.".score DESC, best_main.score DESC,
  177. main.name ASC";
  178. //echo($query);
  179. $result = mysql_query($query,$db) or die(mysql_error());
  180. $eliminated=0;
  181. $top_score = -1;
  182. while($user = mysql_fetch_array($result))
  183. {
  184. //echo($userid."--".$user['userid']);
  185. if( $top_score < 0 )
  186. {
  187. $top_score = $user['score'];
  188. }
  189. // Print out the contents of each row into a table
  190. if ($userid == $user['userid'] )
  191. {
  192. echo '<tr class="thisuser">';
  193. }
  194. else
  195. {
  196. if( $user['eliminated'] > 0 )
  197. {
  198. echo "<tr class='eliminated'>";
  199. $eliminated=1;
  200. }
  201. else
  202. {
  203. echo "<tr>";
  204. }
  205. }
  206. echo "<td align='right'>&nbsp;&nbsp;".$rankings[$sortStyle][$user['id']]."</td><td>";
  207. $charity = ($user[userlevel]>0)?"Site Admin - Not eligible to win.":stripslashes($user['supportedCharity']);
  208. $donor = ($user[paid]==1)?"-DONOR-":"";
  209. echo "<a href=\"view.php?id=$user[id]\">" . strtoupper(stripslashes($user[name])) . "</a>";
  210. echo " <small><span style=\"color: green\">$donor</span></small>";
  211. echo "<br><small>$charity</small>";
  212. if ($user['eliminated'] > 0 & strtolower($useremail) == strtolower($_COOKIE['useremail'] )) {
  213. echo " - Eliminated";
  214. }
  215. echo "</td><td>";
  216. echo $user['score'];
  217. echo "</td><td>";
  218. echo $user['b_score']-$user['score'];
  219. echo "</td><td>";
  220. echo $user['b_score'];
  221. echo "</td><td>";
  222. echo $user['63'];
  223. echo " - ";
  224. echo $user['tiebreaker'];
  225. echo "</td>";
  226. for( $j=0; $j<count($scoringTypeNames); $j++ )
  227. {
  228. echo "<td onmouseover='showScoring( event, ".$j.",2000);' onmouseout='clearScoring();'>";
  229. echo getRankFormat( $rankings['main'][$user['id']], $rankings[$scoringTypeNames[$j]][$user['id']] )."</td>";
  230. }
  231. echo "</tr>";
  232. }
  233. ?>
  234. </table>
  235. <?php
  236. if( $eliminated==1 ) {
  237. echo "<span class='eliminated'>&nbsp;&nbsp;Eliminated&nbsp;&nbsp;</span>";
  238. }
  239. ?>
  240. <?php
  241. include("cfatfooter.php");
  242. ?>