<?php
require_once './Control/ControlMedia.php';
require_once './Util/formAjax/FormAjax.php';
extract($_POST);
if (!isset($lang))
{
	$lang = 'pt';
} else 
{
	if ($lang == 'undefined')
	{
		$lang = 'pt';
	}
}
$controlMedia = new ControlMedia();
if ($acao == 'inserir')
{
        $galeria = $controlMedia->pegarUmGalMedia($pk);
        echo 'Novo registro para galeria: <b>' . $galeria->gNome() . '</b>';
	$media = new Media();
        $media->setGalmedia($pk);
        $media->setHabilitado(1);
        $pk = '';
} else
{
	$media = $controlMedia->pegarUmMedia($pk);
}
$media->lang = $lang;
$arquivoGrid = 'adm_mediaGrid.php';
?>
<form name="frmMedia" id="frmMedia" action="adm_mediaCMD.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="galeriaid" name="galmediaid" type="hidden" value="<?php echo $media->getGalmedia()?>">
    <input id="arqFrm" name="arqFrm" type="hidden" value="<?php echo end(explode("/", $_SERVER['PHP_SELF']))?>">
	<fieldset>
		<label>Mídia</label>
                <?php echo Idiomas::ComboSelecionarIdiomaPainelControle($acao, $pk, $lang, 'fnIdiomaDivMedia');?>
		<section><label for="mediapk">ID</label>
                    <div><input  readonly="true" type="text" id="mediapk" name="mediapk" value="<?php echo $media->getMediaid(); ?>" placeholder="Este campo é gerido de forma automática."></div>
		</section>
                <section>
                    <label for="mediacbTipoMediaID">Tipo de mídia</label>
                    <div>					
                        <select name="mediacbTipoMediaID" id="mediacbTipoMidiaID">
                            <optgroup label="Tipo de Mídia">
                                <?php
       $tipoMedia = $controlMedia->pegarTodosTipomedia();
       Utilidades::formselectorOpcaoMarcada('0','Nenhum','null');
       while ($tipoMedia->fetch())
       {
       		Utilidades::formselectorOpcaoMarcada($tipoMedia->getTipomediaid(),$tipoMedia->gNome(),$media->getTipomediaid());
       }
      ?>
                            </optgroup>
                        </select>
                    </div>
		</section>
                <section><label for="mediatxtNome">Nome</label>
                    <div><input type="text" id="mediatxtNome" name="mediatxtNome" required value="<?php echo $media->gNome(); ?>"></div>
		</section>
                <section><label for="mediatxtDescricao">Descrição</label>
                    <div><input type="text" id="mediatxtDescricao" name="mediatxtDescricao" required value="<?php echo $media->gDescricao(); ?>"></div>
		</section>
                <section><label for="mediatxtValor">Valor</label>
                    <div><input type="text" id="mediatxtValor" name="mediatxtValor" required value="<?php echo htmlspecialchars($media->getValor()); ?>"></div>
		</section>
                <section><label for="mediacbHabilitado">Visível ao público:</label>
                    <div>					
                        <select name="mediacbHabilitado" id="mediacbHabilitado">
                            <optgroup label="Habilitado">
                                <?php echo Utilidades::formSeletorBoleano('mediacbHabilitado',$media->getHabilitado())?>
                            </optgroup>
                        </select>
                    </div>
		</section>
                <section>
                    <div><button onclick="mostrarArquivoDados('<?php echo $arquivoGrid; ?>','#divMedia','pk=<?php echo $media->getGalmedia();?>');" >Cancelar</button><button id="salvar" class="submit" name="submitbuttonname" value="submitbuttonvalue">Salvar</button></div>
		</section>
	</fieldset>
</form>
<?php
      FormAjax::javascriptTrocarIdioma('adm_mediaForm.php','#divMedia', 'fnIdiomaDivMedia');
      FormAjax::PrepararFormAjax('#frmMedia');
?>