Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'haevanhemmat.php';
- function tulostaSukutaulu($vh, $muokattava = false) {
- if ($vh == "") {
- return;
- }
- echo "<table class=\"sukutaulu";
- echo ($muokattava ? " muokattavasukutaulu" : "");
- echo "\" id=\"sukutaulu\"";
- echo ($muokattava ? " style=\"transform: scale(0.95);\"" : "");
- echo ">";
- $ekapolvi = haeVanhemmat($vh);
- $tokapolvi = $kolmaspolvi = null;
- $rotustr = "";
- for($a = 0; $a < 2; $a++) {
- // tulosta eka polvi
- if ($a == 0) {
- $rotustr = "";
- $tokapolvi = haeVanhemmat($ekapolvi['IsanVH']);
- $n = "i";
- echo "<tr>";
- echo "<td rowspan=\"4\" rel=\"" . $ekapolvi['Isa_VH'] . "\"><strong>". $n .".</strong> ";
- if($ekapolvi['IsanURL'] != "") {
- echo "<a href=\"" . $ekapolvi['IsanURL'] . "\">";
- }
- echo ($ekapolvi['IsanNimi'] != null ? $ekapolvi['IsanNimi'] : "tuntematon");
- if($ekapolvi['IsanURL'] != "") {
- echo "</a>";
- }
- echo "<br><em>";
- echo ($ekapolvi['IsanURL'] == "" ? "evm " : "");
- echo ($ekapolvi['IsanRotu'] != null ? html_entity_decode($ekapolvi['IsanRotu']) : "") . " " . ($ekapolvi['IsanVari'] != null ? html_entity_decode($ekapolvi['IsanVari']) : "") . " " . ($ekapolvi['IsanSaka'] != null ? html_entity_decode($ekapolvi['IsanSaka']) . "cm" : "");
- if ($ekapolvi['IsanMeriitit'] != "" && $ekapolvi['IsanVPt'] != "") {
- echo "<br>" . html_entity_decode($ekapolvi['IsanMeriitit']) . " <small style=\"display:inline-block\">✱ " . html_entity_decode($ekapolvi['IsanVPt']) . "</small>";
- } else if($ekapolvi['IsanMeriitit'] == null && $ekapolvi['IsanVPt'] != "") {
- echo "<br>✱ " . html_entity_decode($ekapolvi['IsanVPt']);
- } else if ($ekapolvi['IsanVPt'] == null && $ekapolvi['IsanMeriitit'] != "") {
- echo "<br>" . html_entity_decode($ekapolvi['IsanMeriitit']) . "";
- }
- echo "</em>";
- echo "</td>";
- } else {
- $rotustr = "";
- $tokapolvi = haeVanhemmat($ekapolvi['EmanVH']);
- $n = "e";
- echo "<tr>";
- echo "<td rowspan=\"4\" rel=\"" . $ekapolvi['Ema_VH'] . "\"><strong>". $n .".</strong> ";
- if($ekapolvi['EmanURL'] != "") {
- echo "<a href=\"" . $ekapolvi['EmanURL'] . "\">";
- }
- echo ($ekapolvi['EmanNimi'] != null ? $ekapolvi['EmanNimi'] : "tuntematon");
- if($ekapolvi['EmanURL'] != "") {
- echo "</a>";
- }
- echo "<br><em>";
- echo ($ekapolvi['EmanURL'] == "" ? "evm " : "");
- echo ($ekapolvi['EmanRotu'] != null ? html_entity_decode($ekapolvi['EmanRotu']) : "") . " " . ($ekapolvi['EmanVari'] != null ? html_entity_decode($ekapolvi['EmanVari']) : "") . " " . ($ekapolvi['EmanSaka'] != null ? html_entity_decode($ekapolvi['EmanSaka']) . "cm" : "");
- if ($ekapolvi['EmanMeriitit'] != "" && $ekapolvi['EmanVPt'] != "") {
- echo "<br>" . html_entity_decode($ekapolvi['EmanMeriitit']) . " <small style=\"display:inline-block\">✱ " . html_entity_decode($ekapolvi['EmanVPt']) . "</small>";
- }else if($ekapolvi['EmanMeriitit'] == null && $ekapolvi['EmanVPt'] != "") {
- echo "<br>✱ " . html_entity_decode($ekapolvi['EmanVPt']);
- } else if ($ekapolvi['EmanVPt'] == null && $ekapolvi['EmanMeriitit'] != "") {
- echo "<br>" . html_entity_decode($ekapolvi['EmanMeriitit']) . "";
- }
- echo "</em>";
- echo "</td>";
- }
- for ($b = 0; $b < 2; $b++ ) {
- // tulosta toinen polvi
- if ($b == 0) {
- $kolmaspolvi = haeVanhemmat($tokapolvi['IsanVH']);
- $rotustr .= $tokapolvi['IsanRotu'];
- $o = $n . "i";
- echo "<td rowspan=\"2\" rel=\"" . $tokapolvi['Isa_VH'] . "\"><strong>". $o .".</strong> ";
- if($tokapolvi['IsanURL'] != "") {
- echo "<a href=\"" . $tokapolvi['IsanURL'] . "\">";
- }
- echo ($tokapolvi['IsanNimi'] != null ? $tokapolvi['IsanNimi'] : "tuntematon");
- if($tokapolvi['IsanURL'] != "") {
- echo "</a>";
- }
- echo "<br><em>";
- echo ($tokapolvi['IsanURL'] == "" ? "evm " : "");
- echo ($tokapolvi['IsanRotu'] != null ? html_entity_decode($tokapolvi['IsanRotu']) : "") . " " . ($tokapolvi['IsanVari'] != null ? html_entity_decode($tokapolvi['IsanVari']) : "") . " " . ($tokapolvi['IsanSaka'] != null ? html_entity_decode($tokapolvi['IsanSaka']) . "cm" : "");
- if ($tokapolvi['IsanMeriitit'] != "" && $tokapolvi['IsanVPt'] != "") {
- echo "<br>" . html_entity_decode($tokapolvi['IsanMeriitit']) . " <small style=\"display:inline-block\">✱ " . html_entity_decode($tokapolvi['IsanVPt']) . "</small>";
- } else if($tokapolvi['IsanMeriitit'] == null && $tokapolvi['IsanVPt'] != "") {
- echo "<br>✱ " . html_entity_decode($tokapolvi['IsanVPt']);
- } else if ($tokapolvi['IsanVPt'] == null && $tokapolvi['IsanMeriitit'] != "") {
- echo "<br>" . html_entity_decode($tokapolvi['IsanMeriitit']) . "";
- }
- echo "</em>";
- echo "</td>";
- } else {
- $kolmaspolvi = haeVanhemmat($tokapolvi['EmanVH']);
- $rotustr .= $tokapolvi['EmanRotu'];
- $o = $n . "e";
- echo "<tr><td rowspan=\"2\" rel=\"" . $tokapolvi['Ema_VH'] . "\"><strong>". $o .".</strong> ";
- if($tokapolvi['EmanURL'] != "") {
- echo "<a href=\"" . $tokapolvi['EmanURL'] . "\">";
- }
- echo ($tokapolvi['EmanNimi'] != null ? $tokapolvi['EmanNimi'] : "tuntematon");
- if($tokapolvi['EmanURL'] != "") {
- echo "</a>";
- }
- echo "<br><em>";
- echo ($tokapolvi['EmanURL'] == "" ? "evm " : "");
- echo ($tokapolvi['EmanRotu'] != null ? html_entity_decode($tokapolvi['EmanRotu']) : "") . " " . ($tokapolvi['EmanVari'] != null ? html_entity_decode($tokapolvi['EmanVari']) : "") . " " . ($tokapolvi['EmanSaka'] != null ? html_entity_decode($tokapolvi['EmanSaka']) . "cm" : "");
- if ($tokapolvi['EmanMeriitit'] != "" && $tokapolvi['EmanVPt'] != "") {
- echo "<br>" . html_entity_decode($tokapolvi['EmanMeriitit']) . " <small style=\"display:inline-block\">✱ " . html_entity_decode($tokapolvi['EmanVPt']) . "</small>";
- } else if($tokapolvi['EmanMeriitit'] == null && $tokapolvi['EmanVPt'] != "") {
- echo "<br>✱ " . html_entity_decode($tokapolvi['EmanVPt']);
- } else if ($tokapolvi['EmanVPt'] == null && $tokapolvi['EmanMeriitit'] != "") {
- echo "<br>" . html_entity_decode($tokapolvi['EmanMeriitit']) . "";
- }
- echo "</em>";
- echo "</td>";
- }
- for ($c = 0; $c < 2; $c++) {
- // tulosta kolmas polvi
- if ($c == 0) {
- $rotustr .= $kolmaspolvi['IsanRotu'];
- $p = $o . "i";
- echo "<td rowspan=\"1\" rel=\"" . $kolmaspolvi['Isa_VH'] . "\"><strong>". $p .".</strong> ";
- if($kolmaspolvi['IsanURL'] != "") {
- echo "<a href=\"" . $kolmaspolvi['IsanURL'] . "\">";
- }
- echo ($kolmaspolvi['IsanNimi'] != null ? $kolmaspolvi['IsanNimi'] : "tuntematon");
- if($kolmaspolvi['IsanURL'] != "") {
- echo "</a>";
- }
- if(preg_match('/\%/', $rotustr) && $ekapolvi['Nayta3p'] == '1') {
- echo " <em>" . html_entity_decode($kolmaspolvi['IsanRotu']) . "</em>";
- }
- if ($kolmaspolvi['IsanMeriitit'] != "" && $kolmaspolvi['IsanVPt'] != "") {
- echo "<br><em>" . html_entity_decode($kolmaspolvi['IsanMeriitit']) . " <small style=\"display:inline-block\">✱ " . html_entity_decode($kolmaspolvi['IsanVPt']) . "</small></em>";
- }else if($kolmaspolvi['IsanMeriitit'] == null && $kolmaspolvi['IsanVPt'] != "") {
- echo "<br><em>✱ " . html_entity_decode($kolmaspolvi['IsanVPt']) . "</em>";
- } else if ($kolmaspolvi['IsanVPt'] == null && $kolmaspolvi['IsanMeriitit'] != "") {
- echo "<br><em>" . html_entity_decode($kolmaspolvi['IsanMeriitit']) . "</em>";
- }
- echo "</td>";
- } else {
- $rotustr .= $kolmaspolvi['IsanRotu'];
- $p = $o . "e";
- echo "<tr><td rowspan=\"1\" rel=\"" . $kolmaspolvi['Ema_VH'] . "\"><strong>". $p .".</strong> ";
- if($kolmaspolvi['EmanURL'] != "") {
- echo "<a href=\"" . $kolmaspolvi['EmanURL'] . "\">";
- }
- echo ($kolmaspolvi['EmanNimi'] != null ? $kolmaspolvi['EmanNimi'] : "tuntematon");
- if($kolmaspolvi['EmanURL'] != "") {
- echo "</a>";
- }
- if(preg_match('/\%/', $rotustr) && $ekapolvi['Nayta3p'] == '1') {
- echo " <em>" . html_entity_decode($kolmaspolvi['EmanRotu']) . "</em>";
- }
- if ($kolmaspolvi['EmanMeriitit'] != "" && $kolmaspolvi['EmanVPt'] != "") {
- echo "<br><em>" . html_entity_decode($kolmaspolvi['EmanMeriitit']) . " <small style=\"display:inline-block\">✱ " . html_entity_decode($kolmaspolvi['EmanVPt']) . "</small></em>";
- } else if($kolmaspolvi['EmanMeriitit'] == null && $kolmaspolvi['EmanVPt'] != "") {
- echo "<br><em>✱ " . html_entity_decode($kolmaspolvi['EmanVPt']) . "</em>";
- } else if ($kolmaspolvi['EmanVPt'] == null && $kolmaspolvi['EmanMeriitit'] != "") {
- echo "<br><em>" . html_entity_decode($kolmaspolvi['EmanMeriitit']) . "</em>";
- }
- echo "</td>";
- }
- echo "</tr>";
- }
- }
- }
- echo "</table>";
- }
- function tulostaMeriitit($vh) {
- if ($vh == "") {
- return;
- }
- $heppa = haeVanhemmat($vh);
- echo $heppa['Meriitit'];
- }
- function tulostaVarsapalkinnot($vh) {
- if ($vh == "") {
- return;
- }
- $heppa = haeVanhemmat($vh);
- echo $heppa['Varsapalkinnot'];
- }
- function tulostaJalkelaisenMeriitit($vh) {
- if ($vh == "") {
- return;
- }
- $heppa = haeVanhemmat($vh);
- if ($heppa['Meriitit'] != "" && $heppa['Varsapalkinnot'] != "") {
- echo "<em>" . html_entity_decode($heppa['Meriitit']) . " <small style=\"display:inline-block\">✱ " . html_entity_decode($heppa['Varsapalkinnot']) . "</small></em>";
- } else if($heppa['Meriitit'] == null && $heppa['Varsapalkinnot'] != "") {
- echo "<em>✱ " . html_entity_decode($heppa['Varsapalkinnot']) . "</em>";
- } else if ($heppa['Varsapalkinnot'] == null && $heppa['Meriitit'] != "") {
- echo "<em>" . html_entity_decode($heppa['Meriitit']) . "</em>";
- } else {
- echo "";
- }
- }
- function tulostaKaukaiset($vh, $muokattava = false) {
- if ($vh == "") {
- return;
- }
- require 'tk_kredentiaalit.php';
- try {
- $kaukaiset = $conn->prepare("WITH RECURSIVE Suku AS (
- SELECT *, 0 as lvl, 'A ' as kirjain FROM Hevonen WHERE VH = (?)
- UNION
- SELECT h.*, s.lvl + 1 as lvl,
- ( CASE
- WHEN h.VH = s.Isa_VH THEN CONCAT(TRIM(REPLACE(s.kirjain, 'A', '')), 'i')
- ELSE CONCAT(TRIM(REPLACE(s.kirjain, 'A', '')), 'e')
- END ) as kirjain
- FROM Hevonen as h, Suku as s
- WHERE h.VH = s.Isa_VH OR h.VH = s.Ema_VH
- )
- SELECT * FROM Suku WHERE URL IS NOT NULL AND lvl >= 4 ORDER BY CHAR_LENGTH(kirjain) ASC, kirjain DESC;");
- if($kaukaiset->execute([$vh])) {
- $sukulaiset = $kaukaiset->fetchAll();
- if(count($sukulaiset) < 1) {
- return;
- }
- $ie = "ö";
- $monespolvi = 0;
- foreach ($sukulaiset as $s) {
- if(substr($s['kirjain'], 0, 1 ) != $ie) {
- if($ie != "ö") {
- echo "</p>\n";
- }
- if($ie == "ö" || $monespolvi != $s['lvl']) {
- if($ie != "ö") {
- echo "</td></tr></table>\n";
- }
- echo "<h5>Sukuselvitys " . $s['lvl'] ."-polvi</h5>";
- echo "<table id=\"kisakalenteri\" style=\"width:100%\"><tr><td class=\"eka\"></td></tr>\n<tr><td style=\"position:relative\">";
- $monespolvi = $s['lvl'];
- }
- echo "<p>";
- $ie = mb_substr($s['kirjain'], 0, 1);
- }
- echo $muokattava ? "<button class=\"kaukaisenmuokkaus\" rel=\"". $vh . "\" data-heppa=\"". $s['VH'] . "\">Muokkaa</button> " : "";
- echo $s['kirjain'] . ". ";
- echo (!empty($s['URL']) ? "<a href=\"" . $s['URL'] . "\">" : "");
- echo (!empty($s['Nimi']) ? $s['Nimi'] : "");
- echo (!empty($s['URL']) ? "</a>" : "");
- if ($s['Meriitit'] != "" && $s['Varsapalkinnot'] != "") {
- echo " – " . html_entity_decode($s['Meriitit']) . " <small style=\"display:inline-block\">✱ " . html_entity_decode($s['Varsapalkinnot']) . "</small>";
- } else if($s['Meriitit'] == null && $s['Varsapalkinnot'] != "") {
- echo " – ✱ " . html_entity_decode($s['Varsapalkinnot']);
- } else if ($s['Varsapalkinnot'] == null && $s['Meriitit'] != "") {
- echo " – " . html_entity_decode($s['Meriitit']);
- }
- echo "<br>\n";
- }
- echo $muokattava ? "<br><button class=\"kaukaisenlisays\" rel=\"". $vh . "\">Lisää kaukainen sukulainen</button>" : "";
- echo "</p>\n</td></tr></table>\n";
- } else {
- echo "Kaukaisten sukulaisten haku epäonnistui";
- }
- } catch(PDOException $e) {
- echo $e->getMessage();
- }
- }
- function fetchApiData($url) {
- $ch = curl_init();
- // Asetetaan cURL-asetukset
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 5); // Asetetaan kokonaisaikakatkaisu 5 sekunniksi
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // Asetetaan yhdistämisen aikakatkaisu 5 sekunniksi
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Seurataan uudelleenohjauksia
- curl_setopt($ch, CURLOPT_FAILONERROR, true); // Palauttaa virheen HTTP-koodilla 4xx tai 5xx
- curl_setopt($ch, CURLOPT_NOSIGNAL, 1); // Lisätty cURL-signaalien estämiseksi aikakatkaisun vuoksi
- $output = curl_exec($ch);
- // Tarkistetaan, tapahtuiko virhe
- if (curl_errno($ch)) {
- $error_message = curl_error($ch);
- curl_close($ch);
- return ['error' => 1, 'error_message' => $error_message];
- }
- // Tarkistetaan, jos palautusarvo on false
- if ($output === false) {
- $error_message = curl_error($ch);
- curl_close($ch);
- return ['error' => 1, 'error_message' => $error_message];
- }
- curl_close($ch);
- return json_decode($output, true);
- }
- function tulostaPorrastetut($vh, $jaokset) {
- $url = 'http://virtuaalihevoset.net/rajapinta/porrastetut/'.$vh;
- $obj = fetchApiData($url);
- if($vh == "" || $jaokset == "" || empty($jaokset)) {
- return;
- }
- if(isset($obj['error']) && $obj['error'] == 0){
- $data = $obj['porrastetut'];
- $info = $data['info'];
- $hevonen = $data['hevonen'];
- if($hevonen['error'] == 1){
- echo $hevonen['error_message'];
- } else {
- foreach ($hevonen['tasot'] as $jaos=>$tasoinfo){
- $jaosnimi = $info['jaokset'][$jaos]['jaos_nimi'];
- $jaoslyhenne = $info['jaokset'][$jaos]['jaos_lyhenne'];
- $taso = $tasoinfo['taso'];
- $max_taso_per_ika = $hevonen['info']['max_taso_per_ika'];
- $max_taso_per_pisteet = $tasoinfo['max_taso_per_pisteet'];
- $max_taso_rajoitus = $tasoinfo['taso_rajoitus'];
- // Tulostusosio
- if(in_array($jaoslyhenne, $jaokset)) {
- echo "tasolla " . ($max_taso_per_pisteet > 10 ? $max_taso_per_pisteet : $taso) . "/" . $max_taso_rajoitus;
- }
- // tulostusosio päättyy
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment