Kirsiina

tiikeri

Aug 2nd, 2024 (edited)
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.23 KB | None | 0 0
  1. <?php
  2. include 'haevanhemmat.php';
  3.  
  4. function tulostaSukutaulu($vh, $muokattava = false) {
  5.     if ($vh == "") {
  6.         return;
  7.     }
  8.  
  9.     echo "<table class=\"sukutaulu";
  10.     echo ($muokattava ? " muokattavasukutaulu" : "");
  11.     echo "\" id=\"sukutaulu\"";
  12.     echo ($muokattava ? " style=\"transform: scale(0.95);\"" : "");
  13.     echo ">";
  14.  
  15.     $ekapolvi = haeVanhemmat($vh);
  16.     $tokapolvi = $kolmaspolvi = null;
  17.  
  18.     $rotustr = "";
  19.  
  20.  
  21.     for($a = 0; $a < 2; $a++) {
  22.         // tulosta eka polvi
  23.         if ($a == 0) {
  24.             $rotustr = "";
  25.             $tokapolvi = haeVanhemmat($ekapolvi['IsanVH']);
  26.             $n = "i";
  27.             echo "<tr>";
  28.             echo "<td rowspan=\"4\" rel=\"" . $ekapolvi['Isa_VH'] . "\"><strong>". $n .".</strong> ";
  29.             if($ekapolvi['IsanURL'] != "") {
  30.                 echo "<a href=\"" . $ekapolvi['IsanURL'] . "\">";
  31.             }
  32.             echo ($ekapolvi['IsanNimi'] != null ? $ekapolvi['IsanNimi'] : "tuntematon");
  33.             if($ekapolvi['IsanURL'] != "") {
  34.                 echo "</a>";
  35.             }
  36.             echo "<br><em>";
  37.             echo ($ekapolvi['IsanURL'] == "" ? "evm " : "");
  38.             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" : "");
  39.  
  40.             if ($ekapolvi['IsanMeriitit'] != "" && $ekapolvi['IsanVPt'] != "") {
  41.                 echo "<br>" . html_entity_decode($ekapolvi['IsanMeriitit']) . " <small style=\"display:inline-block\">&#10033; " . html_entity_decode($ekapolvi['IsanVPt']) . "</small>";
  42.             } else if($ekapolvi['IsanMeriitit'] == null && $ekapolvi['IsanVPt'] != "") {
  43.                 echo "<br>&#10033; " . html_entity_decode($ekapolvi['IsanVPt']);
  44.             } else if ($ekapolvi['IsanVPt'] == null && $ekapolvi['IsanMeriitit'] != "") {
  45.                 echo "<br>" . html_entity_decode($ekapolvi['IsanMeriitit']) . "";
  46.             }
  47.             echo "</em>";
  48.             echo "</td>";
  49.         } else {
  50.             $rotustr = "";
  51.             $tokapolvi = haeVanhemmat($ekapolvi['EmanVH']);
  52.             $n = "e";
  53.             echo "<tr>";
  54.             echo "<td rowspan=\"4\" rel=\"" . $ekapolvi['Ema_VH'] . "\"><strong>". $n .".</strong> ";
  55.             if($ekapolvi['EmanURL'] != "") {
  56.                 echo "<a href=\"" . $ekapolvi['EmanURL'] . "\">";
  57.             }
  58.             echo ($ekapolvi['EmanNimi'] != null ? $ekapolvi['EmanNimi'] : "tuntematon");
  59.             if($ekapolvi['EmanURL'] != "") {
  60.                 echo "</a>";
  61.             }
  62.             echo "<br><em>";
  63.             echo ($ekapolvi['EmanURL'] == "" ? "evm " : "");
  64.             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" : "");
  65.  
  66.             if ($ekapolvi['EmanMeriitit'] != "" && $ekapolvi['EmanVPt'] != "") {
  67.                 echo "<br>" . html_entity_decode($ekapolvi['EmanMeriitit']) . " <small style=\"display:inline-block\">&#10033; " . html_entity_decode($ekapolvi['EmanVPt']) . "</small>";
  68.             }else if($ekapolvi['EmanMeriitit'] == null && $ekapolvi['EmanVPt'] != "") {
  69.                 echo "<br>&#10033; " . html_entity_decode($ekapolvi['EmanVPt']);
  70.             } else if ($ekapolvi['EmanVPt'] == null && $ekapolvi['EmanMeriitit'] != "") {
  71.                 echo "<br>" . html_entity_decode($ekapolvi['EmanMeriitit']) . "";
  72.             }
  73.             echo "</em>";
  74.             echo "</td>";
  75.         }
  76.  
  77.         for ($b = 0; $b < 2; $b++ ) {
  78.         // tulosta toinen polvi
  79.             if ($b == 0) {
  80.                 $kolmaspolvi = haeVanhemmat($tokapolvi['IsanVH']);
  81.                 $rotustr .= $tokapolvi['IsanRotu'];
  82.                 $o = $n . "i";
  83.                 echo "<td rowspan=\"2\" rel=\"" . $tokapolvi['Isa_VH'] . "\"><strong>". $o .".</strong> ";
  84.                 if($tokapolvi['IsanURL'] != "") {
  85.                     echo "<a href=\"" . $tokapolvi['IsanURL'] . "\">";
  86.                 }
  87.                 echo ($tokapolvi['IsanNimi'] != null ? $tokapolvi['IsanNimi'] : "tuntematon");
  88.                 if($tokapolvi['IsanURL'] != "") {
  89.                     echo "</a>";
  90.                 }
  91.                 echo "<br><em>";
  92.                 echo ($tokapolvi['IsanURL'] == "" ? "evm " : "");
  93.                 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" : "");
  94.  
  95.                 if ($tokapolvi['IsanMeriitit'] != "" && $tokapolvi['IsanVPt'] != "") {
  96.                     echo "<br>" . html_entity_decode($tokapolvi['IsanMeriitit']) . " <small style=\"display:inline-block\">&#10033; " . html_entity_decode($tokapolvi['IsanVPt']) . "</small>";
  97.                 } else if($tokapolvi['IsanMeriitit'] == null && $tokapolvi['IsanVPt'] != "") {
  98.                     echo "<br>&#10033; " . html_entity_decode($tokapolvi['IsanVPt']);
  99.                 } else if ($tokapolvi['IsanVPt'] == null && $tokapolvi['IsanMeriitit'] != "") {
  100.                     echo "<br>" . html_entity_decode($tokapolvi['IsanMeriitit']) . "";
  101.                 }
  102.                 echo "</em>";
  103.                 echo "</td>";
  104.             } else {
  105.                 $kolmaspolvi = haeVanhemmat($tokapolvi['EmanVH']);
  106.                 $rotustr .= $tokapolvi['EmanRotu'];
  107.                 $o = $n . "e";
  108.                 echo "<tr><td rowspan=\"2\" rel=\"" . $tokapolvi['Ema_VH'] . "\"><strong>". $o .".</strong> ";
  109.                 if($tokapolvi['EmanURL'] != "") {
  110.                     echo "<a href=\"" . $tokapolvi['EmanURL'] . "\">";
  111.                 }
  112.                 echo ($tokapolvi['EmanNimi'] != null ? $tokapolvi['EmanNimi'] : "tuntematon");
  113.                 if($tokapolvi['EmanURL'] != "") {
  114.                     echo "</a>";
  115.                 }
  116.                 echo "<br><em>";
  117.                 echo ($tokapolvi['EmanURL'] == "" ? "evm " : "");
  118.                 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" : "");
  119.  
  120.                 if ($tokapolvi['EmanMeriitit'] != "" && $tokapolvi['EmanVPt'] != "") {
  121.                     echo "<br>" . html_entity_decode($tokapolvi['EmanMeriitit']) . " <small style=\"display:inline-block\">&#10033; " . html_entity_decode($tokapolvi['EmanVPt']) . "</small>";
  122.                 } else if($tokapolvi['EmanMeriitit'] == null && $tokapolvi['EmanVPt'] != "") {
  123.                     echo "<br>&#10033; " . html_entity_decode($tokapolvi['EmanVPt']);
  124.                 } else if ($tokapolvi['EmanVPt'] == null && $tokapolvi['EmanMeriitit'] != "") {
  125.                     echo "<br>" . html_entity_decode($tokapolvi['EmanMeriitit']) . "";
  126.                 }
  127.                 echo "</em>";
  128.                 echo "</td>";
  129.             }
  130.  
  131.  
  132.             for ($c = 0; $c < 2; $c++) {
  133.             // tulosta kolmas polvi
  134.                 if ($c == 0) {
  135.                     $rotustr .= $kolmaspolvi['IsanRotu'];
  136.                     $p = $o . "i";
  137.                     echo "<td rowspan=\"1\" rel=\"" . $kolmaspolvi['Isa_VH'] . "\"><strong>". $p .".</strong> ";
  138.                     if($kolmaspolvi['IsanURL'] != "") {
  139.                         echo "<a href=\"" . $kolmaspolvi['IsanURL'] . "\">";
  140.                     }
  141.                     echo ($kolmaspolvi['IsanNimi'] != null ? $kolmaspolvi['IsanNimi'] : "tuntematon");
  142.                     if($kolmaspolvi['IsanURL'] != "") {
  143.                         echo "</a>";
  144.                     }
  145.                     if(preg_match('/\%/', $rotustr) && $ekapolvi['Nayta3p'] == '1') {
  146.                         echo " <em>" . html_entity_decode($kolmaspolvi['IsanRotu']) . "</em>";
  147.                     }
  148.                     if ($kolmaspolvi['IsanMeriitit'] != "" && $kolmaspolvi['IsanVPt'] != "") {
  149.                         echo "<br><em>" . html_entity_decode($kolmaspolvi['IsanMeriitit']) . " <small style=\"display:inline-block\">&#10033; " . html_entity_decode($kolmaspolvi['IsanVPt']) . "</small></em>";
  150.                     }else if($kolmaspolvi['IsanMeriitit'] == null && $kolmaspolvi['IsanVPt'] != "") {
  151.                         echo "<br><em>&#10033; " . html_entity_decode($kolmaspolvi['IsanVPt']) . "</em>";
  152.                     } else if ($kolmaspolvi['IsanVPt'] == null && $kolmaspolvi['IsanMeriitit'] != "") {
  153.                         echo "<br><em>" . html_entity_decode($kolmaspolvi['IsanMeriitit']) . "</em>";
  154.                     }
  155.                     echo "</td>";
  156.                 } else {
  157.                     $rotustr .= $kolmaspolvi['IsanRotu'];
  158.                     $p = $o . "e";
  159.                     echo "<tr><td rowspan=\"1\" rel=\"" . $kolmaspolvi['Ema_VH'] . "\"><strong>". $p .".</strong> ";
  160.                     if($kolmaspolvi['EmanURL'] != "") {
  161.                         echo "<a href=\"" . $kolmaspolvi['EmanURL'] . "\">";
  162.                     }
  163.                     echo ($kolmaspolvi['EmanNimi'] != null ? $kolmaspolvi['EmanNimi'] : "tuntematon");
  164.                     if($kolmaspolvi['EmanURL'] != "") {
  165.                         echo "</a>";
  166.                     }
  167.                     if(preg_match('/\%/', $rotustr) && $ekapolvi['Nayta3p'] == '1') {
  168.                         echo " <em>" . html_entity_decode($kolmaspolvi['EmanRotu']) . "</em>";
  169.                     }
  170.                     if ($kolmaspolvi['EmanMeriitit'] != "" && $kolmaspolvi['EmanVPt'] != "") {
  171.                         echo "<br><em>" . html_entity_decode($kolmaspolvi['EmanMeriitit']) . " <small style=\"display:inline-block\">&#10033; " . html_entity_decode($kolmaspolvi['EmanVPt']) . "</small></em>";
  172.                     } else if($kolmaspolvi['EmanMeriitit'] == null && $kolmaspolvi['EmanVPt'] != "") {
  173.                         echo "<br><em>&#10033; " . html_entity_decode($kolmaspolvi['EmanVPt']) . "</em>";
  174.                     } else if ($kolmaspolvi['EmanVPt'] == null && $kolmaspolvi['EmanMeriitit'] != "") {
  175.                         echo "<br><em>" . html_entity_decode($kolmaspolvi['EmanMeriitit']) . "</em>";
  176.                     }
  177.                     echo "</td>";
  178.                 }
  179.  
  180.                 echo "</tr>";
  181.             }
  182.         }
  183.  
  184.     }
  185.     echo "</table>";
  186. }
  187.  
  188. function tulostaMeriitit($vh) {
  189.     if ($vh == "") {
  190.         return;
  191.     }
  192.     $heppa = haeVanhemmat($vh);
  193.  
  194.     echo $heppa['Meriitit'];
  195. }
  196.  
  197. function tulostaVarsapalkinnot($vh) {
  198.     if ($vh == "") {
  199.         return;
  200.     }
  201.     $heppa = haeVanhemmat($vh);
  202.  
  203.     echo $heppa['Varsapalkinnot'];
  204. }
  205.  
  206. function tulostaJalkelaisenMeriitit($vh) {
  207.     if ($vh == "") {
  208.         return;
  209.     }
  210.  
  211.     $heppa = haeVanhemmat($vh);
  212.  
  213.  
  214.  
  215.     if ($heppa['Meriitit'] != "" && $heppa['Varsapalkinnot'] != "") {
  216.         echo "<em>" . html_entity_decode($heppa['Meriitit']) . " <small style=\"display:inline-block\">&#10033; " . html_entity_decode($heppa['Varsapalkinnot']) . "</small></em>";
  217.     } else if($heppa['Meriitit'] == null && $heppa['Varsapalkinnot'] != "") {
  218.         echo "<em>&#10033; " . html_entity_decode($heppa['Varsapalkinnot']) . "</em>";
  219.     } else if ($heppa['Varsapalkinnot'] == null && $heppa['Meriitit'] != "") {
  220.         echo "<em>" . html_entity_decode($heppa['Meriitit']) . "</em>";
  221.     } else {
  222.         echo "";
  223.     }
  224. }
  225.  
  226. function tulostaKaukaiset($vh, $muokattava = false) {
  227.     if ($vh == "") {
  228.         return;
  229.     }
  230.     require 'tk_kredentiaalit.php';
  231.     try {
  232.  
  233.         $kaukaiset = $conn->prepare("WITH RECURSIVE Suku AS (
  234.        SELECT *, 0 as lvl, 'A          ' as kirjain FROM Hevonen WHERE VH = (?)
  235.        UNION
  236.        SELECT h.*, s.lvl + 1 as lvl,
  237.        ( CASE
  238.             WHEN h.VH = s.Isa_VH THEN CONCAT(TRIM(REPLACE(s.kirjain, 'A', '')), 'i')
  239.             ELSE CONCAT(TRIM(REPLACE(s.kirjain, 'A', '')), 'e')
  240.        END ) as kirjain
  241.        FROM Hevonen as h, Suku as s
  242.        WHERE h.VH = s.Isa_VH OR h.VH = s.Ema_VH
  243.        )
  244.        SELECT * FROM Suku WHERE URL IS NOT NULL AND lvl >= 4 ORDER BY CHAR_LENGTH(kirjain) ASC, kirjain DESC;");
  245.         if($kaukaiset->execute([$vh])) {
  246.  
  247.             $sukulaiset = $kaukaiset->fetchAll();
  248.  
  249.             if(count($sukulaiset) < 1) {
  250.                 return;
  251.             }
  252.  
  253.             $ie = "ö";
  254.             $monespolvi = 0;
  255.  
  256.             foreach ($sukulaiset as $s) {
  257.                 if(substr($s['kirjain'], 0, 1 ) != $ie) {
  258.                     if($ie != "ö") {
  259.                         echo "</p>\n";
  260.                     }
  261.                     if($ie == "ö" || $monespolvi != $s['lvl']) {
  262.                         if($ie != "ö") {
  263.                             echo "</td></tr></table>\n";
  264.                         }
  265.                         echo "<h5>Sukuselvitys " . $s['lvl'] ."-polvi</h5>";
  266.                         echo "<table id=\"kisakalenteri\" style=\"width:100%\"><tr><td class=\"eka\"></td></tr>\n<tr><td style=\"position:relative\">";
  267.                         $monespolvi = $s['lvl'];
  268.                     }
  269.                     echo "<p>";
  270.                     $ie = mb_substr($s['kirjain'], 0, 1);
  271.                 }
  272.  
  273.                 echo $muokattava ? "<button class=\"kaukaisenmuokkaus\" rel=\"". $vh . "\"  data-heppa=\"". $s['VH'] . "\">Muokkaa</button>&nbsp;" : "";
  274.                 echo $s['kirjain'] . ". ";
  275.                 echo (!empty($s['URL']) ? "<a href=\"" . $s['URL'] . "\">" : "");
  276.                 echo (!empty($s['Nimi']) ? $s['Nimi'] : "");
  277.                 echo (!empty($s['URL']) ? "</a>" : "");
  278.                 if ($s['Meriitit'] != "" && $s['Varsapalkinnot'] != "") {
  279.                     echo " &ndash; " . html_entity_decode($s['Meriitit']) . " <small style=\"display:inline-block\">&#10033; " . html_entity_decode($s['Varsapalkinnot']) . "</small>";
  280.                 } else if($s['Meriitit'] == null && $s['Varsapalkinnot'] != "") {
  281.                     echo " &ndash; &#10033; " . html_entity_decode($s['Varsapalkinnot']);
  282.                 } else if ($s['Varsapalkinnot'] == null && $s['Meriitit'] != "") {
  283.                     echo " &ndash; " . html_entity_decode($s['Meriitit']);
  284.                 }
  285.                 echo "<br>\n";
  286.             }
  287.             echo $muokattava ? "<br><button class=\"kaukaisenlisays\" rel=\"". $vh . "\">Lisää kaukainen sukulainen</button>" : "";
  288.             echo "</p>\n</td></tr></table>\n";
  289.  
  290.         } else {
  291.             echo "Kaukaisten sukulaisten haku epäonnistui";
  292.         }
  293.  
  294.     } catch(PDOException $e) {
  295.         echo $e->getMessage();
  296.     }
  297. }
  298.  
  299. function fetchApiData($url) {
  300.     $ch = curl_init();
  301.  
  302.     // Asetetaan cURL-asetukset
  303.     curl_setopt($ch, CURLOPT_URL, $url);
  304.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  305.     curl_setopt($ch, CURLOPT_TIMEOUT, 5); // Asetetaan kokonaisaikakatkaisu 5 sekunniksi
  306.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // Asetetaan yhdistämisen aikakatkaisu 5 sekunniksi
  307.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Seurataan uudelleenohjauksia
  308.     curl_setopt($ch, CURLOPT_FAILONERROR, true); // Palauttaa virheen HTTP-koodilla 4xx tai 5xx
  309.     curl_setopt($ch, CURLOPT_NOSIGNAL, 1); // Lisätty cURL-signaalien estämiseksi aikakatkaisun vuoksi
  310.  
  311.     $output = curl_exec($ch);
  312.  
  313.     // Tarkistetaan, tapahtuiko virhe
  314.     if (curl_errno($ch)) {
  315.         $error_message = curl_error($ch);
  316.         curl_close($ch);
  317.         return ['error' => 1, 'error_message' => $error_message];
  318.     }
  319.  
  320.     // Tarkistetaan, jos palautusarvo on false
  321.     if ($output === false) {
  322.         $error_message = curl_error($ch);
  323.         curl_close($ch);
  324.         return ['error' => 1, 'error_message' => $error_message];
  325.     }
  326.  
  327.     curl_close($ch);
  328.  
  329.     return json_decode($output, true);
  330. }
  331.  
  332. function tulostaPorrastetut($vh, $jaokset) {
  333.     $url = 'http://virtuaalihevoset.net/rajapinta/porrastetut/'.$vh;
  334.     $obj = fetchApiData($url);
  335.  
  336.     if($vh == "" || $jaokset == "" || empty($jaokset)) {
  337.         return;
  338.     }
  339.  
  340.     if(isset($obj['error']) && $obj['error'] == 0){        
  341.         $data = $obj['porrastetut'];
  342.  
  343.         $info = $data['info'];
  344.         $hevonen = $data['hevonen'];
  345.  
  346.         if($hevonen['error'] == 1){
  347.             echo $hevonen['error_message'];
  348.         } else {
  349.             foreach ($hevonen['tasot'] as $jaos=>$tasoinfo){
  350.                 $jaosnimi = $info['jaokset'][$jaos]['jaos_nimi'];
  351.                 $jaoslyhenne = $info['jaokset'][$jaos]['jaos_lyhenne'];
  352.                 $taso = $tasoinfo['taso'];
  353.                 $max_taso_per_ika = $hevonen['info']['max_taso_per_ika'];
  354.                 $max_taso_per_pisteet = $tasoinfo['max_taso_per_pisteet'];
  355.                 $max_taso_rajoitus = $tasoinfo['taso_rajoitus'];
  356.  
  357.                 // Tulostusosio
  358.                 if(in_array($jaoslyhenne, $jaokset)) {
  359.                     echo "tasolla " . ($max_taso_per_pisteet > 10 ? $max_taso_per_pisteet : $taso) . "/" . $max_taso_rajoitus;
  360.                 }
  361.                 // tulostusosio päättyy
  362.  
  363.  
  364.             }
  365.         }
  366.  
  367.     }
  368.  
  369. }
  370.  
  371. ?>
Advertisement
Add Comment
Please, Sign In to add comment