Via onderstaande functie haal ik de kalender en klassementen van volleybalcompetities op en voeg ik deze in op onze site.
Ik had echter graag gehad dat bij kalender
-> http://www.bravoc.be/index.php/kalender-heren-1 en bij klassement
-> http://www.bravoc.be/index.php/klassement-heren4
elke rij een andere achtergrondkleur krijgt.
Hoe moet ik dit doen?
<?php
include ('simple_html_dom.php');
function getGamesHeader(){
echo "<table class='responsive' id='wedstrijdkalender' cellspacing='1' style='display:table' align='left'>";
echo "<tr>";
echo "<th>Datum</th>";
echo "<th>Uur</th>";
echo "<th>Sporthal</th>";
echo "<th>Thuis</th>";
echo "<th>Uit</th>";
echo "<th>Uitslag</th>";
echo "</tr>";
}
function getGamesFooter(){
echo "</table>";
}
function getGameRow($eventStart,$venue,$homeTeam,$otherTeam,$uitslag){
echo "<tr>";
echo "<td>".date('d/m/Y', $eventStart -> getTimestamp())."</td>";
echo "<td>".date('H:i', $eventStart -> getTimestamp())."</td>";
echo "<td>".$venue."</td>";
echo "<td>".$homeTeam."</td>";
echo "<td>".$otherTeam."</td>";
echo "<td>".$uitslag."</td>";
echo "</tr>";
}
function addAVFGames($reeks, $officialTeamName, $clubTeamName, $urlUitslag, $officialReeksNameUitslag) {
getGamesHeader();
$url = 'http://www.volley-avf.be/competitie/kalendersClubReeksavf.php';;
// build data for request
$data_array = array('Stamnummer' => "AA-1887", 'Reeks' => $reeks);
$data = http_build_query($data_array);
// load html
$html = str_get_html(do_post_request($url, $data));
$tables = $html -> find('table');
// get specific game table
$table = $tables[count($tables) - 1];
$cells = $table -> find("td");
$i = 0;
//retreive game nrs
$officialGameNrs = array();
foreach ($cells as $cell) {
if ($i % 6 === 0 && $i > 5) {
array_push($officialGameNrs, $cell -> innertext);
}
$i++;
}
//retreive uitslagen by game nrs
$uitslagen = getAVFUitslag($urlUitslag, $officialReeksNameUitslag, $officialTeamName, $officialGameNrs);
$i = 0;
foreach ($cells as $cell) {
if ($i % 6 === 0 && $i > 5) {
$homeTeam = $cells[$i + 2] -> innertext;
if($homeTeam == $officialTeamName){
$homeTeam = $clubTeamName;
}
$otherTeam = $cells[$i + 3] -> innertext;
if($otherTeam == $officialTeamName){
$otherTeam = $clubTeamName;
}
//$gameTitle = buildGameTitle($officialTeamName, $homeTeam, $otherTeam, $clubTeamName);
//add AVF to game number (for filter by federation)
$officialGameNr = "AVF" . $cell -> innertext;
// get date data
$dateParts = explode("/", $cells[$i + 1] -> innertext);
$day = intval(str_replace(" ", "", trim($dateParts[0])));
$month = intval($dateParts[1]);
$dateParts2 = explode("<br>", $dateParts[2]);
$dateParts3 = explode(":", $dateParts2[1]);
$hour = intval($dateParts3[0]);
$minute = intval($dateParts3[1]);
$year = intval($dateParts2[0]);
// build start and end datetime
$eventStart = new DateTime();
$eventStart -> setTimestamp(mktime($hour, $minute, 0, $month, $day, $year));
$eventEnd = new DateTime();
$eventEnd -> setTimestamp(mktime($hour + 2, $minute, 0, $month, $day, $year));
// get place of game
$venue = $cells[$i + 5] -> innertext;
// build gameContent text
//$gameContent = buildGameContent($homeTeam, $otherTeam, $eventStart, $venue, $clubTeamName, $officialTeamName, null, false);
// set score blanco
$uitslag = " - ";
// check if game has score, set score if true
foreach ($uitslagen as $possibleUitslag) {
if (substr($possibleUitslag, 0, strpos($possibleUitslag, '=')) == $cell -> innertext) {
$uitslag = substr($possibleUitslag, strpos($possibleUitslag, '=') + 1);
}
}
getGameRow($eventStart,$venue,$homeTeam,$otherTeam,$uitslag);
}
$i++;
}
getGamesFooter();
}
function getAVFUitslag($url, $reeks, $officialTeamName, $gameNrs) {
$xml = simplexml_load_file($url);
$uitslagen = array();
foreach ($xml->channel->item->description as $description) {
$games = explode("<br>", $description);
foreach ($games as $game) {
$gameParts = explode(" ", $game);
if (in_array($gameParts[0], $gameNrs)) {
array_push($uitslagen, str_replace(" ", "", $gameParts[0] . "=" . str_replace("/", "-", substr($game, strpos($game, "/") - 2, 5))));
}
}
}
return $uitslagen;
}
function addGewestGames($url, $team, $officialTeamName, $clubTeamName) {
getGamesHeader();
// build data for request
$data_array = array('ploegnr' => $team);
$data = http_build_query($data_array);
// load html
$html = str_get_html(do_post_request($url, $data));
foreach ($html->find('table') as $element) {
// get specific game table
if ($element -> id == 'sa-table') {
$isFirst = true;
foreach ($element->find('tr') as $row) {
if ($isFirst) {
$isFirst = false;
} else {
if (rowIsGameOfTeam($row, $officialTeamName)) {
$cells = $row -> find('td');
$venueSpan = $cells[2] -> find('span');
// get teams
$homeTeam = substr($cells[2] -> innertext, 0, strpos($cells[2] -> innertext, "<br>"));
if($homeTeam == $officialTeamName){
$homeTeam = $clubTeamName;
}
$otherTeam = $cells[3] -> innertext;
if($otherTeam == $officialTeamName){
$otherTeam = $clubTeamName;
}
//add GEW to game number (for filter by federation)
$officialGameNr = "GEW" . $cells[0] -> innertext;
// get date data
$hour = intval(substr($cells[1] -> innertext, 14, -3));
$minute = intval(substr($cells[1] -> innertext, 17, 19));
$day = intval(substr($cells[1] -> innertext, 0, 2));
$month = intval(substr($cells[1] -> innertext, 3, 5));
$year = intval(substr($cells[1] -> innertext, 6, 10));
// build start and end datetime
$eventStart = new DateTime();
$eventStart -> setTimestamp(mktime($hour, $minute, 0, $month, $day, $year));
$eventEnd = new DateTime();
$eventEnd -> setTimestamp(mktime($hour + 2, $minute, 0, $month, $day, $year));
// get place of game
$venue = $venueSpan[0] -> innertext;
// set score
$uitslag = $cells[4] -> innertext;
// add event
getGameRow($eventStart,$venue,$homeTeam,$otherTeam,$uitslag);
}
}
}
}
}
getGamesFooter();
}
function rowIsGameOfTeam($row, $teamName) {
if (strpos($row, $teamName) !== false) {
return true;
}
return false;
}
function addSportaKlassement($reeks, $officialName, $clubName){
$url = "http://lap.sporta.be/schrijftoegang/ranking_voan.php?s=47";
// build data for request
$data_array = array('afdeling' => $reeks);
$data = http_build_query($data_array);
// load html
$html = str_get_html(do_post_request($url, $data));
$tables = $html -> find('table');
// get specific game table
$tableToUse = null;
foreach ($tables as $table) {
$rows = $table -> find('tr');
if(count($rows) > 10){
$tableToUse = $table;
break;
}
}
if ($tableToUse) {
$rows = $tableToUse -> find("tr");
echo getTableHeader();
for($i = 5; $i < count($rows); $i++){
$cells = $rows[$i] -> find('th');
if($cells[1]->innertext==$officialName){
echo getTableRow(true, $cells[0]->innertext, $clubName, $cells[2]->innertext, $cells[3]->innertext + $cells[4]->innertext, $cells[5]->innertext, $cells[6]->innertext, $cells[7]->innertext + $cells[8]->innertext, $cells[9]->innertext, $cells[10]->innertext, $cells[12]->innertext);
}else {
echo getTableRow(false, $cells[0]->innertext, $cells[1]->innertext, $cells[2]->innertext, $cells[3]->innertext + $cells[4]->innertext, $cells[5]->innertext, $cells[6]->innertext, $cells[7]->innertext + $cells[8]->innertext, $cells[9]->innertext, $cells[10]->innertext, $cells[12]->innertext);
}
}
echo getTableFooter();
}
}
function addAvfKlassement($reeks, $officialName, $clubName){
$url = "http://www.volley-avf.be/competitie/klassementavf.php";
// build data for request
$data_array = array('Reeks' => $reeks);
$data = http_build_query($data_array);
// load html
$html = str_get_html(do_post_request($url, $data));
$tables = $html -> find('table');
// get specific game table
$tableToUse = null;
foreach ($tables as $table) {
$rows = $table -> find('tr');
$cells = $rows[0] -> find('td');
if(count($cells)>1){
if ($cells[1] -> innertext == "Nr") {
$tableToUse = $table;
break;
}
}
}
if ($tableToUse) {
$rows = $tableToUse -> find("tr");
echo getTableHeader();
for($i = 1; $i < count($rows); $i++){
$cells = $rows[$i] -> find('td');
if($cells[2]->innertext==$officialName){
echo getTableRow(true, $cells[1]->innertext, $clubName, $cells[3]->innertext, $cells[4]->innertext, $cells[5]->innertext, $cells[6]->innertext, $cells[7]->innertext, $cells[8]->innertext, $cells[9]->innertext, $cells[10]->innertext);
}else {
echo getTableRow(false, $cells[1]->innertext, $cells[2]->innertext, $cells[3]->innertext, $cells[4]->innertext, $cells[5]->innertext, $cells[6]->innertext, $cells[7]->innertext, $cells[8]->innertext, $cells[9]->innertext, $cells[10]->innertext);
}
}
echo getTableFooter();
}
}
function addVvbKlassement($reeks, $officialName, $clubName){
$xml = simplexml_load_file('http://www.volleyvvb.be/Competitie/rangschikking_xml.php';);
echo getTableHeader();
foreach ($xml->rangschikking as $rangschikking) {
if(($rangschikking->reeks == $reeks) AND ($rangschikking->wedstrijdtype == "Hoofd")) {
if($rangschikking->ploegnaam == $officialName){
echo getTableRow(true, $rangschikking->volgorde,$clubName,$rangschikking->aantalGespeeldeWedstrijden,$rangschikking->aantalGewonnen30_31,$rangschikking->aantalGewonnen32,$rangschikking->aantalVerloren32,$rangschikking->aantalVerloren30_31,$rangschikking->aantalGewonnenSets,$rangschikking->aantalVerlorenSets,$rangschikking->puntentotaal);
} else {
echo getTableRow(false, $rangschikking->volgorde,$rangschikking->ploegnaam,$rangschikking->aantalGespeeldeWedstrijden,$rangschikking->aantalGewonnen30_31,$rangschikking->aantalGewonnen32,$rangschikking->aantalVerloren32,$rangschikking->aantalVerloren30_31,$rangschikking->aantalGewonnenSets,$rangschikking->aantalVerlorenSets,$rangschikking->puntentotaal);
}
}
}
echo getTableFooter();
}
function addGewestKlassement($url, $officialName, $clubName){
$html = str_get_html(do_post_request($url, null));
// get specific game table
foreach ($html->find('table') as $element) {
if ($element -> id == 'klassement') {
echo getTableHeader();
$rows = $element->find("tr");
for($i = 2; $i < count($rows); $i++){
$cells = $rows[$i]->find("td");
if($cells[1]->innertext==$officialName){
echo getTableRow(true, $cells[0]->innertext, $clubName, $cells[2]->innertext, $cells[3]->innertext, $cells[4]->innertext, $cells[5]->innertext, $cells[6]->innertext, $cells[7]->innertext, $cells[8]->innertext, $cells[11]->innertext);
}else {
echo getTableRow(false, $cells[0]->innertext, $cells[1]->innertext, $cells[2]->innertext, $cells[3]->innertext, $cells[4]->innertext, $cells[5]->innertext, $cells[6]->innertext, $cells[7]->innertext, $cells[8]->innertext, $cells[11]->innertext);
}
}
echo getTableFooter();
}
}
}
function do_post_request($url, $data, $optional_headers = null) {
$params = array('http' => array('method' => 'POST', 'content' => $data));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
function getTableHeader(){
return "<table id='klassement' cellspacing='0' style='display:table'>
<tr>
<th width='5%'>Nr</td>
<th width='33%'>Ploegnaam</th>
<th width='8%'>Gesp. wedstr. </th>
<th width='8%'>Gew. 3/0 of 3/1</th>
<th width='8%'>Gew. 3/2</th>
<th width='8%'>Verl. 3/2</th>
<th width='8%'>Verl. 3/0 of 3/1</th>
<th width='8%'>Gew. sets</th>
<th width='8%'>Verl. sets</th>
<th width='8%'>Punten-totaal</th>
</tr>";
}
function getTableRow($ownTeam, $nr, $name, $played, $game3_0, $game3_2, $game2_3, $game0_3, $gameWonSet, $gameLostSet, $points){
$rowContent = "<tr>";
//check if row is team of our club, yes is set special style
if($ownTeam){
$rowContent = "<tr style='font-weight:bold;'>";
}
//build row
$rowContent .= "<td>$nr</td><td>$name</td>";
$rowContent .= "<td align='middle'>$played</td>";
$rowContent .= "<td align='middle'>$game3_0</td>";
$rowContent .= "<td align='middle'>$game3_2</td>";
$rowContent .= "<td align='middle'>$game2_3</td>";
$rowContent .= "<td align='middle'>$game0_3</td>";
$rowContent .= "<td align='middle'>$gameWonSet</td>";
$rowContent .= "<td align='middle'>$gameLostSet</td>";
$rowContent .= "<td align='middle'>$points</td>";
$rowContent .= "</tr>";
return $rowContent;
}
function getTableFooter(){
return "</table>";
}
?>
1.029 views