Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php header("Content-type: image/png");
- // get install path of wordpress
- function find_wp_path() {
- $dir = dirname(__FILE__);
- do {
- if( file_exists($dir."/wp-load.php") ) {
- return $dir;
- }
- } while( $dir = realpath("$dir/..") );
- return null;
- }
- include_once( find_wp_path() . '/wp-load.php' );
- /************** Declare variables ****************/
- // get which stat to be displayed from uri
- $stats = $_GET['s'];
- // define defaults if no stats given
- if ( empty ( $_GET['s'] ) ) {
- $stats = 1;
- }
- $font1 = dirname( __FILE__ ).'/tahoma.ttf';
- $font2 = dirname( __FILE__ ).'/tahomabd.ttf';
- $lines = 1;
- $lineh = 24;
- // function to output alternating row colours
- function rows($rows) {
- global $lineh, $image;
- for ($i = 1; $i <= $rows; $i++) {
- $pich = $lineh + ($i * $lineh) + 8;
- if ($i % 2 != 0) {
- $rowcol = imagecolorallocate($image, 51, 51, 51);
- } else {
- $rowcol = imagecolorallocate($image, 71, 71, 71);
- }
- imagefilledrectangle ($image, 2, $pich + 1, 696, $pich + 22, $rowcol);
- }
- }
- // get title for titlebar and define number of rows
- $title = "FUSION F1 League";
- $rows = 30;
- switch ($stats) {
- case 1:
- $titleString = $title." ~ Race Attendance Div 1 ~ Top ".$rows;
- break;
- case 2:
- $titleString = $title." ~ Pole Positions ~ Top ".$rows;;
- break;
- case 3:
- $titleString = $title." ~ Race Wins ~ Top ".$rows;
- break;
- case 4:
- $titleString = $title." ~ Podiums ~ Top ".$rows;
- break;
- case 5:
- $titleString = $title." ~ Hall of Fame";
- break;
- case 6:
- $titleString = $title." ~ Race Attendance Div 2 ~ Top ".$rows;
- break;
- case 7:
- $titleString = $title." ~ Pole Positions Div 2 ~ Top ".$rows;;
- break;
- case 8:
- $titleString = $title." ~ Race Wins Div 2 ~ Top ".$rows;
- break;
- case 9:
- $titleString = $title." ~ Podiums Div 2 ~ Top ".$rows;
- break;
- case 10:
- $titleString = $title." ~ Hall of Fame ";
- break;
- // get award rows
- $tablename = $wpdb->prefix . "fusion_f1_awards";
- //$awards = $wpdb->get_results( $wpdb->prepare(
- $awards = $wpdb->get_results(
- "
- SELECT seasonID
- FROM $tablename
- "
- );
- //) );
- $awardrows = $wpdb->num_rows;
- $rows = $awardrows;
- // get champion rows
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $champs = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT DISTINCT(seasonID) as season
- FROM $tablename
- WHERE seasonID > %d AND raceID > %d
- GROUP BY seasonID
- ",
- 0,
- 0
- ) );
- foreach ($champs as $val) {
- // get total champs across divisions
- $tablename = $wpdb->prefix . "fusion_f1_seasonparams";
- $divchamps = $wpdb->get_var(
- "
- SELECT SUM(divs) as season
- FROM $tablename
- "
- );
- }
- $rows += $divchamps + 3;
- break;
- }
- // define image variables
- $boxh = ( $lineh * 2 ) + ($lineh * $rows) + 9;
- $image = imagecreatetruecolor ( 700, $boxh );
- $bgcol = imagecolorallocate($image, 34, 34, 34);
- $fgcol = imagecolorallocate($image, 51, 51, 51);
- $txcol = imagecolorallocate($image, 255, 255, 255);
- $txcol2 = imagecolorallocate($image, 204, 204, 204);
- $txcol3 = imagecolorallocate($image, 175, 175, 175);
- $ttcol = imagecolorallocate($image, 0, 200, 0);
- $stcol = imagecolorallocate($image, 168, 3, 41);
- $txgold = imagecolorallocate($image, 220, 210, 55);
- $txsilver = imagecolorallocate($image, 192, 192, 192);
- $txbronze = imagecolorallocate($image, 196, 125, 61);
- // create base image
- imagefill ($image, 0, 0, $bgcol);
- // Create title bar
- $fsize = 11;
- imagefilledrectangle ($image, 2, 2, 697, $lineh + 6, $ttcol);
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $titleString );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(348 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2)+2, $txcol, $font2, $titleString );
- // add logos to titlebar
- $f1logo = "images/s_f1_logo.png";
- $f1 = imagecreatefrompng($f1logo);
- imagesavealpha($f1, true);
- imagecopy($image, $f1, 5, 5 , 0, 0, 57, 23);
- $aclogo = "images/s_ac_logo.png";
- $ac = imagecreatefrompng($aclogo);
- imagesavealpha($ac, true);
- imagecopy($image, $ac, 65, 5 , 0, 0, 26, 23);
- $fuslogo = "images/s_logo.png";
- $fus = imagecreatefrompng($fuslogo);
- imagesavealpha($fus, true);
- imagecopy($image, $fus, 672, 5 , 0, 0, 23, 23);
- // create rows (alternate colours)
- rows($rows);
- // create column lines
- imagerectangle($image, 233, $lineh+8, 466, $boxh, $bgcol);
- // ********************* Race Attendance *********************
- if ($stats == 1) {
- // column headings
- $ch[1] = "Driver";
- $ch[2] = "Races Attended";
- $ch[3] = "Races Finished (%)";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
- // get attendance records for top 10
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $races = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT playerID, COUNT(playerID) as races
- FROM $tablename
- WHERE raceID > %d AND divID = 1
- GROUP BY playerID
- ORDER BY races DESC
- LIMIT %d
- ",
- 0,
- $rows ) );
- foreach ( $races as $val ) {
- // get player names
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $player = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %s
- ",
- $val->playerID
- ) );
- // get races not finished
- $dnfdsq = "%D%";
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $nonfinishes = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT COUNT(resultID)
- FROM $tablename
- WHERE playerID = %d AND raceID > %d AND resultTime LIKE %s AND divID = 1
- ",
- $val->playerID,
- 0,
- $dnfdsq
- ) );
- $finishes = $val->races-$nonfinishes;
- $percentfinishes = ($finishes/$val->races)*100;
- $finishes .= " (".round($percentfinishes)."%)";
- $pich = $lineh;
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
- imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
- imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
- $box = imageTTFbbox( $fsize, 0, $font2, $finishes );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $finishes );
- $lines++;
- }
- }
- // ********************* Pole Positions *********************
- if ($stats == 2) {
- // column headings
- $ch[1] = "Driver";
- $ch[2] = "Pole Positions";
- $ch[3] = "Poles Converted to Wins (%)";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
- // get pole positions for top 10
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $races = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT playerID, COUNT(playerID) as races
- FROM $tablename
- WHERE raceID > %d AND resultGrid = %d AND divID = 1
- GROUP BY playerID
- ORDER BY races DESC LIMIT %d
- ",
- 0,
- 1,
- $rows
- ) );
- // show top 10 pole positions
- $i = 1;
- foreach ( $races as $val ) {
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $player = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %s
- ",
- $val->playerID
- ) );
- // get pole converted
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $conversions = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT COUNT(resultID)
- FROM $tablename
- WHERE playerID = %d AND raceID > %d AND resultGrid = %d AND resultPosition = %d AND divID = 1
- ",
- $val->playerID,
- 0,
- 1,
- 1
- ) );
- $percentconversions = ($conversions/$val->races)*100;
- $conversions .= " (".round($percentconversions)."%)";
- $pich = $lineh;
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
- imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
- imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
- $box = imageTTFbbox( $fsize, 0, $font2, $conversions );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $conversions );
- $lines++;
- $i++;
- }
- }
- // ********************* Race Wins *********************
- if ($stats == 3) {
- // column headings
- $ch[1] = "Driver";
- $ch[2] = "Race Wins";
- $ch[3] = "Lowest Qualification to Win";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
- // get race wins for top 10
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $races = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT playerID, COUNT(playerID) as races
- FROM $tablename
- WHERE raceID > %d AND resultPosition = %d AND divID = 1
- GROUP BY playerID
- ORDER BY races DESC LIMIT %d
- ",
- 0,
- 1,
- $rows
- ) );
- // show top 10 race wins
- $i = 1;
- foreach ( $races as $val ) {
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $player = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %d
- ",
- $val->playerID
- ) );
- // get lowest quali to win
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $lowestqtowin = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT MAX(resultGrid)
- FROM $tablename
- WHERE playerID = %d AND raceID > %d AND resultPosition = %d AND resultGrid > %d AND divID = 1
- ",
- $val->playerID,
- 0,
- 1,
- 0
- ) );
- $pich = $lineh;
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
- imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
- imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
- $box = imageTTFbbox( $fsize, 0, $font2, $lowestqtowin );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $lowestqtowin );
- $lines++;
- $i++;
- }
- }
- // ********************* Podiums *********************
- if ($stats == 4) {
- // column headings
- $ch[1] = "Driver";
- $ch[2] = "Podiums";
- $ch[3] = "Podium/Race Average";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(292 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
- $cupPic = "images/cup1.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 359, $lineh+($lineh/2)-2, 0, 0, 18, 21);
- $cupPic = "images/cup2.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 397, $lineh+($lineh/2)-2, 0, 0, 18, 21);
- $cupPic = "images/cup3.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 435, $lineh+($lineh/2)-2, 0, 0, 18, 21);
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
- // get podiums for top 10
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $races = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT playerID, COUNT(playerID) as races, SUM(podium1) as gold, SUM(podium2) as silver, SUM(podium3) as bronze
- FROM $tablename
- WHERE raceID > %d AND resultPosition <= %d AND divID = 1
- GROUP BY playerID
- ORDER BY races DESC LIMIT %d
- ",
- 0,
- 3,
- $rows
- ) );
- // show top 10 podiums
- $i = 1;
- foreach ( $races as $val ) {
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $player = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %d
- ",
- $val->playerID
- ) );
- // get podiums / race average
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $races = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT COUNT(resultID)
- FROM $tablename
- WHERE playerID = %d AND raceID > %d AND divID = 1
- ",
- $val->playerID,
- 0
- ) );
- $podiums = $val->races;
- $podraceaverage = ROUND(($val->races / $races) * 100)."%";
- $pich = $lineh;
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
- imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
- imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
- $box = imageTTFbbox( $fsize, 0, $font2, $podiums );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(292 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $podiums );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->gold );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(368 - ($txtwidth/2)), $txth + 5, $txgold, $font2, $val->gold );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->silver );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(406 - ($txtwidth/2)), $txth + 5, $txsilver, $font2, $val->silver );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->bronze );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(444 - ($txtwidth/2)), $txth + 5, $txbronze, $font2, $val->bronze );
- $box = imageTTFbbox( $fsize, 0, $font2, $podraceaverage );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $podraceaverage );
- $lines++;
- $i++;
- }
- }
- // ********************* Hall of Fame *********************
- // Awards
- if ($stats == 5) {
- $subtitleString = "Awards";
- $fsize = 11;
- $pich = $lineh +6;
- imagefilledrectangle ($image, 2, $pich+3, 697, $pich + $lineh, $stcol);
- $subtitleBox = imageTTFbbox( $fsize, 0, $font2, $subtitleString );
- $textwidth = abs( $subtitleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(348 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich, $txcol, $font2, $subtitleString );
- imagefilledrectangle ($image, 2, $pich+$lineh, 697, $pich + ($lineh*2), $bgcol);
- // column headings
- $fsize = 12;
- $ch[1] = "";
- $ch[2] = "Rookie of the Season";
- $ch[3] = "Driver of the Season";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[2] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[3] );
- // get rookies/drivers of the years
- $tablename = $wpdb->prefix . "fusion_f1_awards";
- $award = $wpdb->get_results(
- "
- SELECT *
- FROM $tablename
- ORDER BY seasonID DESC
- "
- ) ;
- foreach ($award as $val) {
- $tablename = $wpdb->prefix . "fusion_f1_races";
- $game = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT raceGame
- FROM $tablename
- WHERE raceOrder = %d AND raceSeason = %d
- ",
- 1,
- $val->seasonID
- ) );
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $rookie = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %d
- ",
- $val->rookieID
- ) );
- $driver = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %d
- ",
- $val->driverID
- ) );
- $pich = $lineh*2;
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
- $gamePic = "images/".$game."/s_logo.png";
- $gameP = imagecreatefrompng($gamePic);
- imagesavealpha($gameP, true);
- imagecopy($image, $gameP, 3, $txth-($lineh/2), 0, 0, 70, 22);
- $sgame = "Season ".$val->seasonID;
- $box = imageTTFbbox( $fsize, 0, $font2, $sgame );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(153 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $sgame );
- $box = imageTTFbbox( $fsize, 0, $font2, $rookie );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $rookie );
- $box = imageTTFbbox( $fsize, 0, $font2, $driver );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $driver );
- $lines++;
- $i++;
- }
- // get champions
- $lines=1;
- $subtitleString = "Champions";
- $fsize = 12;
- $pich = ($lineh * $awardrows) + ($lineh*3) + 6;
- imagefilledrectangle ($image, 2, $pich+3, 697, $pich + $lineh, $stcol);
- $subtitleBox = imageTTFbbox( $fsize, 0, $font2, $subtitleString );
- $textwidth = abs( $subtitleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(348 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich, $txcol, $font2, $subtitleString );
- imagefilledrectangle ($image, 2, $pich+$lineh+3, 697, $pich + ($lineh*2), $bgcol);
- // column headings
- $ch[1] = "";
- $ch[2] = "Driver";
- $ch[3] = "Podiums";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[2] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(525 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[3] );
- $cupPic = "images/cup1.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 592, $pich+$lineh+3, 0, 0, 18, 21);
- $cupPic = "images/cup2.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 630, $pich+$lineh+3, 0, 0, 18, 21);
- $cupPic = "images/cup3.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 668,$pich+$lineh+3, 0, 0, 18, 21);
- // get current season
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $currseason = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT MAX(seasonID) as currseason
- FROM $tablename
- WHERE raceID > %d
- ",
- 0
- ) );
- // get list of seasons
- $tablename = $wpdb->prefix . "fusion_f1_seasonparams";
- $seasons = $wpdb->get_results(
- "
- SELECT seasonID, game, divs
- FROM $tablename
- ORDER BY seasonID DESC
- "
- );
- foreach ($seasons as $val) {
- for ($ii=1; $ii<=$val->divs; $ii++) {
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $champ = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerID, SUM(resultPoints) as points
- FROM $tablename
- WHERE raceID > %d AND seasonID = %d AND divID = %d
- GROUP BY playerID
- ORDER BY points DESC
- ",
- 0,
- $val->seasonID,
- $ii
- ) );
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $player = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %d
- ",
- $champ
- ) );
- // check to see if mid season
- $tablename = $wpdb->prefix . "fusion_f1_races";
- $races = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT COUNT(raceID) as races
- FROM $tablename
- WHERE raceSeason = %d AND divID = %d
- ",
- $val->seasonID,
- $ii
- ) );
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $racesraced = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT COUNT(raceID) as raced
- FROM $tablename
- WHERE raceID > %d and seasonID = %d AND divID = %d
- GROUP BY raceID
- ",
- 0,
- $val->seasonID,
- $ii
- ) );
- $raced = $wpdb->num_rows;
- // if mid-season current champion, add 'leading' to string
- if (($currseason == $val->seasonID) && ($raced < $races)) $player .=" (leading)";
- // get podiums for player/season
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $cups = $wpdb->get_row( $wpdb->prepare(
- "
- SELECT playerID, COUNT(playerID) as podiums, SUM(podium1) as gold, SUM(podium2) as silver, SUM(podium3) as bronze
- FROM $tablename
- WHERE raceID > %d AND resultPosition <= %d AND seasonID = %d AND playerID = %d
- ",
- 0,
- 3,
- $val->seasonID,
- $champ
- ) );
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * ($lineh) + $lineh);
- $gamePic = "images/".$val->game."/s_logo.png";
- $gameP = imagecreatefrompng($gamePic);
- imagesavealpha($gameP, true);
- imagecopy($image, $gameP, 3, $txth-($lineh/2)-5, 0, 0, 70, 22);
- $sgame = "Season ".$val->seasonID;
- if ($val->divs > 1) {
- $sgame .= " Div ".$ii;
- }
- $box = imageTTFbbox( $fsize, 0, $font2, $sgame );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(153 - ($txtwidth/2)), $txth, $txcol, $font2, $sgame );
- $box = imageTTFbbox( $fsize, 0, $font2, $player );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth, $txcol, $font2, $player );
- $box = imageTTFbbox( $fsize, 0, $font2, $cups->podiums );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(525 - ($txtwidth/2)), $txth, $txcol, $font2, $cups->podiums );
- $box = imageTTFbbox( $fsize, 0, $font2, $cups->gold );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(601 - ($txtwidth/2)), $txth, $txgold, $font2, $cups->gold );
- $box = imageTTFbbox( $fsize, 0, $font2, $cups->silver );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(639 - ($txtwidth/2)), $txth, $txsilver, $font2, $cups->silver );
- $box = imageTTFbbox( $fsize, 0, $font2, $cups->bronze );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(677- ($txtwidth/2)), $txth, $txbronze, $font2, $cups->bronze );
- $lines++;
- $i++;
- }
- }
- }
- // ********************* Race Attendance Div 2*********************
- if ($stats == 6) {
- // column headings
- $ch[1] = "Driver";
- $ch[2] = "Races Attended";
- $ch[3] = "Races Finished (%)";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
- // get attendance records for top 10
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $races = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT playerID, COUNT(playerID) as races
- FROM $tablename
- WHERE raceID > %d AND divID = 2
- GROUP BY playerID
- ORDER BY races DESC
- LIMIT %d
- ",
- 0,
- $rows ) );
- foreach ( $races as $val ) {
- // get player names
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $player = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %s
- ",
- $val->playerID
- ) );
- // get races not finished
- $dnfdsq = "%D%";
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $nonfinishes = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT COUNT(resultID)
- FROM $tablename
- WHERE playerID = %d AND raceID > %d AND resultTime LIKE %s AND divID = 2
- ",
- $val->playerID,
- 0,
- $dnfdsq
- ) );
- $finishes = $val->races-$nonfinishes;
- $percentfinishes = ($finishes/$val->races)*100;
- $finishes .= " (".round($percentfinishes)."%)";
- $pich = $lineh;
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
- imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
- imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
- $box = imageTTFbbox( $fsize, 0, $font2, $finishes );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $finishes );
- $lines++;
- }
- }
- // ********************* Pole Positions Div 2*********************
- if ($stats == 7) {
- // column headings
- $ch[1] = "Driver";
- $ch[2] = "Pole Positions";
- $ch[3] = "Poles Converted to Wins (%)";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
- // get pole positions for top 10
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $races = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT playerID, COUNT(playerID) as races
- FROM $tablename
- WHERE raceID > %d AND resultGrid = %d AND divID = 2
- GROUP BY playerID
- ORDER BY races DESC LIMIT %d
- ",
- 0,
- 1,
- $rows
- ) );
- // show top 10 pole positions
- $i = 1;
- foreach ( $races as $val ) {
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $player = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %s
- ",
- $val->playerID
- ) );
- // get pole converted
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $conversions = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT COUNT(resultID)
- FROM $tablename
- WHERE playerID = %d AND raceID > %d AND resultGrid = %d AND resultPosition = %d AND divID = 2
- ",
- $val->playerID,
- 0,
- 1,
- 1
- ) );
- $percentconversions = ($conversions/$val->races)*100;
- $conversions .= " (".round($percentconversions)."%)";
- $pich = $lineh;
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
- imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
- imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
- $box = imageTTFbbox( $fsize, 0, $font2, $conversions );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $conversions );
- $lines++;
- $i++;
- }
- }
- // ********************* Race Wins Div 2*********************
- if ($stats == 8) {
- // column headings
- $ch[1] = "Driver";
- $ch[2] = "Race Wins";
- $ch[3] = "Lowest Qualification to Win";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
- // get race wins for top 10
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $races = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT playerID, COUNT(playerID) as races
- FROM $tablename
- WHERE raceID > %d AND resultPosition = %d AND divID = 2
- GROUP BY playerID
- ORDER BY races DESC LIMIT %d
- ",
- 0,
- 1,
- $rows
- ) );
- // show top 10 race wins
- $i = 1;
- foreach ( $races as $val ) {
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $player = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %d
- ",
- $val->playerID
- ) );
- // get lowest quali to win
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $lowestqtowin = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT MAX(resultGrid)
- FROM $tablename
- WHERE playerID = %d AND raceID > %d AND resultPosition = %d AND resultGrid > %d AND divID = 2
- ",
- $val->playerID,
- 0,
- 1,
- 0
- ) );
- $pich = $lineh;
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
- imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
- imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->races );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $val->races );
- $box = imageTTFbbox( $fsize, 0, $font2, $lowestqtowin );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $lowestqtowin );
- $lines++;
- $i++;
- }
- }
- // ********************* Podiums Div 2*********************
- if ($stats == 9) {
- // column headings
- $ch[1] = "Driver";
- $ch[2] = "Podiums";
- $ch[3] = "Podium/Race Average";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(292 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[2] );
- $cupPic = "images/cup1.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 359, $lineh+($lineh/2)-2, 0, 0, 18, 21);
- $cupPic = "images/cup2.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 397, $lineh+($lineh/2)-2, 0, 0, 18, 21);
- $cupPic = "images/cup3.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 435, $lineh+($lineh/2)-2, 0, 0, 18, 21);
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 2 + 2, $txcol3, $font2, $ch[3] );
- // get podiums for top 10
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $races = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT playerID, COUNT(playerID) as races, SUM(podium1) as gold, SUM(podium2) as silver, SUM(podium3) as bronze
- FROM $tablename
- WHERE raceID > %d AND resultPosition <= %d AND divID = 2
- GROUP BY playerID
- ORDER BY races DESC LIMIT %d
- ",
- 0,
- 3,
- $rows
- ) );
- // show top 10 podiums
- $i = 1;
- foreach ( $races as $val ) {
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $player = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %d
- ",
- $val->playerID
- ) );
- // get podiums / race average
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $races = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT COUNT(resultID)
- FROM $tablename
- WHERE playerID = %d AND raceID > %d AND divID = 2
- ",
- $val->playerID,
- 0
- ) );
- $podiums = $val->races;
- $podraceaverage = ROUND(($val->races / $races) * 100)."%";
- $pich = $lineh;
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
- imageTTFtext( $image, $fsize , 0, 13, $txth + 5, $txcol, $font2, $lines );
- imageTTFtext( $image, $fsize , 0, 50, $txth + 5, $txcol, $font2, $player );
- $box = imageTTFbbox( $fsize, 0, $font2, $podiums );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(292 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $podiums );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->gold );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(368 - ($txtwidth/2)), $txth + 5, $txgold, $font2, $val->gold );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->silver );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(406 - ($txtwidth/2)), $txth + 5, $txsilver, $font2, $val->silver );
- $box = imageTTFbbox( $fsize, 0, $font2, $val->bronze );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(444 - ($txtwidth/2)), $txth + 5, $txbronze, $font2, $val->bronze );
- $box = imageTTFbbox( $fsize, 0, $font2, $podraceaverage );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $ttcol, $font2, $podraceaverage );
- $lines++;
- $i++;
- }
- }
- // ********************* Hall of Fame *********************
- // Awards
- if ($stats == 10) {
- $subtitleString = "Awards";
- $fsize = 11;
- $pich = $lineh +6;
- imagefilledrectangle ($image, 2, $pich+3, 697, $pich + $lineh, $stcol);
- $subtitleBox = imageTTFbbox( $fsize, 0, $font2, $subtitleString );
- $textwidth = abs( $subtitleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(348 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich, $txcol, $font2, $subtitleString );
- imagefilledrectangle ($image, 2, $pich+$lineh, 697, $pich + ($lineh*2), $bgcol);
- // column headings
- $fsize = 12;
- $ch[1] = "";
- $ch[2] = "Rookie of the Season";
- $ch[3] = "Driver of the Season";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[2] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(583 - ($textwidth/2)), $lineh * 3 + 2, $txcol3, $font2, $ch[3] );
- // get rookies/drivers of the years
- $tablename = $wpdb->prefix . "fusion_f1_awards";
- $award = $wpdb->get_results(
- "
- SELECT *
- FROM $tablename
- ORDER BY seasonID DESC
- "
- ) ;
- foreach ($award as $val) {
- $tablename = $wpdb->prefix . "fusion_f1_races";
- $game = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT raceGame
- FROM $tablename
- WHERE raceOrder = %d AND raceSeason = %d
- ",
- 1,
- $val->seasonID
- ) );
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $rookie = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %d
- ",
- $val->rookieID
- ) );
- $driver = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %d
- ",
- $val->driverID
- ) );
- $pich = $lineh*2;
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * $lineh) +1;
- $gamePic = "images/".$game."/s_logo.png";
- $gameP = imagecreatefrompng($gamePic);
- imagesavealpha($gameP, true);
- imagecopy($image, $gameP, 3, $txth-($lineh/2), 0, 0, 70, 22);
- $sgame = "Season ".$val->seasonID;
- $box = imageTTFbbox( $fsize, 0, $font2, $sgame );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(153 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $sgame );
- $box = imageTTFbbox( $fsize, 0, $font2, $rookie );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $rookie );
- $box = imageTTFbbox( $fsize, 0, $font2, $driver );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(583 - ($txtwidth/2)), $txth + 5, $txcol, $font2, $driver );
- $lines++;
- $i++;
- }
- // get champions
- $lines= 20;
- $subtitleString = "Champions";
- $fsize = 12;
- $pich = ($lineh * $awardrows) + ($lineh*3) + 6;
- imagefilledrectangle ($image, 2, $pich+3, 697, $pich + $lineh, $stcol);
- $subtitleBox = imageTTFbbox( $fsize, 0, $font2, $subtitleString );
- $textwidth = abs( $subtitleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(348 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich, $txcol, $font2, $subtitleString );
- imagefilledrectangle ($image, 2, $pich+$lineh+3, 697, $pich + ($lineh*2), $bgcol);
- // column headings
- $ch[1] = "";
- $ch[2] = "Driver";
- $ch[3] = "Podiums";
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[1] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(117 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[1] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[2] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(350 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[2] );
- $titleBox = imageTTFbbox( $fsize, 0, $font2, $ch[3] );
- $textwidth = abs( $titleBox[2] );
- imageTTFtext( $image, $fsize, 0, intval(525 - ($textwidth/2)), ($lineh/2)+(($fsize/3)*2) + $pich + $lineh, $txcol3, $font2, $ch[3] );
- $cupPic = "images/cup1.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 592, $pich+$lineh+3, 0, 0, 18, 21);
- $cupPic = "images/cup2.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 630, $pich+$lineh+3, 0, 0, 18, 21);
- $cupPic = "images/cup3.png";
- $cupP = imagecreatefrompng($cupPic);
- imagesavealpha($cupP, true);
- imagecopy($image, $cupP, 668,$pich+$lineh+3, 0, 0, 18, 21);
- // get current season
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $currseason = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT MAX(seasonID) as currseason
- FROM $tablename
- WHERE raceID > %d
- ",
- 0
- ) );
- // get list of seasons
- $tablename = $wpdb->prefix . "fusion_f1_seasonparams";
- $seasons = $wpdb->get_results(
- "
- SELECT seasonID, game, divs
- FROM $tablename
- ORDER BY seasonID DESC
- "
- );
- foreach ($seasons as $val) {
- for ($ii=1; $ii<=$val->divs; $ii++) {
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $champ = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerID, SUM(resultPoints) as points
- FROM $tablename
- WHERE raceID > %d AND seasonID = %d AND divID = %d
- GROUP BY playerID
- ORDER BY points DESC
- ",
- 0,
- $val->seasonID,
- $ii
- ) );
- $tablename = $wpdb->prefix . "fusion_f1_players";
- $player = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT playerName
- FROM $tablename
- WHERE playerID = %d
- ",
- $champ
- ) );
- // check to see if mid season
- $tablename = $wpdb->prefix . "fusion_f1_races";
- $races = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT COUNT(raceID) as races
- FROM $tablename
- WHERE raceSeason = %d AND divID = %d
- ",
- $val->seasonID,
- $ii
- ) );
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $racesraced = $wpdb->get_results( $wpdb->prepare(
- "
- SELECT COUNT(raceID) as raced
- FROM $tablename
- WHERE raceID > %d and seasonID = %d AND divID = %d
- GROUP BY raceID
- ",
- 0,
- $val->seasonID,
- $ii
- ) );
- $raced = $wpdb->num_rows;
- // if mid-season current champion, add 'leading' to string
- if (($currseason == $val->seasonID) && ($raced < $races)) $player .=" (leading)";
- // get podiums for player/season
- $tablename = $wpdb->prefix . "fusion_f1_results";
- $cups = $wpdb->get_row( $wpdb->prepare(
- "
- SELECT playerID, COUNT(playerID) as podiums, SUM(podium1) as gold, SUM(podium2) as silver, SUM(podium3) as bronze
- FROM $tablename
- WHERE raceID > %d AND resultPosition <= %d AND seasonID = %d AND playerID = %d
- ",
- 0,
- 3,
- $val->seasonID,
- $champ
- ) );
- $txth = $pich + (($lineh/2)+(($fsize/3)*2)) + ($lines * ($lineh) + $lineh);
- $gamePic = "images/".$val->game."/s_logo.png";
- $gameP = imagecreatefrompng($gamePic);
- imagesavealpha($gameP, true);
- imagecopy($image, $gameP, 3, $txth-($lineh/2)-5, 0, 0, 70, 22);
- $sgame = "Season ".$val->seasonID;
- if ($val->divs > 1) {
- $sgame .= " Div ".$ii;
- }
- $box = imageTTFbbox( $fsize, 0, $font2, $sgame );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(153 - ($txtwidth/2)), $txth, $txcol, $font2, $sgame );
- $box = imageTTFbbox( $fsize, 0, $font2, $player );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(350 - ($txtwidth/2)), $txth, $txcol, $font2, $player );
- $box = imageTTFbbox( $fsize, 0, $font2, $cups->podiums );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(525 - ($txtwidth/2)), $txth, $txcol, $font2, $cups->podiums );
- $box = imageTTFbbox( $fsize, 0, $font2, $cups->gold );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(601 - ($txtwidth/2)), $txth, $txgold, $font2, $cups->gold );
- $box = imageTTFbbox( $fsize, 0, $font2, $cups->silver );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(639 - ($txtwidth/2)), $txth, $txsilver, $font2, $cups->silver );
- $box = imageTTFbbox( $fsize, 0, $font2, $cups->bronze );
- $txtwidth = abs( $box[2] );
- imageTTFtext( $image, $fsize , 0, intval(677- ($txtwidth/2)), $txth, $txbronze, $font2, $cups->bronze );
- $lines++;
- $i++;
- }
- }
- }
- // output image
- imagepng($image);
- imagedestroy($image);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement