<?php require_once('topo.php');?>
<?php require_once('lateral.php');?>
<?php
$idmarca = Sanitize::filter($_GET["idmarca"]);

if($idmarca == ""){
$acao	= "Salvar";
}else{
$acao = "Alterar";	
}

//Recebe Acao
$acao_bd	= Sanitize::filter($_GET["acao"]);
$acao_bd	.= Sanitize::filter($_POST["acao"]);


//CAMPOS POST 


$idmarca .= Sanitize::filter($_POST["idmarca"]);
$titulo = Sanitize::filter($_POST["titulo"]);
$origem = Sanitize::filter($_POST["origem"]);
//CAMPOS TABELA SALVAR 

$campos_tabela = "titulo, origem";

//Dados da Tabela

$tabela	="marcas";

$campos_value = "'$titulo', '$origem'";

//INSERIR REGISTROS

if($acao_bd == "Salvar"){

$salvar = Salvar($tabela, $campos_tabela, $campos_value);

// RETORNA ULTIMO ID INSERIDO

$id_insert = mysql_insert_id();

//CRIO ALBUM
$criar_album = Salvar("albuns",  "album_name, idmarca", "'$titulo', '$id_insert'");	

$redireciona = VerificaSql($salvar, "manutencao_marcas.php?idmarca=".$id_insert."", "manutencao_marcas.php");

}


// CAMPOS ALTERAR 


if($acao_bd == "Alterar"){

$campos_alterar = "titulo='$titulo', origem='$origem'";

$atualizar = Alterar($tabela, $campos_alterar, "idmarca", $idmarca);

$redireciona = VerificaSql($atualizar, "manutencao_marcas.php?idmarca=".$idmarca."&Box=".$_GET['Box']."", "manutencao_marcas.php?idmarca=".$idmarca."&Box=".$_GET['Box']."");

}


//EXCLUIR REGISTRO 



if($_GET["excluir"] == "sim"){

$deletar = Excluir($tabela, "idmarca", $idmarca);
	$excluir_album = Excluir("albuns", "idmarca", $idmarca);
$redireciona = VerificaSql($deletar, "listar_marcas.php?Box=".$_GET['Box']."", "manutencao_marcas.php?idmarca=".$idmarca."&Box=".$_GET['Box']."");

} 

//CAMPOS SELECT 

if($acao == "Alterar"){

$selecionar_paginas = Seleciona($tabela, "WHERE idmarca=$idmarca", "") or die(mysql_error());
while($linha_pagina=mysql_fetch_array($selecionar_paginas)){
$idmarca = $linha_pagina['idmarca']; 
$titulo = $linha_pagina['titulo']; 
$origem = $linha_pagina['origem']; 

} 

$seleciona_album = Seleciona("albuns", "WHERE idmarca='$idmarca'", "");
while($album = mysql_fetch_array($seleciona_album)){
	$idalbum = $album['album_id'];
}

} 

?>

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="js/css/froala_editor.css">
  <link rel="stylesheet" href="js/css/froala_style.css">
  <link rel="stylesheet" href="js/css/plugins/code_view.css">
  <link rel="stylesheet" href="js/css/plugins/colors.css">
  <link rel="stylesheet" href="js/css/plugins/emoticons.css">
  <link rel="stylesheet" href="js/css/plugins/image_manager.css">
  <link rel="stylesheet" href="js/css/plugins/image.css">
  <link rel="stylesheet" href="js/css/plugins/line_breaker.css">
  <link rel="stylesheet" href="js/css/plugins/table.css">
  <link rel="stylesheet" href="js/css/plugins/char_counter.css">
  <link rel="stylesheet" href="js/css/plugins/video.css">
  <link rel="stylesheet" href="js/css/plugins/fullscreen.css">
  <link rel="stylesheet" href="js/css/plugins/file.css">
  <link rel="stylesheet" href="js/css/plugins/quick_insert.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/codemirror.min.css">

