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

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

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


//CAMPOS POST 


$idloja .= Sanitize::filter($_POST["idloja"]);
$nome_loja = Sanitize::filter($_POST["nome_loja"]);
$endereco = Sanitize::filter($_POST["endereco"]);
$contatos = Sanitize::filter($_POST["contatos"]);
$whatsapp = Sanitize::filter($_POST["whatsapp"]);
$iframe_google = Sanitize::filter($_POST["iframe_google"]);

//CAMPOS TABELA SALVAR 

$campos_tabela = "nome_loja, endereco, contatos, whatsapp, iframe_google";

//Dados da Tabela

$tabela	="lojas";

$campos_value = "'$nome_loja', '$endereco', '$contatos', '$whatsapp', '$iframe_google'";

//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, idloja", "'$nome_loja', '$id_insert'");	

$redireciona = VerificaSql($salvar, "manutencao_lojas.php?idloja=".$id_insert."&Box=".$_GET['Box']."", "manutencao_lojas.php?Box=".$_GET['Box']."");

}


// CAMPOS ALTERAR 


if($acao_bd == "Alterar"){

$campos_alterar = "nome_loja='$nome_loja', endereco='$endereco', contatos='$contatos', iframe_google='$iframe_google'";

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

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

}


//EXCLUIR REGISTRO 



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

$deletar = Excluir($tabela, "idloja", $idloja);
	$excluir_album = Excluir("albuns", "idloja", $idloja);
$redireciona = VerificaSql($deletar, "listar_lojas.php?Box=".$_GET['Box']."", "manutencao_lojas.php?idloja=".$idloja."&Box=".$_GET['Box']."");

} 

//CAMPOS SELECT 

if($acao == "Alterar"){

$selecionar_paginas = Seleciona($tabela, "WHERE idloja=$idloja", "") or die(mysql_error());
while($linha_pagina=mysql_fetch_array($selecionar_paginas)){
$idloja = $linha_pagina['idloja']; 
$nome_loja = $linha_pagina['nome_loja']; 
$endereco = $linha_pagina['endereco']; 
$contatos = $linha_pagina['contatos']; 
$whatsapp = $linha_pagina['whatsapp']; 
$iframe_google = $linha_pagina['iframe_google']; 


} 

$seleciona_album = Seleciona("albuns", "WHERE idloja='$idloja'", "");
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_lojas.php?Box=<?php echo $_GET['Box'];?>" enctype="multipart/form-data" class="form-default">
<input type="hidden" name="acao" value="<?php echo $acao;?>">
<input type="hidden" name="idloja" value="<?php echo $idloja;?>"> 
 

      <!-- 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>
            Lojas
            <small>Detalhe</small>
			<button type="button" class="btn btn-primary" style=" float: inherit;" onclick="location.href='manutencao_lojas.php?Box=<?php echo $_GET['Box'];?>';">Nova Loja</button>            
          </h1>
          <ol class="breadcrumb">
            <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="listar_lojas.php?Box=<?php echo $_GET['Box'];?>">Lojas</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 da Loja</h3>                  
                </div>
                <div class="box-body">
                  <div class="row">                                        

		<div class='col-xs-6'>
		<label for='nome_loja'>Nome da Loja</label>
		  <input type='text' id='nome_loja' name='nome_loja' class='form-control' placeholder='nome_loja' value='<?php echo $nome_loja;?>'>
		</div>

		<div class='col-xs-6'>
		<label for='whatsapp'>WhatsApp</label>
		  <input type='text' id='whatsapp' name='whatsapp' class='form-control' placeholder='whatsapp' value='<?php echo $whatsapp;?>'>
		</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_lojas.php?idloja=<?php echo $idloja;?>&excluir=sim&Box=<?php echo $_GET['Box'];?>';">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;?>&Box=<?php echo $_GET['Box'];?>';">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 class="col-md-6">
              <div class="box box-primary">
                <div class="box-header">
                  <h3 class="box-title">Dados do Texto</h3>
                </div>
                <div class="box-body">
                  <div class="row">
                  
		<div class='col-xs-12'>
		<label for='endereco'>Endereço</label>          
        <textarea id="edit" name="endereco" style="width: 500px; height: 400px;">
        <?php echo $endereco;?>
        </textarea>          
		</div>
        
		<div class='col-xs-12'>
		<label for='contatos'>Contatos</label>          
        <textarea id="edit2" name="contatos" style="width: 500px; height: 400px;">
        <?php echo $contatos;?>
        </textarea>          
		</div>  
        
		<div class='col-xs-12'>
		<label for='iframe_google'>Iframe Google</label>          
        <textarea id="iframe_google" name="iframe_google" class='form-control'>
        <?php echo $iframe_google;?>
        </textarea>          
		</div>                
                    
                
                  </div>
                </div><!-- /.box-body -->
              </div><!-- /.box -->            
              
            </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()
    });
    $(function(){
      $('#edit2').froalaEditor()
    });	
  </script>    
<?php require_once('rodape.php');?>
