File: //opt/plugins/atalantini/pages/classifica.inc.php
<style>
td {
font-family: inherit;
font-size: 15px;
font-weight: inherit;
line-height: 20px;
}
</style>
<?php
global $wpdb;
function getImmagine($squadra, $img1, $img2) {
$squadra = strtolower($squadra);
if (strpos($squadra, "atalanta") > -1) {
$squadra = "atalanta";
}
if ($squadra != "atalanta") {
return $img1;
} else {
return $img2;
}
}
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[] = "PORTIERE";
$ruoli[] = "DIFENSORE";
$ruoli[] = "CENTROCAMPISTA";
$ruoli[] = "ATTACCANTE";
$ruoli[] = "ALLENATORE";
?>
<div class="page-content">
<div class="row clearfix">
<div class="grid_12 alpha">
<div class="grid_12 omega posts">
<div class="post_day mbf clearfix">
<div class="title_bu">Classifica</div>
<br>
<?php for ($c = 0; $c < count($girone); $c++) {
echo "<h2>" . $girone[$c] . "</h2>";
?>
<table width="100%" cellspacing="3" cellpadding="3">
<tr>
<td width="50" align="center"><img width="60" src="/wp-content/themes/atalantini/squadre/logo_atalanta.gif"></td>
<?php
$sql = "select * from wp_plugin_atalantini_team where girone = '" . $girone[$c] . "';";
$teams = $wpdb->get_results($sql);
foreach ( $teams as $team ) {
?>
<td width="50" align="center"><img width="60" src="/wp-content/themes/atalantini/squadre/<?= getImmagine($team->sq1, $team->immagine1, $team->immagine2) ?>"></td>
<?php
}
?>
<td></td>
</tr>
<tr>
<td width="50" align="center"></td>
<?php
$sql = "select * from wp_plugin_atalantini_team where girone = '" . $girone[$c] . "';";
$teams = $wpdb->get_results($sql);
foreach ( $teams as $team ) {
?>
<td width="50" 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.id, numero, nominativo,count(vote) as vote, (select count(vote) from wp_plugin_votazioni where player_id = wp_plugin_atalantini_player.id) as totale, (select avg(vote) from wp_plugin_votazioni where player_id = wp_plugin_atalantini_player.id and vote is not null and vote != 's.v.') as maxtotale from wp_plugin_atalantini_player, wp_plugin_votazioni where vote is not null and player_id = wp_plugin_atalantini_player.id group by wp_plugin_atalantini_player.id, numero, nominativo order by totale desc, maxtotale desc;";
$players = $wpdb->get_results($sql);
foreach ( $players as $player ) {
$avg = 0;
$countavg = 0;
?>
<tr>
<td width="200" align="left"><?= $player->nominativo ?></td>
<?php
$sql = "select id,wp_plugin_atalantini_team.id as game , (select avg(vote) from wp_plugin_votazioni where game = wp_plugin_atalantini_team.id and player_id = " . $player->id . " and vote != 's.v.' and vote is not null) as voto, (select max(vote) from wp_plugin_votazioni where vote is not null and vote != 's.v.' and game = wp_plugin_atalantini_team.id) as maxvoto from wp_plugin_atalantini_team where 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++;
}
}
$current_player = $wpdb->get_var( "select player_id from wp_plugin_votazioni where vote = '" . $team->maxvoto . "' and game = " . $team->game . ";" );
?>
<td width="50" align="center" bgcolor="<?= getBackgroundVote($team->voto, $team->maxvoto, $ruolo, $player->id, $current_player); ?>">
<?
$voto = $team->voto;
if ($voto == "0") {
$voto = "s.v.";
}
echo round($voto,2);
?></td>
<?php
}
?>
<td style="margin-left:20px;"> <?= round(($avg/$countavg),2) ?></td>
</tr>
<?php
}
//}
?>
</table><br><br>
<?php } ?>
</div><!-- /post day -->
</div><!-- /grid11 -->
</div><!-- /grid12 -->
</div><!-- /row -->
</div><!-- /end page content -->