HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.34
System: Linux atalantini.com 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64
User: root (0)
PHP: 7.2.34
Disabled: NONE
Upload Files
File: //opt/Newsmag/classifica.php
<?php
/*
Template Name: Classifica
*/
$suffix = "";
if (isset($_GET['suffix'])) {
	$suffix = $_GET['suffix'];
}


function getImmagine($squadra, $img1, $img2) {
	$squadra = strtolower($squadra);
        if (strpos($squadra, "atalanta") > -1) {
                $squadra = "atalanta";
        }
	if ($squadra != "atalanta") {
		return $img1;
	} else {
		return $img2;
	}
}

function getCasaFuori($squadra) {
        $squadra = strtolower($squadra);
        if (strpos($squadra, "atalanta") > -1) {
                $squadra = "atalanta";
        }
        if ($squadra != "atalanta") {
                return "T";
        } else {
                return "C";
        }
}

function getBackground($squadra, $rs1, $rs2) {
	$color = "green";
        $squadra = strtolower($squadra);
        if (strpos($squadra, "atalanta") > -1) {
                $squadra = "atalanta";
        }
	if ($rs1 == $rs2) {
		$color = "#ffd800";
	} else {
        	if ($squadra != "atalanta") {
			if ($rs1 > $rs2) {
				$color = "red";
			}
		} else {
                        if ($rs1 < $rs2) {
                                $color = "red";
                        }
		}
	}
	return $color;
}

function getBackgroundVote($voto, $maxvoto, $role, $player, $player_1) {
        $background = "";
        //if ($voto == $maxvoto) {
        if ($player == $player_1) {
                $background = "#00a2ff";
        }
        if (!is_numeric($voto)) {
                $background = "";
        }
        if ($role == "ALLENATORE") {
                $background = "";
        }
        return $background;
}

$uri = $_SERVER['REQUEST_URI'];
$girone = array();
$girone[] = "ANDATA";
$girone[] = "RITORNO";

$ruoli = array();
$ruoli[] = "ALLENATORE";
$ruoli[] = "PORTIERE";
$ruoli[] = "DIFENSORE";
$ruoli[] = "CENTROCAMPISTA";
$ruoli[] = "ATTACCANTE";
$armedia = array();
?>
<?php get_header(); ?>
<style>

#balance {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    width: 100%;
    height:300px !important; 
    border-collapse: collapse;
}

#balance td, #balance th {
    font-size: 0.7em;
    border: 1px solid #1a7cbf;
    padding: 3px 7px 2px 7px;
}

#balance td {
    height:42px !important;
}

#balance th {
    font-size: 0.7em;
    text-align: left;
    padding-top: 5px;
    padding-bottom: 4px;
    background-color: #1a7cbf;
    color: #ffffff;
}

#balance tr.alt td {
    color: #000000;
    width:10px;
    background-color: #1a7cbf;
}

</style>
<div class="td-main-content-wrap">
	<div class="td-container">
		<div class="td-container-border">
			<div class="td-pb-row">
				<div class="td-pb-span12 td-main-content">
