<?php
require_once("admin/inc/protecao-final.php");

/////////////////////////////////////////////////
////////// Idioma //////////
/////////////////////////////////////////////////

$lang[ 'lang_info_camera_studio_tab_titulo' ] = 'C&acirc;mera Studio' ;
$lang[ 'lang_info_camera_studio_aba_instalar' ] = 'Instalar' ;
$lang[ 'lang_info_camera_studio_instalar' ] = 'Instalar C&acirc;mera Studio' ;
$lang[ 'lang_info_camera_studio_aba_dados_conexao' ] = 'Dados Conex&atilde;o' ;
$lang[ 'lang_info_camera_studio_info' ] = 'Para transmitir sua c&acirc;mera voc&ecirc; deve usar o Adobe FMLE, OBS ou VMIX com os dados abaxo.' ;
$lang[ 'lang_info_camera_studio_servidor' ] = 'Servidor' ;
$lang[ 'lang_info_camera_studio_usuario' ] = 'Usu&aacute;rio' ;
$lang[ 'lang_info_camera_studio_senha' ] = 'Senha' ;
$lang[ 'lang_info_camera_studio_ajuda' ] = 'Ajuda' ;
$lang[ 'lang_info_camera_studio_profile_fmle_info' ] = 'Download do profile pr&eacute;-configurado para usar no Adobe Flash Media Live Encoder' ;
$lang[ 'lang_info_camera_studio_sincronizar' ] = '[Resolver Problemas]' ;
$lang[ 'lang_info_camera_studio_sincronizar_info' ] = '(use esta op&ccedil;&atilde;o para resolver poss&iacute;veis problemas com a transmiss&atilde;o)' ;
$lang[ 'lang_info_camera_studio_aba_status' ] = 'Status' ;
$lang[ 'lang_info_camera_studio_espectadores' ] = 'Total Espectadores' ;
$lang[ 'lang_info_camera_studio_aba_gerar_player' ] = 'Criar Player' ;
$lang[ 'lang_info_camera_studio_player_largura' ] = 'Largura' ;
$lang[ 'lang_info_camera_studio_player_altura' ] = 'Altura' ;
$lang[ 'lang_info_camera_studio_player_aspectratio' ] = 'Aspectratio' ;
$lang[ 'lang_info_camera_studio_player_autoplay' ] = 'AutoPlay' ;
$lang[ 'lang_info_camera_studio_player_responsivo' ] = 'Responsivo' ;
$lang[ 'lang_info_camera_studio_player_gerar' ] = 'Criar C&oacute;digo HTML' ;
$lang[ 'lang_info_camera_studio_aba_assistir' ] = 'Assistir' ;

$lang[ 'lang_info_camera_studio_resultado_ok' ] = 'C&acirc;mera Studio instalada com sucesso!' ;
$lang[ 'lang_info_camera_studio_resultado_sincronizar_ok' ] = 'C&acirc;mera Studio sincronizado com sucesso, verifique se problema foi resolvido.' ;


$total_avisos_ativos = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM avisos WHERE area = 'streaming'"));
$checar_status_aviso = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM avisos_desativados WHERE area = 'streaming' AND codigo_usuario = '".$dados_stm["porta"]."'"));
$total_avisos_exibir = ($total_avisos_ativos > $checar_status_aviso) ? $total_avisos_ativos-$checar_status_aviso : 0;

$dados_servidor_camera_studio = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM servidores where codigo = '".$dados_stm["codigo_servidor_camera_studio_atual"]."'"));

if($dados_servidor_camera_studio["nome_principal"]) {
$servidor = code_decode($dados_servidor_camera_studio["nome_principal"].".".$dados_config["dominio_padrao"],"E");
} else {
$servidor = code_decode($dados_servidor_camera_studio["nome"].".".$dados_config["dominio_padrao"],"E");
}

$url_player = (!empty($dados_revenda["dominio_padrao"])) ? "player.".$dados_revenda["dominio_padrao"]."" : "player.".$dados_config["dominio_padrao"]."";