<form name="cadastro_pagina" id="cadastro_pagina" method="post" action="manutencao_marcas.php" enctype="multipart/form-data" class="form-default">
<input type="hidden" name="acao" value="<?php echo $acao;?>">
<input type="hidden" name="idmarca" value="<?php echo $idmarca;?>"> 
 

      <!-- Right side column. Contains the navbar and content of the page -->
      <div class="content-wrapper" style="<?php if($_GET['Box'] != ""){ echo "margin-left: 0px;"; }?>">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Marcas
            <small>Detalhe</small>
			<button type="button" class="btn btn-primary" style=" float: inherit;" onclick="location.href='manutencao_marcas.php';">Novo Marca</button>            
          </h1>
          <ol class="breadcrumb">
            <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="listar_marcas.php">Marcas</a></li>
            <li class="active">Detalhes / Editar</li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
            <!-- left column -->
            <div class="col-md-6">
              <div class="box box-primary">
                <div class="box-header">
                  <h3 class="box-title">Dados do Pagina</h3>                  
                </div>
                <div class="box-body">
                  <div class="row">                                        
        <div class='col-xs-6'>		
        <label>Origem</label>
        <select class="form-control" name="origem">             
        <option value="" <?php if($origem == ""){ echo "selected";}?>>Todos</option>
        <option value="Institucional" <?php if($origem == "Institucional"){ echo "selected";}?>>Institucional</option>
        <option value="LojaVirtual" <?php if($origem == "LojaVirtual"){ echo "selected";}?>>Loja Virtual</option>
        <option value="App" <?php if($origem == "App"){ echo "selected";}?>>App</option>        
        </select>            
        </div>
		<div class='col-xs-6'>
		<label for='titulo'>Titulo</label>
		  <input type='text' id='titulo' name='titulo' class='form-control' placeholder='titulo' value='<?php echo $titulo;?>'>
		</div>

                  </div>
                    <div class="box-footer">
                    <button type="submit" class="btn btn-primary">Salvar</button>
                    <?php if($acao != "Salvar"){ ?>
                    <button type="button" class="btn btn-danger" onclick="location.href='manutencao_marcas.php?idmarca=<?php echo $idmarca;?>&excluir=sim&Origem=<?php echo $_GET['Origem'];?>';">Excluir</button>
                    <?php }?>
                    </div>                  
                </div><!-- /.box-body -->
              </div><!-- /.box -->
              
              <!-- ALBUM DE FOTOS -->
              <?php if($acao != "Salvar"){ ?>
              <div class="box box-primary">
                <div class="box-header">
                  <h3 class="box-title">Fotos do Album</h3>
                  
				  <button type="button" class="btn btn-twitter" style=" float: right;" onclick="location.href='album.php?id=<?php echo $idalbum;?>';">Album de Fotos</button>                         
                </div>
                <div class="box-body">
                  <div class="row">                                        
					<?php if($acao == "Alterar"){ ?>
                    <?php
                    if($idalbum != "" and $idalbum != 0){
                    $SelecionaFotos	= Seleciona("fotos", "WHERE foto_album=$idalbum", "");
                    while($fotos = mysql_fetch_array ($SelecionaFotos)){					
                    ?>
                    <div style="border: #CCC 1px solid; margin: 10px; width: 150px; height: 150px; float:left;"> <img src="../catalogo/painel/albumdefotos/fotos/<?php echo $fotos['foto_url']?>" width="150" height="150" alt=""></div>
                    <?php } }?>
                    <?php }?>                  
                  </div>                 
                </div><!-- /.box-body -->
              </div><!-- /.box -->  
              <?php }?> 
              <!-- FIM ALBUM DE FOTOS -->               
              
            </div><!--/.col (left) -->

          </div>   <!-- /.row -->
        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->
</form>  
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/codemirror.min.js"></script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/mode/xml/xml.min.js"></script>

  <script type="text/javascript" src="js/js/froala_editor.min.js" ></script>
  <script type="text/javascript" src="js/js/plugins/align.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/char_counter.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/code_beautifier.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/code_view.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/colors.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/draggable.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/emoticons.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/entities.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/file.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/font_size.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/font_family.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/fullscreen.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/image.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/image_manager.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/line_breaker.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/inline_style.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/link.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/lists.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/paragraph_format.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/paragraph_style.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/quick_insert.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/quote.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/table.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/save.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/url.min.js"></script>
  <script type="text/javascript" src="js/js/plugins/video.min.js"></script>

  <script>
    $(function(){
      $('#edit').froalaEditor()
    });
  </script>    
<?php require_once('rodape.php');?>