<br><br>
<span class="td-pulldown-size">CLASSIFICA</span>
							<br>
							<?php for ($c = 0; $c < count($girone); $c++) {
								echo "<h2>" . $girone[$c] . "</h2>";
								?>
<figure class="wp-block-table">
								<table width="100%" id="balance" cellspacing="3" cellpadding="3">
									<tr>
										<td align="center"><img width="30" src="/wp-content/themes/atalantini/squadre/logo_atalanta.gif"></td>
										<?php
									        $sql = "select * from wp_plugin_atalantini_team" . $suffix . " where tipo = '0' and girone = '" . $girone[$c] . "';";
									        $teams = $wpdb->get_results($sql);
									        foreach ( $teams as $team )  {
										?>
                                                                                <td  align="center">
											<img width="50" height="50" src="/wp-content/themes/atalantini/squadre/<?= getImmagine($team->sq1, $team->immagine1, $team->immagine2) ?>">
										<?= getCasaFuori($team->sq1) ?>
										</td>
										<?php
										}
										?>
										<td></td>
									</tr>
                                                                        <tr>
                                                                                <td align="center"></td>
                                                                                <?php
                                                                                $sql = "select * from wp_plugin_atalantini_team" . $suffix . " where tipo = '0' and  girone = '" . $girone[$c] . "';";
                                                                                $teams = $wpdb->get_results($sql);
                                                                                foreach ( $teams as $team )  {
                                                                                ?>
                                                                                <td  align="center" bgcolor="<?= getBackground($team->sq1, $team->resultsq1, $team->resultsq2) ?>"><?= $team->resultsq1 ?> - <?= $team->resultsq2 ?></td>
                                                                                <?php
                                                                                }
                                                                                ?>
                                                                                <td></td>
                                                                        </tr>
									<?php
           		                                                     //foreach ($ruoli as $ruolo) {
										$avg = 0;
										$countavg = 0;
                        		                                        //$sql = "select wp_plugin_atalantini_player" . $suffix . ".id, numero, nominativo,count(vote) as vote, (select count(vote) from wp_plugin_votazioni" . $suffix . " where player_id = wp_plugin_atalantini_player" . $suffix . ".id) as totale, (select avg(voto) from (select avg(vote) as voto,player_id from wp_plugin_votazioni" . $suffix . " where  vote is not null and vote != 's.v.' and vote != '' and game  group by game,player_id) as avgs where player_id = wp_plugin_atalantini_player" . $suffix . ".id) as maxtotale, 100 as totalepartite from wp_plugin_atalantini_player" . $suffix . ", wp_plugin_votazioni" . $suffix . " where vote is not null and player_id = wp_plugin_atalantini_player" . $suffix . ".id group by wp_plugin_atalantini_player" . $suffix . ".id, numero, nominativo order by totale  desc, maxtotale desc;";
										$sql = "(select wp_plugin_atalantini_player" . $suffix . ".id, numero, nominativo,count(vote) as vote, (select count(vote) from wp_plugin_votazioni" . $suffix . " where player_id = wp_plugin_atalantini_player" . $suffix . ".id) as totale, 10 as maxtotale, 100 as totalepartite from wp_plugin_atalantini_player" . $suffix . ", wp_plugin_votazioni" . $suffix . " where game in (select id  from wp_plugin_atalantini_team where tipo = '0') and vote is not null and player_id = wp_plugin_atalantini_player" . $suffix . ".id and ruolo = 'ALLENATORE' group by wp_plugin_atalantini_player" . $suffix . ".id, numero, nominativo order by round(maxtotale * 1) desc) union (select wp_plugin_atalantini_player" . $suffix . ".id, numero, nominativo,count(vote) as vote, (select count(vote) from wp_plugin_votazioni" . $suffix . " where player_id = wp_plugin_atalantini_player" . $suffix . ".id) as totale, (select avg(voto) from (select avg(vote) as voto,player_id from wp_plugin_votazioni" . $suffix . " where  vote is not null and vote != 's.v.' and vote != '' and game  group by game,player_id) as avgs where player_id = wp_plugin_atalantini_player" . $suffix . ".id) as maxtotale, (select count(distinct(game)) from wp_plugin_votazioni" . $suffix . " where game in (select id  from wp_plugin_atalantini_team where tipo = '0') and player_id = wp_plugin_atalantini_player" . $suffix . ".id and vote > 0) as totalepartite from wp_plugin_atalantini_player" . $suffix . ", wp_plugin_votazioni" . $suffix . " where  game in (select id  from wp_plugin_atalantini_team where tipo = '0') and vote is not null and player_id = wp_plugin_atalantini_player" . $suffix . ".id and ruolo != 'ALLENATORE' group by wp_plugin_atalantini_player" . $suffix . ".id, numero, nominativo order by totalepartite desc, (maxtotale * 1) desc) order by totalepartite desc,maxtotale desc;";
                                                                		$players = $wpdb->get_results($sql);
                                                                		foreach ( $players as $player )  {
                                                                                $avg = 0;
                                                                                $countavg = 0;

										?>
                                                                        <tr>
                                                                                <td  align="left">
										<?= $player->nominativo ?>
										<?php if ($player->totalepartite < 100) {
											echo " (" . $player->totalepartite . ")";
										} ?>
										</td>
                                                                                <?php
                                                                                $sql = "select id,wp_plugin_atalantini_team" . $suffix . ".id as game , (select avg(vote) from wp_plugin_votazioni" . $suffix . " where game = wp_plugin_atalantini_team" . $suffix . ".id  and player_id = " . $player->id . " and vote != 's.v.' and vote is not null) as voto, (select max(vote) from wp_plugin_votazioni" . $suffix . " where vote is not null and vote != 's.v.' and game = wp_plugin_atalantini_team" . $suffix . ".id) as maxvoto from wp_plugin_atalantini_team" . $suffix . " where tipo = '0' and girone = '" . $girone[$c] . "';";
                                                                                $teams = $wpdb->get_results($sql);
                                                                                foreach ( $teams as $team )  {
                                                                                        if (is_numeric($team->voto)) {
                                                                                                if ($team->voto > 0) {
                                                                                                        $avg = $avg + $team->voto;
                                                                                                        $countavg++;
                                                                                                }
                                                                                        }
											$avg_vote = 
                                                                                        //$current_player = $wpdb->get_var( "select player_id from wp_plugin_votazioni" . $suffix . " where vote = '" . $team->maxvoto . "' and game = " . $team->game . ";" );
											$current_player = $wpdb->get_var( "select player_id from wp_plugin_votazioni" . $suffix . " where vote != 's.v.'  and vote != '' and game = " . $team->game . " and player_id in (select distinct(id) from wp_plugin_atalantini_player" . $suffix . " where ruolo != 'ALLENATORE') group by player_id order by avg(vote) desc limit 1");
                                                                                ?>
                                                                                <td valign="top"  align="center" bgcolor="<?= getBackgroundVote($team->voto, $team->maxvoto, $ruolo, $player->id, $current_player); ?>">
                                                                                <?php
                                                                                $voto = $team->voto;
                                                                                if ($voto == "0")  {
                                                                                        $voto = "s.v.";
                                                                                }
                                                                                echo round($voto,2);
										?></td>
                                                                                <?php
                                                                                }
                                                                                ?>
                                                                                <td valign="top" style="text-align:left;">
										<?php $media = round(($avg/$countavg),2); 
										if ($media == 0) {
											$media = "";
										}
										if ($girone[$c] == "ANDATA") {
											echo round($media,2);
											$armedia[$player->id] = round($media,2);
										} else {
											$divisore = 0;
                                                                                        $media_andata = $armedia[$player->id];
                                                                                        $media_ritorno = round($media,2);
											if ($media_andata > 0) {
												$divisore++;
											}
                                                                                        if ($media_ritorno > 0) {
                                                                                                $divisore++;
                                                                                        }
											$media_andata = $armedia[$player->id];
											$media_ritorno = round($media,2);
											$media_totale = ($media_andata + $media_ritorno)/$divisore;
											echo round($media_totale,2);
										}
										?>
										</td>
                                                                        </tr>
										<?php
										}
									     //}
									?>
								</table></figure><br><br>
							<?php } ?>
</div>
</div>
</div>
</div>
</div>

<?php get_footer(); ?>