if(query_string('1') == "instalar") {

$dados_servidor_camera_studio = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM servidores where codigo = '".$dados_config["codigo_servidor_camera_studio_atual"]."'"));

mysqli_query($conexao,"Update streamings set codigo_servidor_camera_studio_atual = '".$dados_config["codigo_servidor_camera_studio_atual"]."', camera_studio_instalado = 'sim' where codigo = '".$dados_stm["codigo"]."'");

// Instala o streaming de video para a porta

// Conexão SSH
$ssh = new SSH();
$ssh->conectar($dados_servidor_camera_studio["ip"],$dados_servidor_camera_studio["porta_ssh"]);
$ssh->autenticar("root",code_decode($dados_servidor_camera_studio["senha"],"D"));

// Ativa o streaming no Wowza
$ssh->executar("/usr/local/WowzaMediaServer/desativar ".$dados_stm["porta"]."");
$ssh->executar("/usr/local/WowzaMediaServer/ativar ".$dados_stm["porta"]." '".$dados_stm["senha"]."' 1024 100 live");

// Cria o sessão do status das ações executadas e redireciona.
$_SESSION["status_acao"] = '<div class="alert alert-success text-center" role="alert">'.$lang['lang_info_camera_studio_resultado_ok'].'</div>';

header("Location: /camera-studio");
exit();

}

if(query_string('1') == "sincronizar") {


// Instala o streaming de video para a porta
$dados_servidor_camera_studio = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM servidores where codigo = '".$dados_stm["codigo_servidor_camera_studio_atual"]."'"));

// Conexão SSH
$ssh = new SSH();
$ssh->conectar($dados_servidor_camera_studio["ip"],$dados_servidor_camera_studio["porta_ssh"]);
$ssh->autenticar("root",code_decode($dados_servidor_camera_studio["senha"],"D"));

// Sincroniza o streaming no Wowza
$ssh->executar("/usr/local/WowzaMediaServer/sincronizar ".$dados_stm["porta"]." '".$dados_stm["senha"]."' 1024 100 live");

// Cria o sessão do status das ações executadas e redireciona.
$_SESSION["status_acao"] = '<div class="alert alert-success text-center" role="alert">'.$lang['lang_info_camera_studio_resultado_sincronizar_ok'].'</div>';

header("Location: /camera-studio");
exit();

}

if(query_string('1') == "FMLE") {

$dados_servidor_camera_studio = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM servidores where codigo = '".$dados_stm["codigo_servidor_camera_studio_atual"]."'"));

$dominio = strtolower($dados_servidor_camera_studio["nome"]).".".$dados_config["dominio_padrao"];

header('Content-disposition: attachment; filename=profile_fmle_'.$dados_stm["porta"].'.xml');
header ("Content-Type:text/xml"); 
echo '<?xml version="1.0" encoding="UTF-8"?>
<flashmedialiveencoder_profile>
    <preset>
        <name>Custom</name>
        <description></description>
    </preset>
    <process>
        <video>
        <preserve_aspect></preserve_aspect>
        </video>
    </process>
  <capture>
        <video>
        <device></device>
        <crossbar_input>0</crossbar_input>
        <frame_rate>29.97</frame_rate>
        <size>
            <width></width>
            <height></height>
        </size>
        </video>
        <audio>
        <device></device>
        <crossbar_input>0</crossbar_input>
        <sample_rate>44100</sample_rate>
        <channels>2</channels>
        <input_volume>100</input_volume>
        </audio>
    </capture>
    <encode>
        <video>
        <format>H.264</format>
        <datarate>200;</datarate>
        <outputsize>320x240;</outputsize>
        <advanced>
            <profile>Baseline</profile>
            <level>3.1</level>
            <keyframe_frequency>5 Seconds</keyframe_frequency>
        </advanced>
        <autoadjust>
            <enable>false</enable>
            <maxbuffersize>1</maxbuffersize>
            <dropframes>
            <enable>false</enable>
            </dropframes>
            <degradequality>
            <enable>false</enable>
            <minvideobitrate></minvideobitrate>
            <preservepfq>false</preservepfq>
            </degradequality>
        </autoadjust>
        </video>
    <audio>
        <format>MP3</format>
        <datarate>96</datarate>
        </audio>
    </encode>
    <output>
        <rtmp>
        <url>rtmp://'.$dominio.':1935/'.$dados_stm["porta"].'</url>
        <backup_url></backup_url>
        <stream>'.$dados_stm["porta"].'</stream>
        </rtmp>
    </output>
    <preview>
        <video>
        <input>
            <zoom>100%</zoom>
        </input>
        <output>
            <zoom>100%</zoom>
        </output>
        </video>
        <audio></audio>
    </preview>
</flashmedialiveencoder_profile>';
header("Expires: 0");
exit();
}

