<?php
session_start();
///Construtoras listar
include "../phpconfig/config.php";
include "../phpconfig/valida_login.php";
include "../phpconfig/funcoes.php";
include "../includes/topo.php"; 





$sqle = mysql_query("SELECT * FROM cadastros ORDER BY data_cad desc limit 1");

 $num2 = mysql_num_rows($sqle);


?>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<script type="text/javascript">
  // When the document is ready set up our sortable with it's inherant function(s)
  $(document).ready(function() {
    $("#test-list").sortable({
      handle : '.handle',
      update : function () {
      var order = $('#test-list').sortable('serialize');
      $("#info").load("process-sortable.php?"+order);  
   

      }
    });
}); 

</script>

        <ul class="breadcrumb">
          <li><a href="<?php echo sti('adm');  ?>">Home</a></li>

        </ul>


        <table class="table table-bordered">

        <thead>
          <tr>
            <td  colspan='2'> 

                           
              Ao excluir esta lista, os dados abaixo (Bairros e Empresas) do último cadastro multiplo serão deletados.

            </td>

          </tr>
          <tr>
   

             <th>Última Empresa</th>
             <th>Deletar cadastros</th>

          </tr>


        </thead>
        <tbody id='test-list'>

          <div id="info"></div>
          <?php  

          while($lin = mysql_fetch_assoc($sqle)){  ?>
          <tr id="listItem_<?php echo $lin['id']; ?>">




            <?php          


            $empresa = retorna($lin['last_empresa'], 'empresas');


            $le =$lin['last_empresa'];
            $dc = $lin['data_cad'];

            ?>
            <td colspan='2'><?php echo $lin['last_empresa'];  ?> - <?php echo $empresa['empresa'];  ?></td>


           

          </tr>
          <tr>
            <td>Último cadastro <?php echo $dc;  ?></td>
            <td><a href="dellista.php?le=<?php echo $le;  ?>" onclick="return confirma('Deseja deletar estes cadastros?');" class="btn btn-default" ><span class="glyphicon glyphicon-trash"></span></a></td>


          </tr>          
          <?php  } if($num2==0){echo "<tr><td  colspan='2'>Não há cadastros</td></tr>";} ?>

        </tbody>
      </table>


<?php

$sql = mysql_query("SELECT * FROM empresas2 ORDER BY id DESC");
$num = mysql_num_rows($sql);


?>
        <table class="table table-bordered">

        <thead>

          <tr>
   

             <th>ID</th>
            <th>Nome</th>

            
             

             <th>Telefone</th>
             <th>slug</th>
             <th>Endereço</th>
             <th>Cidade / UF</th>
             <th>Bairro</th>
             <th></th>
          </tr>
        </thead>
        <tbody id='test-list'>

          <div id="info"></div>
          <?php  

          while($lin = mysql_fetch_assoc($sql)){  ?>
          <tr id="listItem_<?php echo $lin['id']; ?>">

            <?php


            $line = retorna($lin['id'], 'empresas');
            $cidade = retorna($line['id_cidade'], 'l_cidades');
            $estado = retorna($line['id_uf'], 'l_estados');
            $bairro = retorna($line['id_bairro'], 'l_bairros');

            ?>

            <td><?php echo $line['id'];  ?></td>
            <td><?php echo $line['empresa'];  ?></td>
            <td><?php echo $line['telefone'];  ?></td>
            <td><?php echo $line['slug'];  ?></td>
            <td><?php echo $line['endereco'];  ?></td>
            <td><?php echo $cidade['cidade'];  ?> - <?php echo strtoupper($estado['uf']);  ?></td>
            <td><?php echo $bairro['bairro'];  ?></td>
           
              <td>
              <a href="edit.php?id=<?php echo $line['id'];  ?>" class="btn btn-default" ><span class="glyphicon glyphicon-pencil"></span></a>
              <a href="del.php?id=<?php echo $line['id'];  ?>" onclick="return confirma('Deseja deletar este cliente?');" class="btn btn-default" ><span class="glyphicon glyphicon-trash"></span></a>
            </td>
          </tr>
          <?php  } if($num==0){echo "<tr><td  colspan='8'>Não há cadastro de empresas</td></tr>";} ?>


        </tbody>
      </table>

        <table class="table table-bordered">

        <thead>

          <tr>
            <!-- <th>MOVER</th> -->

            <th>Nome</th>  

            <th>Slug</th>   
  

             <th>Ação</th>

             <!-- <th>Deletar</th> -->
          </tr>
        </thead>
        <tbody id='test-list'>

                    
          <?php




            $sqlc = mysql_query("SELECT * FROM l_bairros2 ORDER BY bairro asc");

            $num = mysql_num_rows($sqlc);

             while($lin = mysql_fetch_assoc($sqlc)){ ?>

          <tr id="listItem_<?php echo $lin['id']; ?>"><!-- 
            <td> <div class="box_img handle" style="cursor:move;display:block">
            <div class="mover"><i class='icon-move'></i></div></td> -->
            <td><?php echo $lin['bairro']; ?></td>
            <td><p class='pull-right'><?php echo $lin['slug']; ?></p></td>
            
            
              <td>
             <a href="editb.php?id=<?php echo $lin['id']; ?>&c=<?php echo $id_cidade; ?>" class="btn btn-default" ><span class="glyphicon glyphicon-pencil"></span></a>
              <a href="delb.php?id=<?php echo $lin['id']; ?>&c=<?php echo $id_cidade; ?>" onclick="return confirma('Deseja deletar esta cidade?');" class="btn btn-default" ><span class="glyphicon glyphicon-trash"></i></a>

          </tr>
            </td>
          <!--   <td>
              <a href="del.php?id=<?php echo $lin['id'];  ?>" onclick="return confirma('Deseja deletar este bairro?');" class="btn btn-danger" ><i class="icon-trash"></i></a>
            </td> -->
          </tr>



          <?php  }  if($num==0){echo "<tr><td  colspan='5'>Não há cadastro de bairros</td></tr>";} ?>


        </tbody>
      </table>



<?php include "../includes/rodape.php"; ?>
