<?php
error_reporting(-1); ini_set('display_errors', 'On'); 
error_reporting(E_ALL);
ini_set("display_errors", 1);
if($stmt = $mysqli -> prepare("SELECT username FROM Twitch WHERE uid = ?")){
	$stmt -> bind_param("i", $userid);
	$stmt -> execute();
	$stmt -> bind_result($TwitchUsername);
	$stmt -> fetch();
	$stmt -> close();
}
if(isset($TwitchUsername))
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://api.twitch.tv/kraken/users/".$TwitchUsername."/follows/channels"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $jsonreturn = json_decode(curl_exec($ch), true);
    curl_setopt($ch, CURLOPT_URL, "https://api.twitch.tv/kraken/users/".$TwitchUsername); 
    $userdata = json_decode(curl_exec($ch), true);
}
?>
<head>
    <style type="text/css">
        title {
            font-size: 200%;
        }
    </style>
</head>

<div class="col-lg-12">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>Twitch Integratie</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                    <i class="fa fa-wrench"></i>
                </a>
                <ul class="dropdown-menu dropdown-user">
                    <li><a href="twitch.php?i=configuration">Configure Twitch Account</a></li>
                </ul>
                <a class="close-link">
                    <i class="fa fa-times"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <label><?php 
            if(isset($TwitchUsername))
            {
                print("Ingelogd als: <br/> <br/> <br/> <img src=".$userdata["logo"]." width=\"100\" height=\"100\">".$userdata["display_name"]);
            }
            else
            {
                print("Nog geen twitchaccount toegevoegd");
            }
            ?> </label>
            <br />
            <br />
            <?php
            if(isset($TwitchUsername))
            {
                print("<label>Aan het volgen:</label>
                <br />
                <label>");
                for($x = 0; $x < count($jsonreturn["follows"]); $x++ )
                {
                    echo "<img src=\"".$jsonreturn["follows"][$x]["channel"]["logo"]."\" width=\"50\" heigth=\"50\">";
                    echo $jsonreturn["follows"][$x]["channel"]["display_name"]."<br />";
                }
            }
            else
            {
                print("<html> Voeg een account toe door op het <i class=\"fa fa-wrench\"></i> icoon rechtsboven te klikken. </html>");
            }
            ?></label>
        </div>
    </div>
</div>