// Função para verificar o status da transmissao
if(query_string('1') == "status") {
  
$dados_servidor_camera_studio = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM servidores where codigo = '".$dados_stm["codigo_servidor_camera_studio_atual"]."'"));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$dados_servidor_camera_studio["ip"].":55/stats");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_USERPWD, "admin:".code_decode($dados_servidor_camera_studio["senha"],"D").""); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Painel de Streaming 3.0.0');
ob_start();
$resultado = curl_exec($ch);
$data = ob_get_clean();
curl_close($ch);

$transmitindo = "nao";

$xml = @simplexml_load_string(utf8_encode($resultado));

$total_streamings = @count($xml->VHost->Application);

if($total_streamings > 0) {

for($i=0;$i<$total_streamings;$i++){

if($xml->VHost->Application[$i]->Name == $dados_stm["porta"]) {

$total_streamings_clients = $xml->VHost->Application[$i]->ConnectionsTotal;

if($total_streamings_clients > 0) {

for($ii=0;$ii<$total_streamings_clients;$ii++){

$user_agent = $xml->VHost->Application[$i]->ApplicationInstance->Client[$ii]->FlashVersion;

if(preg_match("/(Wirecast|Wirecast|vmix|Vmix|FMLE)/i", $user_agent)) {
$transmitindo = "sim";
break;
}
}
}
break;
}
}
}
  
if($transmitindo == "sim") {
echo "<font color=\"#009900\"><strong>".$lang['lang_info_status_transmitindo']."</strong></font>";
exit();
}
  
echo "<font color=\"#009900\"><strong>".$lang['lang_info_status_ligado']."</strong></font>";
  
exit();
  
}

