Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.47 KB | None | 0 0
  1. <?php header("Content-type: image/png");
  2. // get install path of wordpress
  3. function find_wp_path() {
  4. $dir = dirname(__FILE__);
  5. do {
  6. if( file_exists($dir."/wp-load.php") ) {
  7. return $dir;
  8. }
  9. } while( $dir = realpath("$dir/..") );
  10. return null;
  11. }
  12. include_once( find_wp_path() . '/wp-load.php' );
  13. /************** Declare variables ****************/
  14. // get which stat to be displayed from uri
  15. $stats = $_GET['s'];
  16. // define defaults if no stats given
  17. if ( empty ( $_GET['s'] ) ) {
  18. $stats = 1;
  19. }
  20. $font1 = dirname( __FILE__ ).'/tahoma.ttf';
  21. $font2 = dirname( __FILE__ ).'/tahomabd.ttf';
  22. $lines = 1;
  23. $lineh = 24;
  24. // function to output alternating row colours
  25. function rows($rows) {
  26. global $lineh, $image;
  27. for ($i = 1; $i <= $rows; $i++) {
  28. $pich = $lineh + ($i * $lineh) + 8;
  29. if ($i % 2 != 0) {
  30. $rowcol = imagecolorallocate($image, 51, 51, 51);
  31. } else {
  32. $rowcol = imagecolorallocate($image, 71, 71, 71);
  33. }
  34. imagefilledrectangle ($image, 2, $pich + 1, 696, $pich + 22, $rowcol);
  35. }
  36. }
  37. // get title for titlebar and define number of rows
  38. $title = "FUSION F1 League";
  39. $rows = 30;
  40. switch ($stats) {
  41. case 1:
  42. $titleString = $title." ~ Race Attendance Div 1 ~ Top ".$rows;
  43. break;
  44. case 2:
  45. $titleString = $title." ~ Pole Positions ~ Top ".$rows;;
  46. break;
  47. case 3:
  48. $titleString = $title." ~ Race Wins ~ Top ".$rows;
  49. break;
  50. case 4:
  51. $titleString = $title." ~ Podiums ~ Top ".$rows;
  52. break;
  53. case 5:
  54. $titleString = $title." ~ Hall of Fame";
  55. break;
  56. case 6:
  57. $titleString = $title." ~ Race Attendance Div 2 ~ Top ".$rows;
  58. break;
  59. case 7:
  60. $titleString = $title." ~ Pole Positions Div 2 ~ Top ".$rows;;
  61. break;
  62. case 8:
  63. $titleString = $title." ~ Race Wins Div 2 ~ Top ".$rows;
  64. break;
  65. case 9:
  66. $titleString = $title." ~ Podiums Div 2 ~ Top ".$rows;
  67. break;
  68. case 10:
  69. $titleString = $title." ~ Hall of Fame ";
  70. break;
  71.  
  72. // get award rows
  73. $tablename = $wpdb->prefix . "fusion_f1_awards";
  74. //$awards = $wpdb->get_results( $wpdb->prepare(
  75. $awards = $wpdb->get_results(
  76. "
  77. SELECT seasonID
  78. FROM $tablename
  79. "
  80. );
  81. //) );
  82. $awardrows = $wpdb->num_rows;
  83. $rows = $awardrows;
  84. // get champion rows
  85. $tablename = $wpdb->prefix . "fusion_f1_results";
  86. $champs = $wpdb->get_results( $wpdb->prepare(
  87. "
  88. SELECT DISTINCT(seasonID) as season
  89. FROM $tablename
  90. WHERE seasonID > %d AND raceID > %d
  91. GROUP BY seasonID
  92. ",
  93. 0,
  94. 0
  95. ) );
  96. foreach ($champs as $val) {
  97. // get total champs across divisions
  98. $tablename = $wpdb->prefix . "fusion_f1_seasonparams";
  99. $divchamps = $wpdb->get_var(
  100. "
  101. SELECT SUM(divs) as season
  102. FROM $tablename
  103. "
  104. );
  105.  
  106.  
  107.  
  108. }
  109. $rows += $divchamps + 3;
  110. break;
  111. }
  112. // define image variables
  113. $boxh = ( $lineh * 2 ) + ($lineh * $rows) + 9;
  114. $image = imagecreatetruecolor ( 700, $boxh );
  115. $bgcol = imagecolorallocate($image, 34, 34, 34);
  116. $fgcol = imagecolorallocate($image, 51, 51, 51);
  117. $txcol = imagecolorallocate($image, 255, 255, 255);
  118. $txcol2 = imagecolorallocate($image, 204, 204, 204);
  119. $txcol3 = imagecolorallocate($image, 175, 175, 175);
  120. $ttcol = imagecolorallocate($image, 0, 200, 0);
  121. $stcol = imagecolorallocate($image, 168, 3, 41);
  122. $txgold = imagecolorallocate($image, 220, 210, 55);
  123. $txsilver = imagecolorallocate($image, 192, 192, 192);
  124. $txbronze = imagecolorallocate($image, 196, 125, 61);
  125. // create base image
  126. imagefill ($image, 0, 0, $bgcol);
  127.  
  128. // Create title bar
  129. $fsize = 11;
  130. imagefilledrectangle ($image, 2, 2, 697, $lineh + 6, $ttcol);
  131. $titleBox = imageTTFbbox( $fsize, 0, $font2, $titleString );
  132. $textwidth = abs( $titleBox[2] );
  133. imageTTFtext( $image, $fsize, 0, intval(348 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2)+2, $txcol, $font2, $titleString );
  134.  
  135. // add logos to titlebar
  136. $f1logo = "images/s_f1_logo.png";
  137. $f1 = imagecreatefrompng($f1logo);
  138. imagesavealpha($f1, true);
  139. imagecopy($image, $f1, 5, 5 , 0, 0, 57, 23);
  140. $aclogo = "images/s_ac_logo.png";
  141. $ac = imagecreatefrompng($aclogo);
  142. imagesavealpha($ac, true);
  143. imagecopy($image, $ac, 65, 5 , 0, 0, 26, 23);
  144.  
  145.  
  146. $fuslogo = "images/s_logo.png";
  147. $fus = imagecreatefrompng($fuslogo);
  148. imagesavealpha($fus, true);
  149. imagecopy($image, $fus, 672, 5 , 0, 0, 23, 23);
  150.  
  151. // create rows (alternate colours)
  152. rows($rows);
  153. // create column lines
  154. imagerectangle($image, 233, $lineh+8, 466, $boxh, $bgcol);
  155.  
  156. // ********************* Race Attendance *********************
  157. if ($stats == 1) {
  158. // column headings
  159. $ch[1] = "Driver";
  160. $ch[2] = "Races Attended";
  161. $ch[3] = "Races Finished (%)";
  162. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  163. $textwidth = abs( $titleBox[2] );
  164. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
  165. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  166. $textwidth = abs( $titleBox[2] );
  167. imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
  168. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  169. $textwidth = abs( $titleBox[2] );
  170. imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
  171.  
  172. // get attendance records for top 10
  173. $tablename = $wpdb->prefix . "fusion_f1_results";
  174. $races = $wpdb->get_results( $wpdb->prepare(
  175. "
  176. SELECT playerID, COUNT(playerID) as races
  177. FROM $tablename
  178. WHERE raceID > %d AND divID = 1
  179. GROUP BY playerID
  180. ORDER BY races DESC
  181. LIMIT %d
  182. ",
  183. 0,
  184. $rows ) );
  185. foreach ( $races as $val ) {
  186. // get player names
  187. $tablename = $wpdb->prefix . "fusion_f1_players";
  188. $player = $wpdb->get_var( $wpdb->prepare(
  189. "
  190. SELECT playerName
  191. FROM $tablename
  192. WHERE playerID = %s
  193. ",
  194. $val->playerID
  195. ) );
  196. // get races not finished
  197. $dnfdsq = "%D%";
  198. $tablename = $wpdb->prefix . "fusion_f1_results";
  199. $nonfinishes = $wpdb->get_var( $wpdb->prepare(
  200. "
  201. SELECT COUNT(resultID)
  202. FROM $tablename
  203. WHERE playerID = %d AND raceID > %d AND resultTime LIKE %s AND divID = 1
  204.  
  205. ",
  206. $val->playerID,
  207. 0,
  208. $dnfdsq
  209. ) );
  210. $finishes = $val->races-$nonfinishes;
  211. $percentfinishes = ($finishes/$val->races)*100;
  212. $finishes .= " (".round($percentfinishes)."%)";
  213. $pich = $lineh;
  214. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
  215. imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
  216. imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
  217. $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
  218. $txtwidth = abs( $box[2] );
  219. imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
  220. $box = imageTTFbbox( $fsize, 0, $font2, $finishes );
  221. $txtwidth = abs( $box[2] );
  222. imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $finishes );
  223. $lines++;
  224. }
  225. }
  226. // ********************* Pole Positions *********************
  227. if ($stats == 2) {
  228. // column headings
  229. $ch[1] = "Driver";
  230. $ch[2] = "Pole Positions";
  231. $ch[3] = "Poles Converted to Wins (%)";
  232. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  233. $textwidth = abs( $titleBox[2] );
  234. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
  235. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  236. $textwidth = abs( $titleBox[2] );
  237. imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
  238. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  239. $textwidth = abs( $titleBox[2] );
  240. imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
  241. // get pole positions for top 10
  242. $tablename = $wpdb->prefix . "fusion_f1_results";
  243. $races = $wpdb->get_results( $wpdb->prepare(
  244. "
  245. SELECT playerID, COUNT(playerID) as races
  246. FROM $tablename
  247. WHERE raceID > %d AND resultGrid = %d AND divID = 1
  248. GROUP BY playerID
  249. ORDER BY races DESC LIMIT %d
  250. ",
  251. 0,
  252. 1,
  253. $rows
  254. ) );
  255. // show top 10 pole positions
  256. $i = 1;
  257. foreach ( $races as $val ) {
  258. $tablename = $wpdb->prefix . "fusion_f1_players";
  259. $player = $wpdb->get_var( $wpdb->prepare(
  260. "
  261. SELECT playerName
  262. FROM $tablename
  263. WHERE playerID = %s
  264. ",
  265. $val->playerID
  266. ) );
  267. // get pole converted
  268. $tablename = $wpdb->prefix . "fusion_f1_results";
  269. $conversions = $wpdb->get_var( $wpdb->prepare(
  270. "
  271. SELECT COUNT(resultID)
  272. FROM $tablename
  273. WHERE playerID = %d AND raceID > %d AND resultGrid = %d AND resultPosition = %d AND divID = 1
  274. ",
  275. $val->playerID,
  276. 0,
  277. 1,
  278. 1
  279. ) );
  280. $percentconversions = ($conversions/$val->races)*100;
  281. $conversions .= " (".round($percentconversions)."%)";
  282. $pich = $lineh;
  283. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
  284. imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
  285. imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
  286. $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
  287. $txtwidth = abs( $box[2] );
  288. imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
  289. $box = imageTTFbbox( $fsize, 0, $font2, $conversions );
  290. $txtwidth = abs( $box[2] );
  291. imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $conversions );
  292. $lines++;
  293. $i++;
  294. }
  295. }
  296. // ********************* Race Wins *********************
  297. if ($stats == 3) {
  298. // column headings
  299. $ch[1] = "Driver";
  300. $ch[2] = "Race Wins";
  301. $ch[3] = "Lowest Qualification to Win";
  302. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  303. $textwidth = abs( $titleBox[2] );
  304. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
  305. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  306. $textwidth = abs( $titleBox[2] );
  307. imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
  308. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  309. $textwidth = abs( $titleBox[2] );
  310. imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
  311. // get race wins for top 10
  312. $tablename = $wpdb->prefix . "fusion_f1_results";
  313. $races = $wpdb->get_results( $wpdb->prepare(
  314. "
  315. SELECT playerID, COUNT(playerID) as races
  316. FROM $tablename
  317. WHERE raceID > %d AND resultPosition = %d AND divID = 1
  318. GROUP BY playerID
  319. ORDER BY races DESC LIMIT %d
  320. ",
  321. 0,
  322. 1,
  323. $rows
  324. ) );
  325. // show top 10 race wins
  326. $i = 1;
  327. foreach ( $races as $val ) {
  328. $tablename = $wpdb->prefix . "fusion_f1_players";
  329. $player = $wpdb->get_var( $wpdb->prepare(
  330. "
  331. SELECT playerName
  332. FROM $tablename
  333. WHERE playerID = %d
  334. ",
  335. $val->playerID
  336. ) );
  337. // get lowest quali to win
  338. $tablename = $wpdb->prefix . "fusion_f1_results";
  339. $lowestqtowin = $wpdb->get_var( $wpdb->prepare(
  340. "
  341. SELECT MAX(resultGrid)
  342. FROM $tablename
  343. WHERE playerID = %d AND raceID > %d AND resultPosition = %d AND resultGrid > %d AND divID = 1
  344. ",
  345. $val->playerID,
  346. 0,
  347. 1,
  348. 0
  349. ) );
  350. $pich = $lineh;
  351. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
  352. imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
  353. imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
  354. $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
  355. $txtwidth = abs( $box[2] );
  356. imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
  357. $box = imageTTFbbox( $fsize, 0, $font2, $lowestqtowin );
  358. $txtwidth = abs( $box[2] );
  359. imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $lowestqtowin );
  360. $lines++;
  361. $i++;
  362. }
  363. }
  364. // ********************* Podiums *********************
  365. if ($stats == 4) {
  366. // column headings
  367. $ch[1] = "Driver";
  368. $ch[2] = "Podiums";
  369. $ch[3] = "Podium/Race Average";
  370. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  371. $textwidth = abs( $titleBox[2] );
  372. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
  373. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  374. $textwidth = abs( $titleBox[2] );
  375. imageTTFtext( $image, $fsize, 0, intval(292 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
  376. $cupPic = "images/cup1.png";
  377. $cupP = imagecreatefrompng($cupPic);
  378. imagesavealpha($cupP, true);
  379. imagecopy($image, $cupP, 359, $lineh+($lineh/2)-2, 0, 0, 18, 21);
  380. $cupPic = "images/cup2.png";
  381. $cupP = imagecreatefrompng($cupPic);
  382. imagesavealpha($cupP, true);
  383. imagecopy($image, $cupP, 397, $lineh+($lineh/2)-2, 0, 0, 18, 21);
  384. $cupPic = "images/cup3.png";
  385. $cupP = imagecreatefrompng($cupPic);
  386. imagesavealpha($cupP, true);
  387. imagecopy($image, $cupP, 435, $lineh+($lineh/2)-2, 0, 0, 18, 21);
  388. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  389. $textwidth = abs( $titleBox[2] );
  390. imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
  391. // get podiums for top 10
  392. $tablename = $wpdb->prefix . "fusion_f1_results";
  393. $races = $wpdb->get_results( $wpdb->prepare(
  394. "
  395. SELECT playerID, COUNT(playerID) as races, SUM(podium1) as gold, SUM(podium2) as silver, SUM(podium3) as bronze
  396. FROM $tablename
  397. WHERE raceID > %d AND resultPosition <= %d AND divID = 1
  398. GROUP BY playerID
  399. ORDER BY races DESC LIMIT %d
  400. ",
  401. 0,
  402. 3,
  403. $rows
  404. ) );
  405. // show top 10 podiums
  406. $i = 1;
  407. foreach ( $races as $val ) {
  408. $tablename = $wpdb->prefix . "fusion_f1_players";
  409. $player = $wpdb->get_var( $wpdb->prepare(
  410. "
  411. SELECT playerName
  412. FROM $tablename
  413. WHERE playerID = %d
  414. ",
  415. $val->playerID
  416. ) );
  417. // get podiums / race average
  418. $tablename = $wpdb->prefix . "fusion_f1_results";
  419. $races = $wpdb->get_var( $wpdb->prepare(
  420. "
  421. SELECT COUNT(resultID)
  422. FROM $tablename
  423. WHERE playerID = %d AND raceID > %d AND divID = 1
  424. ",
  425. $val->playerID,
  426. 0
  427. ) );
  428. $podiums = $val->races;
  429. $podraceaverage = ROUND(($val->races / $races) * 100)."%";
  430. $pich = $lineh;
  431. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
  432. imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
  433. imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
  434. $box = imageTTFbbox( $fsize, 0, $font2, $podiums );
  435. $txtwidth = abs( $box[2] );
  436. imageTTFtext( $image, $fsize , 0, intval(292 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $podiums );
  437. $box = imageTTFbbox( $fsize, 0, $font2, $val->gold );
  438. $txtwidth = abs( $box[2] );
  439. imageTTFtext( $image, $fsize , 0, intval(368 - ($txtwidth/2)), $txth + 5, $txgold, $font2, $val->gold );
  440. $box = imageTTFbbox( $fsize, 0, $font2, $val->silver );
  441. $txtwidth = abs( $box[2] );
  442. imageTTFtext( $image, $fsize , 0, intval(406 - ($txtwidth/2)), $txth + 5, $txsilver, $font2, $val->silver );
  443. $box = imageTTFbbox( $fsize, 0, $font2, $val->bronze );
  444. $txtwidth = abs( $box[2] );
  445. imageTTFtext( $image, $fsize , 0, intval(444 - ($txtwidth/2)), $txth + 5, $txbronze, $font2, $val->bronze );
  446. $box = imageTTFbbox( $fsize, 0, $font2, $podraceaverage );
  447. $txtwidth = abs( $box[2] );
  448. imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $podraceaverage );
  449. $lines++;
  450. $i++;
  451. }
  452. }
  453.  
  454. // ********************* Hall of Fame *********************
  455. // Awards
  456. if ($stats == 5) {
  457. $subtitleString = "Awards";
  458. $fsize = 11;
  459. $pich = $lineh +6;
  460. imagefilledrectangle ($image, 2, $pich+3, 697, $pich + $lineh, $stcol);
  461. $subtitleBox = imageTTFbbox( $fsize, 0, $font2, $subtitleString );
  462. $textwidth = abs( $subtitleBox[2] );
  463. imageTTFtext( $image, $fsize, 0, intval(348 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich, $txcol, $font2, $subtitleString );
  464. imagefilledrectangle ($image, 2, $pich+$lineh, 697, $pich + ($lineh*2), $bgcol);
  465. // column headings
  466. $fsize = 12;
  467. $ch[1] = "";
  468. $ch[2] = "Rookie of the Season";
  469. $ch[3] = "Driver of the Season";
  470. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  471. $textwidth = abs( $titleBox[2] );
  472. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[1] );
  473. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  474. $textwidth = abs( $titleBox[2] );
  475. imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[2] );
  476. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  477. $textwidth = abs( $titleBox[2] );
  478. imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[3] );
  479. // get rookies/drivers of the years
  480. $tablename = $wpdb->prefix . "fusion_f1_awards";
  481. $award = $wpdb->get_results(
  482. "
  483. SELECT *
  484. FROM $tablename
  485. ORDER BY seasonID DESC
  486. "
  487. ) ;
  488. foreach ($award as $val) {
  489. $tablename = $wpdb->prefix . "fusion_f1_races";
  490. $game = $wpdb->get_var( $wpdb->prepare(
  491. "
  492. SELECT raceGame
  493. FROM $tablename
  494. WHERE raceOrder = %d AND raceSeason = %d
  495. ",
  496. 1,
  497. $val->seasonID
  498. ) );
  499. $tablename = $wpdb->prefix . "fusion_f1_players";
  500. $rookie = $wpdb->get_var( $wpdb->prepare(
  501. "
  502. SELECT playerName
  503. FROM $tablename
  504. WHERE playerID = %d
  505. ",
  506. $val->rookieID
  507. ) );
  508. $driver = $wpdb->get_var( $wpdb->prepare(
  509. "
  510. SELECT playerName
  511. FROM $tablename
  512. WHERE playerID = %d
  513. ",
  514. $val->driverID
  515. ) );
  516.  
  517. $pich = $lineh*2;
  518. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
  519. $gamePic = "images/".$game."/s_logo.png";
  520. $gameP = imagecreatefrompng($gamePic);
  521. imagesavealpha($gameP, true);
  522. imagecopy($image, $gameP, 3, $txth-($lineh/2), 0, 0, 70, 22);
  523. $sgame = "Season ".$val->seasonID;
  524. $box = imageTTFbbox( $fsize, 0, $font2, $sgame );
  525. $txtwidth = abs( $box[2] );
  526. imageTTFtext( $image, $fsize , 0, intval(153 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $sgame );
  527. $box = imageTTFbbox( $fsize, 0, $font2, $rookie );
  528. $txtwidth = abs( $box[2] );
  529. imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $rookie );
  530. $box = imageTTFbbox( $fsize, 0, $font2, $driver );
  531. $txtwidth = abs( $box[2] );
  532. imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $driver );
  533. $lines++;
  534. $i++;
  535. }
  536. // get champions
  537. $lines=1;
  538. $subtitleString = "Champions";
  539. $fsize = 12;
  540. $pich = ($lineh * $awardrows) + ($lineh*3) + 6;
  541. imagefilledrectangle ($image, 2, $pich+3, 697, $pich + $lineh, $stcol);
  542. $subtitleBox = imageTTFbbox( $fsize, 0, $font2, $subtitleString );
  543. $textwidth = abs( $subtitleBox[2] );
  544. imageTTFtext( $image, $fsize, 0, intval(348 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich, $txcol, $font2, $subtitleString );
  545. imagefilledrectangle ($image, 2, $pich+$lineh+3, 697, $pich + ($lineh*2), $bgcol);
  546. // column headings
  547. $ch[1] = "";
  548. $ch[2] = "Driver";
  549. $ch[3] = "Podiums";
  550. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  551. $textwidth = abs( $titleBox[2] );
  552. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[1] );
  553. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  554. $textwidth = abs( $titleBox[2] );
  555. imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[2] );
  556.  
  557. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  558. $textwidth = abs( $titleBox[2] );
  559. imageTTFtext( $image, $fsize, 0, intval(525 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[3] );
  560. $cupPic = "images/cup1.png";
  561. $cupP = imagecreatefrompng($cupPic);
  562. imagesavealpha($cupP, true);
  563. imagecopy($image, $cupP, 592, $pich+$lineh+3, 0, 0, 18, 21);
  564. $cupPic = "images/cup2.png";
  565. $cupP = imagecreatefrompng($cupPic);
  566. imagesavealpha($cupP, true);
  567. imagecopy($image, $cupP, 630, $pich+$lineh+3, 0, 0, 18, 21);
  568. $cupPic = "images/cup3.png";
  569. $cupP = imagecreatefrompng($cupPic);
  570. imagesavealpha($cupP, true);
  571. imagecopy($image, $cupP, 668,$pich+$lineh+3, 0, 0, 18, 21);
  572. // get current season
  573. $tablename = $wpdb->prefix . "fusion_f1_results";
  574. $currseason = $wpdb->get_var( $wpdb->prepare(
  575. "
  576. SELECT MAX(seasonID) as currseason
  577. FROM $tablename
  578. WHERE raceID > %d
  579. ",
  580. 0
  581. ) );
  582. // get list of seasons
  583. $tablename = $wpdb->prefix . "fusion_f1_seasonparams";
  584. $seasons = $wpdb->get_results(
  585. "
  586. SELECT seasonID, game, divs
  587. FROM $tablename
  588. ORDER BY seasonID DESC
  589. "
  590. );
  591. foreach ($seasons as $val) {
  592. for ($ii=1; $ii<=$val->divs; $ii++) {
  593. $tablename = $wpdb->prefix . "fusion_f1_results";
  594. $champ = $wpdb->get_var( $wpdb->prepare(
  595. "
  596. SELECT playerID, SUM(resultPoints) as points
  597. FROM $tablename
  598. WHERE raceID > %d AND seasonID = %d AND divID = %d
  599. GROUP BY playerID
  600. ORDER BY points DESC
  601. ",
  602. 0,
  603. $val->seasonID,
  604. $ii
  605. ) );
  606. $tablename = $wpdb->prefix . "fusion_f1_players";
  607. $player = $wpdb->get_var( $wpdb->prepare(
  608. "
  609. SELECT playerName
  610. FROM $tablename
  611. WHERE playerID = %d
  612. ",
  613. $champ
  614. ) );
  615. // check to see if mid season
  616. $tablename = $wpdb->prefix . "fusion_f1_races";
  617. $races = $wpdb->get_var( $wpdb->prepare(
  618. "
  619. SELECT COUNT(raceID) as races
  620. FROM $tablename
  621. WHERE raceSeason = %d AND divID = %d
  622. ",
  623. $val->seasonID,
  624. $ii
  625. ) );
  626. $tablename = $wpdb->prefix . "fusion_f1_results";
  627. $racesraced = $wpdb->get_results( $wpdb->prepare(
  628. "
  629. SELECT COUNT(raceID) as raced
  630. FROM $tablename
  631. WHERE raceID > %d and seasonID = %d AND divID = %d
  632. GROUP BY raceID
  633. ",
  634. 0,
  635. $val->seasonID,
  636. $ii
  637. ) );
  638. $raced = $wpdb->num_rows;
  639. // if mid-season current champion, add 'leading' to string
  640. if (($currseason == $val->seasonID) && ($raced < $races)) $player .=" (leading)";
  641. // get podiums for player/season
  642. $tablename = $wpdb->prefix . "fusion_f1_results";
  643. $cups = $wpdb->get_row( $wpdb->prepare(
  644. "
  645. SELECT playerID, COUNT(playerID) as podiums, SUM(podium1) as gold, SUM(podium2) as silver, SUM(podium3) as bronze
  646. FROM $tablename
  647. WHERE raceID > %d AND resultPosition <= %d AND seasonID = %d AND playerID = %d
  648. ",
  649. 0,
  650. 3,
  651. $val->seasonID,
  652. $champ
  653. ) );
  654. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * ($lineh) + $lineh);
  655. $gamePic = "images/".$val->game."/s_logo.png";
  656. $gameP = imagecreatefrompng($gamePic);
  657. imagesavealpha($gameP, true);
  658. imagecopy($image, $gameP, 3, $txth-($lineh/2)-5, 0, 0, 70, 22);
  659. $sgame = "Season ".$val->seasonID;
  660. if ($val->divs > 1) {
  661. $sgame .= " Div ".$ii;
  662. }
  663. $box = imageTTFbbox( $fsize, 0, $font2, $sgame );
  664. $txtwidth = abs( $box[2] );
  665. imageTTFtext( $image, $fsize , 0, intval(153 - ($txtwidth/2)), $txth, $txcol, $font2, $sgame );
  666. $box = imageTTFbbox( $fsize, 0, $font2, $player );
  667. $txtwidth = abs( $box[2] );
  668. imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth, $txcol, $font2, $player );
  669. $box = imageTTFbbox( $fsize, 0, $font2, $cups->podiums );
  670. $txtwidth = abs( $box[2] );
  671. imageTTFtext( $image, $fsize , 0, intval(525 - ($txtwidth/2)), $txth, $txcol, $font2, $cups->podiums );
  672. $box = imageTTFbbox( $fsize, 0, $font2, $cups->gold );
  673. $txtwidth = abs( $box[2] );
  674. imageTTFtext( $image, $fsize , 0, intval(601 - ($txtwidth/2)), $txth, $txgold, $font2, $cups->gold );
  675. $box = imageTTFbbox( $fsize, 0, $font2, $cups->silver );
  676. $txtwidth = abs( $box[2] );
  677. imageTTFtext( $image, $fsize , 0, intval(639 - ($txtwidth/2)), $txth, $txsilver, $font2, $cups->silver );
  678. $box = imageTTFbbox( $fsize, 0, $font2, $cups->bronze );
  679. $txtwidth = abs( $box[2] );
  680. imageTTFtext( $image, $fsize , 0, intval(677- ($txtwidth/2)), $txth, $txbronze, $font2, $cups->bronze );
  681. $lines++;
  682. $i++;
  683. }
  684. }
  685. }
  686. // ********************* Race Attendance Div 2*********************
  687. if ($stats == 6) {
  688. // column headings
  689. $ch[1] = "Driver";
  690. $ch[2] = "Races Attended";
  691. $ch[3] = "Races Finished (%)";
  692. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  693. $textwidth = abs( $titleBox[2] );
  694. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
  695. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  696. $textwidth = abs( $titleBox[2] );
  697. imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
  698. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  699. $textwidth = abs( $titleBox[2] );
  700. imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
  701.  
  702. // get attendance records for top 10
  703. $tablename = $wpdb->prefix . "fusion_f1_results";
  704. $races = $wpdb->get_results( $wpdb->prepare(
  705. "
  706. SELECT playerID, COUNT(playerID) as races
  707. FROM $tablename
  708. WHERE raceID > %d AND divID = 2
  709. GROUP BY playerID
  710. ORDER BY races DESC
  711. LIMIT %d
  712. ",
  713. 0,
  714. $rows ) );
  715. foreach ( $races as $val ) {
  716. // get player names
  717. $tablename = $wpdb->prefix . "fusion_f1_players";
  718. $player = $wpdb->get_var( $wpdb->prepare(
  719. "
  720. SELECT playerName
  721. FROM $tablename
  722. WHERE playerID = %s
  723. ",
  724. $val->playerID
  725. ) );
  726. // get races not finished
  727. $dnfdsq = "%D%";
  728. $tablename = $wpdb->prefix . "fusion_f1_results";
  729. $nonfinishes = $wpdb->get_var( $wpdb->prepare(
  730. "
  731. SELECT COUNT(resultID)
  732. FROM $tablename
  733. WHERE playerID = %d AND raceID > %d AND resultTime LIKE %s AND divID = 2
  734.  
  735. ",
  736. $val->playerID,
  737. 0,
  738. $dnfdsq
  739. ) );
  740. $finishes = $val->races-$nonfinishes;
  741. $percentfinishes = ($finishes/$val->races)*100;
  742. $finishes .= " (".round($percentfinishes)."%)";
  743. $pich = $lineh;
  744. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
  745. imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
  746. imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
  747. $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
  748. $txtwidth = abs( $box[2] );
  749. imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
  750. $box = imageTTFbbox( $fsize, 0, $font2, $finishes );
  751. $txtwidth = abs( $box[2] );
  752. imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $finishes );
  753. $lines++;
  754. }
  755. }
  756. // ********************* Pole Positions Div 2*********************
  757. if ($stats == 7) {
  758. // column headings
  759. $ch[1] = "Driver";
  760. $ch[2] = "Pole Positions";
  761. $ch[3] = "Poles Converted to Wins (%)";
  762. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  763. $textwidth = abs( $titleBox[2] );
  764. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
  765. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  766. $textwidth = abs( $titleBox[2] );
  767. imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
  768. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  769. $textwidth = abs( $titleBox[2] );
  770. imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
  771. // get pole positions for top 10
  772. $tablename = $wpdb->prefix . "fusion_f1_results";
  773. $races = $wpdb->get_results( $wpdb->prepare(
  774. "
  775. SELECT playerID, COUNT(playerID) as races
  776. FROM $tablename
  777. WHERE raceID > %d AND resultGrid = %d AND divID = 2
  778. GROUP BY playerID
  779. ORDER BY races DESC LIMIT %d
  780. ",
  781. 0,
  782. 1,
  783. $rows
  784. ) );
  785. // show top 10 pole positions
  786. $i = 1;
  787. foreach ( $races as $val ) {
  788. $tablename = $wpdb->prefix . "fusion_f1_players";
  789. $player = $wpdb->get_var( $wpdb->prepare(
  790. "
  791. SELECT playerName
  792. FROM $tablename
  793. WHERE playerID = %s
  794. ",
  795. $val->playerID
  796. ) );
  797. // get pole converted
  798. $tablename = $wpdb->prefix . "fusion_f1_results";
  799. $conversions = $wpdb->get_var( $wpdb->prepare(
  800. "
  801. SELECT COUNT(resultID)
  802. FROM $tablename
  803. WHERE playerID = %d AND raceID > %d AND resultGrid = %d AND resultPosition = %d AND divID = 2
  804. ",
  805. $val->playerID,
  806. 0,
  807. 1,
  808. 1
  809. ) );
  810. $percentconversions = ($conversions/$val->races)*100;
  811. $conversions .= " (".round($percentconversions)."%)";
  812. $pich = $lineh;
  813. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
  814. imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
  815. imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
  816. $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
  817. $txtwidth = abs( $box[2] );
  818. imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
  819. $box = imageTTFbbox( $fsize, 0, $font2, $conversions );
  820. $txtwidth = abs( $box[2] );
  821. imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $conversions );
  822. $lines++;
  823. $i++;
  824. }
  825. }
  826. // ********************* Race Wins Div 2*********************
  827. if ($stats == 8) {
  828. // column headings
  829. $ch[1] = "Driver";
  830. $ch[2] = "Race Wins";
  831. $ch[3] = "Lowest Qualification to Win";
  832. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  833. $textwidth = abs( $titleBox[2] );
  834. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
  835. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  836. $textwidth = abs( $titleBox[2] );
  837. imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
  838. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  839. $textwidth = abs( $titleBox[2] );
  840. imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
  841. // get race wins for top 10
  842. $tablename = $wpdb->prefix . "fusion_f1_results";
  843. $races = $wpdb->get_results( $wpdb->prepare(
  844. "
  845. SELECT playerID, COUNT(playerID) as races
  846. FROM $tablename
  847. WHERE raceID > %d AND resultPosition = %d AND divID = 2
  848. GROUP BY playerID
  849. ORDER BY races DESC LIMIT %d
  850. ",
  851. 0,
  852. 1,
  853. $rows
  854. ) );
  855. // show top 10 race wins
  856. $i = 1;
  857. foreach ( $races as $val ) {
  858. $tablename = $wpdb->prefix . "fusion_f1_players";
  859. $player = $wpdb->get_var( $wpdb->prepare(
  860. "
  861. SELECT playerName
  862. FROM $tablename
  863. WHERE playerID = %d
  864. ",
  865. $val->playerID
  866. ) );
  867. // get lowest quali to win
  868. $tablename = $wpdb->prefix . "fusion_f1_results";
  869. $lowestqtowin = $wpdb->get_var( $wpdb->prepare(
  870. "
  871. SELECT MAX(resultGrid)
  872. FROM $tablename
  873. WHERE playerID = %d AND raceID > %d AND resultPosition = %d AND resultGrid > %d AND divID = 2
  874. ",
  875. $val->playerID,
  876. 0,
  877. 1,
  878. 0
  879. ) );
  880. $pich = $lineh;
  881. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
  882. imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
  883. imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
  884. $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
  885. $txtwidth = abs( $box[2] );
  886. imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
  887. $box = imageTTFbbox( $fsize, 0, $font2, $lowestqtowin );
  888. $txtwidth = abs( $box[2] );
  889. imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $lowestqtowin );
  890. $lines++;
  891. $i++;
  892. }
  893. }
  894. // ********************* Podiums Div 2*********************
  895. if ($stats == 9) {
  896. // column headings
  897. $ch[1] = "Driver";
  898. $ch[2] = "Podiums";
  899. $ch[3] = "Podium/Race Average";
  900. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  901. $textwidth = abs( $titleBox[2] );
  902. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
  903. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  904. $textwidth = abs( $titleBox[2] );
  905. imageTTFtext( $image, $fsize, 0, intval(292 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
  906. $cupPic = "images/cup1.png";
  907. $cupP = imagecreatefrompng($cupPic);
  908. imagesavealpha($cupP, true);
  909. imagecopy($image, $cupP, 359, $lineh+($lineh/2)-2, 0, 0, 18, 21);
  910. $cupPic = "images/cup2.png";
  911. $cupP = imagecreatefrompng($cupPic);
  912. imagesavealpha($cupP, true);
  913. imagecopy($image, $cupP, 397, $lineh+($lineh/2)-2, 0, 0, 18, 21);
  914. $cupPic = "images/cup3.png";
  915. $cupP = imagecreatefrompng($cupPic);
  916. imagesavealpha($cupP, true);
  917. imagecopy($image, $cupP, 435, $lineh+($lineh/2)-2, 0, 0, 18, 21);
  918. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  919. $textwidth = abs( $titleBox[2] );
  920. imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
  921. // get podiums for top 10
  922. $tablename = $wpdb->prefix . "fusion_f1_results";
  923. $races = $wpdb->get_results( $wpdb->prepare(
  924. "
  925. SELECT playerID, COUNT(playerID) as races, SUM(podium1) as gold, SUM(podium2) as silver, SUM(podium3) as bronze
  926. FROM $tablename
  927. WHERE raceID > %d AND resultPosition <= %d AND divID = 2
  928. GROUP BY playerID
  929. ORDER BY races DESC LIMIT %d
  930. ",
  931. 0,
  932. 3,
  933. $rows
  934. ) );
  935. // show top 10 podiums
  936. $i = 1;
  937. foreach ( $races as $val ) {
  938. $tablename = $wpdb->prefix . "fusion_f1_players";
  939. $player = $wpdb->get_var( $wpdb->prepare(
  940. "
  941. SELECT playerName
  942. FROM $tablename
  943. WHERE playerID = %d
  944. ",
  945. $val->playerID
  946. ) );
  947. // get podiums / race average
  948. $tablename = $wpdb->prefix . "fusion_f1_results";
  949. $races = $wpdb->get_var( $wpdb->prepare(
  950. "
  951. SELECT COUNT(resultID)
  952. FROM $tablename
  953. WHERE playerID = %d AND raceID > %d AND divID = 2
  954. ",
  955. $val->playerID,
  956. 0
  957. ) );
  958. $podiums = $val->races;
  959. $podraceaverage = ROUND(($val->races / $races) * 100)."%";
  960. $pich = $lineh;
  961. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
  962. imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
  963. imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
  964. $box = imageTTFbbox( $fsize, 0, $font2, $podiums );
  965. $txtwidth = abs( $box[2] );
  966. imageTTFtext( $image, $fsize , 0, intval(292 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $podiums );
  967. $box = imageTTFbbox( $fsize, 0, $font2, $val->gold );
  968. $txtwidth = abs( $box[2] );
  969. imageTTFtext( $image, $fsize , 0, intval(368 - ($txtwidth/2)), $txth + 5, $txgold, $font2, $val->gold );
  970. $box = imageTTFbbox( $fsize, 0, $font2, $val->silver );
  971. $txtwidth = abs( $box[2] );
  972. imageTTFtext( $image, $fsize , 0, intval(406 - ($txtwidth/2)), $txth + 5, $txsilver, $font2, $val->silver );
  973. $box = imageTTFbbox( $fsize, 0, $font2, $val->bronze );
  974. $txtwidth = abs( $box[2] );
  975. imageTTFtext( $image, $fsize , 0, intval(444 - ($txtwidth/2)), $txth + 5, $txbronze, $font2, $val->bronze );
  976. $box = imageTTFbbox( $fsize, 0, $font2, $podraceaverage );
  977. $txtwidth = abs( $box[2] );
  978. imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $podraceaverage );
  979. $lines++;
  980. $i++;
  981. }
  982. }
  983. // ********************* Hall of Fame *********************
  984. // Awards
  985. if ($stats == 10) {
  986. $subtitleString = "Awards";
  987. $fsize = 11;
  988. $pich = $lineh +6;
  989. imagefilledrectangle ($image, 2, $pich+3, 697, $pich + $lineh, $stcol);
  990. $subtitleBox = imageTTFbbox( $fsize, 0, $font2, $subtitleString );
  991. $textwidth = abs( $subtitleBox[2] );
  992. imageTTFtext( $image, $fsize, 0, intval(348 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich, $txcol, $font2, $subtitleString );
  993. imagefilledrectangle ($image, 2, $pich+$lineh, 697, $pich + ($lineh*2), $bgcol);
  994. // column headings
  995. $fsize = 12;
  996. $ch[1] = "";
  997. $ch[2] = "Rookie of the Season";
  998. $ch[3] = "Driver of the Season";
  999. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  1000. $textwidth = abs( $titleBox[2] );
  1001. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[1] );
  1002. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  1003. $textwidth = abs( $titleBox[2] );
  1004. imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[2] );
  1005. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  1006. $textwidth = abs( $titleBox[2] );
  1007. imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[3] );
  1008. // get rookies/drivers of the years
  1009. $tablename = $wpdb->prefix . "fusion_f1_awards";
  1010. $award = $wpdb->get_results(
  1011. "
  1012. SELECT *
  1013. FROM $tablename
  1014. ORDER BY seasonID DESC
  1015. "
  1016. ) ;
  1017. foreach ($award as $val) {
  1018. $tablename = $wpdb->prefix . "fusion_f1_races";
  1019. $game = $wpdb->get_var( $wpdb->prepare(
  1020. "
  1021. SELECT raceGame
  1022. FROM $tablename
  1023. WHERE raceOrder = %d AND raceSeason = %d
  1024. ",
  1025. 1,
  1026. $val->seasonID
  1027. ) );
  1028. $tablename = $wpdb->prefix . "fusion_f1_players";
  1029. $rookie = $wpdb->get_var( $wpdb->prepare(
  1030. "
  1031. SELECT playerName
  1032. FROM $tablename
  1033. WHERE playerID = %d
  1034. ",
  1035. $val->rookieID
  1036. ) );
  1037. $driver = $wpdb->get_var( $wpdb->prepare(
  1038. "
  1039. SELECT playerName
  1040. FROM $tablename
  1041. WHERE playerID = %d
  1042. ",
  1043. $val->driverID
  1044. ) );
  1045.  
  1046. $pich = $lineh*2;
  1047. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
  1048. $gamePic = "images/".$game."/s_logo.png";
  1049. $gameP = imagecreatefrompng($gamePic);
  1050. imagesavealpha($gameP, true);
  1051. imagecopy($image, $gameP, 3, $txth-($lineh/2), 0, 0, 70, 22);
  1052. $sgame = "Season ".$val->seasonID;
  1053. $box = imageTTFbbox( $fsize, 0, $font2, $sgame );
  1054. $txtwidth = abs( $box[2] );
  1055. imageTTFtext( $image, $fsize , 0, intval(153 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $sgame );
  1056. $box = imageTTFbbox( $fsize, 0, $font2, $rookie );
  1057. $txtwidth = abs( $box[2] );
  1058. imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $rookie );
  1059. $box = imageTTFbbox( $fsize, 0, $font2, $driver );
  1060. $txtwidth = abs( $box[2] );
  1061. imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $driver );
  1062. $lines++;
  1063. $i++;
  1064. }
  1065. // get champions
  1066. $lines= 20;
  1067. $subtitleString = "Champions";
  1068. $fsize = 12;
  1069. $pich = ($lineh * $awardrows) + ($lineh*3) + 6;
  1070. imagefilledrectangle ($image, 2, $pich+3, 697, $pich + $lineh, $stcol);
  1071. $subtitleBox = imageTTFbbox( $fsize, 0, $font2, $subtitleString );
  1072. $textwidth = abs( $subtitleBox[2] );
  1073. imageTTFtext( $image, $fsize, 0, intval(348 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich, $txcol, $font2, $subtitleString );
  1074. imagefilledrectangle ($image, 2, $pich+$lineh+3, 697, $pich + ($lineh*2), $bgcol);
  1075. // column headings
  1076. $ch[1] = "";
  1077. $ch[2] = "Driver";
  1078. $ch[3] = "Podiums";
  1079. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
  1080. $textwidth = abs( $titleBox[2] );
  1081. imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[1] );
  1082. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
  1083. $textwidth = abs( $titleBox[2] );
  1084. imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[2] );
  1085.  
  1086. $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
  1087. $textwidth = abs( $titleBox[2] );
  1088. imageTTFtext( $image, $fsize, 0, intval(525 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[3] );
  1089. $cupPic = "images/cup1.png";
  1090. $cupP = imagecreatefrompng($cupPic);
  1091. imagesavealpha($cupP, true);
  1092. imagecopy($image, $cupP, 592, $pich+$lineh+3, 0, 0, 18, 21);
  1093. $cupPic = "images/cup2.png";
  1094. $cupP = imagecreatefrompng($cupPic);
  1095. imagesavealpha($cupP, true);
  1096. imagecopy($image, $cupP, 630, $pich+$lineh+3, 0, 0, 18, 21);
  1097. $cupPic = "images/cup3.png";
  1098. $cupP = imagecreatefrompng($cupPic);
  1099. imagesavealpha($cupP, true);
  1100. imagecopy($image, $cupP, 668,$pich+$lineh+3, 0, 0, 18, 21);
  1101. // get current season
  1102. $tablename = $wpdb->prefix . "fusion_f1_results";
  1103. $currseason = $wpdb->get_var( $wpdb->prepare(
  1104. "
  1105. SELECT MAX(seasonID) as currseason
  1106. FROM $tablename
  1107. WHERE raceID > %d
  1108. ",
  1109. 0
  1110. ) );
  1111. // get list of seasons
  1112. $tablename = $wpdb->prefix . "fusion_f1_seasonparams";
  1113. $seasons = $wpdb->get_results(
  1114. "
  1115. SELECT seasonID, game, divs
  1116. FROM $tablename
  1117. ORDER BY seasonID DESC
  1118. "
  1119. );
  1120. foreach ($seasons as $val) {
  1121. for ($ii=1; $ii<=$val->divs; $ii++) {
  1122. $tablename = $wpdb->prefix . "fusion_f1_results";
  1123. $champ = $wpdb->get_var( $wpdb->prepare(
  1124. "
  1125. SELECT playerID, SUM(resultPoints) as points
  1126. FROM $tablename
  1127. WHERE raceID > %d AND seasonID = %d AND divID = %d
  1128. GROUP BY playerID
  1129. ORDER BY points DESC
  1130. ",
  1131. 0,
  1132. $val->seasonID,
  1133. $ii
  1134. ) );
  1135. $tablename = $wpdb->prefix . "fusion_f1_players";
  1136. $player = $wpdb->get_var( $wpdb->prepare(
  1137. "
  1138. SELECT playerName
  1139. FROM $tablename
  1140. WHERE playerID = %d
  1141. ",
  1142. $champ
  1143. ) );
  1144. // check to see if mid season
  1145. $tablename = $wpdb->prefix . "fusion_f1_races";
  1146. $races = $wpdb->get_var( $wpdb->prepare(
  1147. "
  1148. SELECT COUNT(raceID) as races
  1149. FROM $tablename
  1150. WHERE raceSeason = %d AND divID = %d
  1151. ",
  1152. $val->seasonID,
  1153. $ii
  1154. ) );
  1155. $tablename = $wpdb->prefix . "fusion_f1_results";
  1156. $racesraced = $wpdb->get_results( $wpdb->prepare(
  1157. "
  1158. SELECT COUNT(raceID) as raced
  1159. FROM $tablename
  1160. WHERE raceID > %d and seasonID = %d AND divID = %d
  1161. GROUP BY raceID
  1162. ",
  1163. 0,
  1164. $val->seasonID,
  1165. $ii
  1166. ) );
  1167. $raced = $wpdb->num_rows;
  1168. // if mid-season current champion, add 'leading' to string
  1169. if (($currseason == $val->seasonID) && ($raced < $races)) $player .=" (leading)";
  1170. // get podiums for player/season
  1171. $tablename = $wpdb->prefix . "fusion_f1_results";
  1172. $cups = $wpdb->get_row( $wpdb->prepare(
  1173. "
  1174. SELECT playerID, COUNT(playerID) as podiums, SUM(podium1) as gold, SUM(podium2) as silver, SUM(podium3) as bronze
  1175. FROM $tablename
  1176. WHERE raceID > %d AND resultPosition <= %d AND seasonID = %d AND playerID = %d
  1177. ",
  1178. 0,
  1179. 3,
  1180. $val->seasonID,
  1181. $champ
  1182. ) );
  1183. $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * ($lineh) + $lineh);
  1184. $gamePic = "images/".$val->game."/s_logo.png";
  1185. $gameP = imagecreatefrompng($gamePic);
  1186. imagesavealpha($gameP, true);
  1187. imagecopy($image, $gameP, 3, $txth-($lineh/2)-5, 0, 0, 70, 22);
  1188. $sgame = "Season ".$val->seasonID;
  1189. if ($val->divs > 1) {
  1190. $sgame .= " Div ".$ii;
  1191. }
  1192. $box = imageTTFbbox( $fsize, 0, $font2, $sgame );
  1193. $txtwidth = abs( $box[2] );
  1194. imageTTFtext( $image, $fsize , 0, intval(153 - ($txtwidth/2)), $txth, $txcol, $font2, $sgame );
  1195. $box = imageTTFbbox( $fsize, 0, $font2, $player );
  1196. $txtwidth = abs( $box[2] );
  1197. imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth, $txcol, $font2, $player );
  1198. $box = imageTTFbbox( $fsize, 0, $font2, $cups->podiums );
  1199. $txtwidth = abs( $box[2] );
  1200. imageTTFtext( $image, $fsize , 0, intval(525 - ($txtwidth/2)), $txth, $txcol, $font2, $cups->podiums );
  1201. $box = imageTTFbbox( $fsize, 0, $font2, $cups->gold );
  1202. $txtwidth = abs( $box[2] );
  1203. imageTTFtext( $image, $fsize , 0, intval(601 - ($txtwidth/2)), $txth, $txgold, $font2, $cups->gold );
  1204. $box = imageTTFbbox( $fsize, 0, $font2, $cups->silver );
  1205. $txtwidth = abs( $box[2] );
  1206. imageTTFtext( $image, $fsize , 0, intval(639 - ($txtwidth/2)), $txth, $txsilver, $font2, $cups->silver );
  1207. $box = imageTTFbbox( $fsize, 0, $font2, $cups->bronze );
  1208. $txtwidth = abs( $box[2] );
  1209. imageTTFtext( $image, $fsize , 0, intval(677- ($txtwidth/2)), $txth, $txbronze, $font2, $cups->bronze );
  1210. $lines++;
  1211. $i++;
  1212. }
  1213. }
  1214. }
  1215. // output image
  1216. imagepng($image);
  1217. imagedestroy($image);
  1218. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement