<?php
ini_set('display_errors', 0);
require_once './Control/ControlMedia.php';
require_once './Util/formAjax/FormAjax.php';
extract($_POST);
//var_dump($_POST);
if (!isset($lang))
{
	$lang = 'pt';
} else 
{
	if ($lang == 'undefined')
	{
		$lang = 'pt';
	}
}
$controlMedia = new ControlMedia();
if ($acao == 'inserir')
{
        echo 'Novo Registro...';
        $pk = '';
	$galeria = new Galmedia();
        $galeria->setHabilitado(1);
} else
{
	$galeria = $controlMedia->pegarUmGalMedia($pk);
}
$galeria->lang = $lang;
$arquivoGrid = 'adm_galMediaGrid.php';
?>
<div class="widget" id="widget_accordion">
    <h3 class="handle">Galeria de Mídias</h3>
    <div class="accordion">
        <h4><a href="#">Geral</a></h4>
            <div>
            <form name="frm" id="frm" action="adm_galMediaCMD.php" method="post">
                <input id="hacao" name="acao" type="hidden" value="<?php echo $acao?>">
                <input id="lang" name="lang" type="hidden" value="<?php echo $lang?>">
                <input id="arqFrm" name="arqFrm" type="hidden" value="<?php echo end(explode("/", $_SERVER['PHP_SELF']))?>">
                    <fieldset>
                            <label>Galeria</label>
                            <?php echo Idiomas::ComboSelecionarIdiomaPainelControle($acao, $pk, $lang);?>
                            <section><label for="pk">ID</label>
                                <div><input  readonly="true" ty pe="text" id="pk" name="pk" value="<?php echo $galeria->getGalmediaid(); ?>" placeholder="Este campo é gerido de forma automática."></div>
                            </section>
                            <section><label for="txtTitulo">Nome</label>
                                <div><input type="text" id="txtNome" name="txtNome" required value="<?php echo $galeria->gNome(); ?>"></div>
                            </section>
                            <section><label for="txtTitulo">Descrição</label>
                                <div><input type="text" id="txtDescricao" name="txtDescricao" required value="<?php echo $galeria->gDescricao(); ?>"></div>
                            </section>
                            <section><label for="txtFoto">Imagem Principal<br><span>Não esqueça de salvar após o upload</span></label>
                                <div><input type="file" id="upFoto" name="upFoto"></div>
                                <?php
                                if ($galeria->getFoto()!= '')
                                echo '<p><img src="' . $galeria->getFoto() . '" alt="Pré-Visualização"/></p>';
                                ?>
                            </section>
                            <section><label for="cbHabilitado">Visível ao público:</label>
                                <div>					
                                    <select name="cbHabilitado" id="cbHabilitado">
                                        <optgroup label="Habilitado">
                                            <?php echo Utilidades::formSeletorBoleano('cbHabilitado',$galeria->getHabilitado())?>
                                        </optgroup>
                                    </select>
                                </div>
                            </section>
                            <section>
                                <div><button onclick="mostrarArquivo('<?php echo $arquivoGrid; ?>','#dados');" >Cancelar</button><button id="salvar" class="submit" name="submitbuttonname" value="submitbuttonvalue">Salvar</button></div>
                            </section>
                    </fieldset>
            </form>
        </div>
        <h4><a href="#">Mídias</a></h4>
        <div id="divMedia">
            <?php include 'adm_mediaGrid.php';?>
        </div>
    </div>
</div>
<?php
      FormAjax::javascriptTrocarIdioma('adm_galMediaForm.php');
      FormAjax::PrepararFormAjax('#frm');
?>
<script>
    $('.accordion').accordion({
				collapsible:true,
				autoHeight:false
		});
    $('#upFoto').wl_File();
</script>