// Função para checar quantidade de espectadores
if(query_string('1') == "espectadores_conectados") {
  
$dados_servidor_camera_studio = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM servidores where codigo = '".$dados_stm["codigo_servidor_camera_studio_atual"]."'"));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$dados_servidor_camera_studio["ip"].":55/stats");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_USERPWD, "admin:".code_decode($dados_servidor_camera_studio["senha"],"D").""); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Painel de Streaming 3.0.0');
ob_start();
$resultado = curl_exec($ch);
$data = ob_get_clean();
curl_close($ch);

$xml = @simplexml_load_string(utf8_encode($resultado));

$total_streamings = @count($xml->VHost->Application);

if($total_streamings > 0) {

for($i=0;$i<$total_streamings;$i++){

if($xml->VHost->Application[$i]->Name == $dados_stm["porta"]) {

echo ($xml->VHost->Application[$i]->ConnectionsTotal > 0) ? $xml->VHost->Application[$i]->ConnectionsTotal : 0;
break;
}
}
}
exit(); 
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>Streaming <?php echo $dados_stm["porta"]; ?></title>
  <link rel="stylesheet" href="/inc/materialdesignicons.min.css">
  <link rel="stylesheet" href="/inc/font-awesome.min.css">
  <link rel="stylesheet" href="/inc/vendor.bundle.base.css">
  <link rel="stylesheet" href="/inc/vendor.bundle.addons.css">
  <link rel="stylesheet" href="/inc/theme.css">
  <link rel="shortcut icon" href="/img/favicon.ico">
  <script type="text/javascript" src="/inc/ajax-streaming.js"></script>
  <script type="text/javascript" src="/inc/javascript.js"></script>
</head>

<body>
  <div class="container-scroller">
      <nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
      <div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-center">
        <?php if($dados_revenda["url_logo"]) { ?>
        <a class="navbar-brand brand-logo" href="/dashboard"><img id="logo" src="<?php echo $dados_revenda["url_logo"]; ?>" title="Painel" height="60" border="0"></a>
        <?php } else { ?>
        <a class="navbar-brand brand-logo" href="/dashboard"><span>Painel Streaming</span></a>
        <?php } ?>
        <a class="navbar-brand brand-logo-mini" href="/dashboard"><img src="/img/icones/img-icone-logo.png" title="Painel" width="32" height="32" border="0"></a>
      </div>
      <div class="navbar-menu-wrapper d-flex align-items-center justify-content-end justify-content-lg-start">
        <button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
          <span class="mdi mdi-menu text-icones"></span>
        </button>
        <ul class="navbar-nav navbar-nav-right">
          <li class="nav-item nav-profile dropdown show">
            <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" id="profileDropdown" aria-expanded="true">
              <i class="fa fa-power-off f-18 text-icones" data-toggle="tooltip" data-placement="bottom" title="<?php echo $lang['lang_botao_titulo_ligar']; ?>/<?php echo $lang['lang_botao_titulo_desligar']; ?>"></i>
            </a>
            <div class="dropdown-menu dropdown-menu-right navbar-dropdown" aria-labelledby="profileDropdown">
              <a class="dropdown-item text-success" href="javascript:ligar_streaming('<?php echo $porta_code; ?>');"> <?php echo $lang['lang_botao_titulo_ligar']; ?> Streaming</a>
              <a class="dropdown-item text-danger" href="javascript:desligar_streaming('<?php echo $porta_code; ?>');"> <?php echo $lang['lang_botao_titulo_desligar']; ?> Streaming</a>
              <?php if($dados_stm["autodj"] == "sim") { ?>
              <div class="dropdown-divider"></div>              
              <a class="dropdown-item text-success" href="javascript:carregar_opcoes_ligar_autodj('<?php echo $porta_code; ?>');"> <?php echo $lang['lang_botao_titulo_ligar']; ?> AutoDJ</a>
              <a class="dropdown-item text-danger" href="javascript:desligar_autodj('<?php echo $porta_code; ?>');"> <?php echo $lang['lang_botao_titulo_desligar']; ?> AutoDJ</a>
              <?php } ?>
            </div>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link count-indicator dropdown-toggle d-flex align-items-center justify-content-center" id="notificationDropdown" href="#" data-toggle="dropdown" aria-expanded="false">
              <i class="mdi mdi-bell f-22 text-icones" data-toggle="tooltip" data-placement="bottom" title="<?php echo $lang['lang_info_pagina_informacoes_tab_avisos']; ?>"></i>
              <?php if($total_avisos_exibir > 0) { ?><span class="count bg-success"><?php echo $total_avisos_exibir; ?></span><?php } ?>           
            </a>
            <div class="dropdown-menu dropdown-menu-right navbar-dropdown preview-list" aria-labelledby="notificationDropdown">
              <a class="dropdown-item">
                <p class="mb-0 font-weight-normal float-left"><?php echo $lang['lang_info_pagina_informacoes_tab_avisos']; ?></p>
              </a>
              <div class="dropdown-divider"></div>
              <?php carregar_avisos_streaming($conexao,$dados_stm["porta"],$dados_servidor["codigo"]); ?>
            </div>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/sair"><i class="mdi mdi-logout f-22 text-icones" data-toggle="tooltip" data-placement="bottom" title="Sair/logout"></i></a>
          </li>
          <li>
            <button type="button" class="btn btn-info" id="status-streaming" onClick="status_streaming('<?php echo $porta_code; ?>');" style="margin: 10px;min-width: 150px; min-height: 40px"><i class="fa fa-refresh"></i></button>
          </li>
        </ul>
        <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
          <span class="mdi mdi-menu text-icones"></span>
        </button>
      </div>
    </nav>

    <!-- modal -->
      <div class="modal fade" id="avisos" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title"><?php echo $lang['lang_info_pagina_informacoes_tab_avisos']; ?></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body" id="avisos-conteudo"><img src="/img/ajax-loader.gif" align="center" /></div>
            </div>
        </div>
      </div>
                
      <div class="modal fade" id="playlists-autodj" tabindex="-1" role="dialog" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">AutoDJ</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body text-center" id="playlists-autodj-conteudo" style="text-align: center;"><img src="/img/ajax-loader.gif" /></div>
            </div>
          </div>
      </div>
                
      <div class="modal fade" id="log-sistema" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-body" id="log-sistema-conteudo" style="text-align:center"><img src="/img/ajax-loader.gif" /></div>
            </div>
        </div>
      </div>
      
    <div class="container-fluid page-body-wrapper">      
    <?php require_once("menu.php"); ?>
      <div class="main-panel">
        <div class="content-wrapper">
          <div id="local-status-acoes"><?php echo $_SESSION['status_acao'];unset($_SESSION['status_acao']); ?></div>
          <div class="row">            

            <?php if($dados_stm["camera_studio"] == 'sim' && $dados_stm["camera_studio_instalado"] == 'nao') { ?>
          <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo $lang['lang_info_camera_studio_aba_instalar']; ?></header>
                  </div>
                <div class="card-body">
                    <button type="button" class="btn btn-info" onClick="window.location = '/camera-studio/instalar';"><?php echo $lang['lang_info_camera_studio_instalar']; ?></button>
                </div>
              </div>
            </div>          
            <?php } ?>
      <?php if($dados_stm["camera_studio"] == 'sim' && $dados_stm["camera_studio_instalado"] == 'sim') { ?>
            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo $lang['lang_info_camera_studio_aba_dados_conexao']; ?></header>
                  </div>
                <div class="card-body">
            <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td width="220" height="30" align="center" class="texto_padrao_destaque" style="border-bottom:#CCCCCC 1px solid;"><?php echo $lang['lang_info_camera_studio_servidor']; ?></td>
                <td width="220" align="center" class="texto_padrao_destaque" style="border-bottom:#CCCCCC 1px solid;">Stream/Chave</td>
                <td width="250" align="center" class="texto_padrao_destaque" style="border-bottom:#CCCCCC 1px solid;">Bitrate</td>
              </tr>
              <tr>
                <td height="45" align="center" class="texto_padrao_pequeno">rtmp://<?php echo strtolower($dados_servidor_camera_studio["nome"]); ?>.<?php echo $dados_config["dominio_padrao"]; ?>:1935/<?php echo $dados_stm["porta"]; ?></td>
                <td height="45" align="center" class="texto_padrao_pequeno"><?php echo $dados_stm["porta"]; ?></td>
                <td height="45" align="center" class="texto_padrao_pequeno">1024 Kbps (video + audio)</td>
              </tr>
              <tr>
                <td height="30" align="center" class="texto_padrao_destaque" style="border-bottom:#CCCCCC 1px solid;"><?php echo $lang['lang_info_camera_studio_usuario']; ?></td>
                <td align="center" class="texto_padrao_destaque" style="border-bottom:#CCCCCC 1px solid;"><?php echo $lang['lang_info_camera_studio_senha']; ?></td>
                <td align="center" class="texto_padrao_destaque" style="border-bottom:#CCCCCC 1px solid;"><?php echo $lang['lang_info_camera_studio_ajuda']; ?></td>
              </tr>
              <tr>
                <td height="45" align="center"><?php echo $dados_stm["porta"]; ?></td>
                <td height="45" align="center"><?php echo $dados_stm["senha"]; ?></td>
                <td height="45" align="center"><a href="http://download.macromedia.com/pub/flashmediaserver/flashmedialiveencoder/installer/flashmedialiveencoder_3.2_wwe_signed.msi">[Download Encoder]</a>&nbsp;<a href="/camera-studio/FMLE">[Download Profile FMLE]</a><br /><a href="/camera-studio/sincronizar"><?php echo $lang['lang_info_camera_studio_sincronizar']; ?></a></td>
              </tr>
            </table>
                </div>
              </div>
            </div>

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header>Status</header>
                  </div>
                <div class="card-body">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td width="50%" height="30" align="center" class="texto_padrao_destaque" style="border-bottom:#CCCCCC 1px solid;">Status</td>
                <td width="50%" align="center" class="texto_padrao_destaque" style="border-bottom:#CCCCCC 1px solid;"><?php echo $lang['lang_info_camera_studio_espectadores']; ?></td>
                </tr>
              <tr>
                <td height="45" align="center" class="texto_padrao_pequeno"><div id="status"><img src="/img/spinner.gif" /></div></td>
                <td height="45" align="center" class="texto_padrao_pequeno"><div id="espectadores"><img src="/img/spinner.gif" /></div></td>
                </tr>
            </table>
                </div>
              </div>
            </div>

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo $lang['lang_info_camera_studio_aba_gerar_player']; ?></header>
                  </div>
                <div class="card-body">
                    <form action="/camera-studio" method="post" name="player">
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                      <tr>
                        <td width="150" height="50" align="left" class="texto_padrao_destaque" style="padding-left:5px;"><?php echo $lang['lang_info_camera_studio_player_altura']; ?></td>
                        <td align="left"><input type="number" class="form-control" name="largura" style="width:100%" value="640" /></td>
                      </tr>
                      <tr>
                        <td height="50" align="left" class="texto_padrao_destaque" style="padding-left:5px;"><?php echo $lang['lang_info_camera_studio_player_largura']; ?></td>
                        <td align="left"><input type="number" class="form-control" name="altura" style="width:100%" value="480" /></td>
                      </tr>
                      <tr>
                        <td height="50" align="left" class="texto_padrao_destaque" style="padding-left:5px;"><?php echo $lang['lang_info_camera_studio_player_aspectratio']; ?></td>
                        <td align="left"><select  class="form-control" name="aspectratio" style="width:100%;">
              <option value="16:9" selected="selected">Wide Screen 16:9</option>
          <option value="4:3">Default 4:3</option>
            </select></td>
                      </tr>
                      <tr>
                        <td height="30" align="left" class="texto_padrao_destaque" style="padding-left:5px;"><?php echo $lang['lang_info_camera_studio_player_autoplay']; ?></td>
                        <td align="left">
                        <input name="autoplay" id="autoplay" type="checkbox" value="true" style="vertical-align:middle" /></td>
                      </tr>
                      <tr>
                        <td height="30" align="left" class="texto_padrao_destaque" style="padding-left:5px;"><?php echo $lang['lang_info_camera_studio_player_responsivo']; ?></td>
                        <td align="left">
                        <input name="responsivo" id="responsivo" type="checkbox" value="true" style="vertical-align:middle" /></td>
                      </tr>
                      <tr>
                        <td height="50" align="left" class="texto_padrao_destaque" style="padding-left:5px;">&nbsp;</td>
                        <td align="left"><button type="button" class="btn btn-info" onClick="document.player.submit();"><?php echo $lang['lang_info_camera_studio_player_gerar']; ?></button></td>
                      </tr>
                    </table>
            </form>
<?php if($_POST) { ?>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td align="center" class="texto_padrao_vermelho_destaque" style="padding:5px">
<?php
$largura = ($_POST["responsivo"] == "true") ? '100%' : $_POST["largura"]."px";
$altura = ($_POST["responsivo"] == "true") ? '100%' : $_POST["altura"]."px";
?>
<br /><textarea name="textarea" readonly="readonly" style="width:99%; height:50px;font-size:11px" onmouseover="this.select()"><iframe style="width:<?php echo $largura; ?>; height:<?php echo $altura; ?>;" src="https://<?php echo $url_player; ?>/camera-studio/<?php echo $dados_stm["porta"]; ?>/<?php echo $servidor; ?>/<?php echo $_POST["aspectratio"]; ?>/<?php echo $_POST["autoplay"]; ?>" scrolling="No" frameborder="0" allowfullscreen="allowfullscreen"></iframe></textarea>
            </td>
          </tr>
        </table>
<?php } ?>
                </div>
              </div>
            </div>

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo $lang['lang_info_camera_studio_aba_assistir']; ?></header>
                  </div>
                <div class="card-body">
                    <iframe style="width:100%; height:500px;" src="https://<?php echo $url_player; ?>/camera-studio/<?php echo $dados_stm["porta"]; ?>/<?php echo $servidor; ?>/16:9/false" scrolling="No" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
                </div>
              </div>
            </div>
<?php } ?>

          </div>
        </div>
      </div>      

    </div>
  </div>
  <script src="/inc/vendor.bundle.base.js"></script>
  <script src="/inc/vendor.bundle.addons.js"></script>
  <script src="/inc/theme.js"></script>
  <script>
  status_streaming('<?php echo $porta_code; ?>');
  setInterval("status_streaming('<?php echo $porta_code; ?>')",60000);
  status_transmissao();
  espectadores_conectados();
  setInterval("status_transmissao()",60000);
  setInterval("espectadores_conectados()",60000);
  // Função para checar status da transmissao
function status_transmissao() {

  document.getElementById( 'status' ).innerHTML = "<img src='/img/spinner.gif' />";
  
  var http = new Ajax();
  http.open("GET", "/camera-studio/status" , true);
  http.onreadystatechange = function() {
  
  if(http.readyState == 4) {
  
  resultado = http.responseText;

  document.getElementById("status").innerHTML = resultado;  
  }
  
  }
  http.send(null);
  delete http;
}

// Função para checar quantidade de espectadores
function espectadores_conectados() {

  document.getElementById( 'espectadores' ).innerHTML = "<img src='/img/spinner.gif' />";
  
  var http = new Ajax();
  http.open("GET", "/camera-studio/espectadores_conectados" , true);
  http.onreadystatechange = function() {
  
  if(http.readyState == 4) {
  
  resultado = http.responseText;

  document.getElementById("espectadores").innerHTML = resultado;  
  }
  
  }
  http.send(null);
  delete http;
}
  </script>
</body>
</html>