<?php
session_start();

include "../phpconfig/config.php";
include "../phpconfig/valida_login.php";
include "../phpconfig/funcoes.php";
include "../includes/topo.php"; 

$id = $_GET['id'];


$sqle = mysql_query("SELECT * FROM l_estados ORDER BY estado asc");
$sqlc = mysql_query("SELECT * FROM l_cidades ORDER BY cidade asc");

$sql = mysql_query("SELECT * FROM info_estado WHERE id='$id'");

$lin = mysql_fetch_assoc($sql);

$id_uf = $lin['uf'];
$id_cidade = $lin['id_cidade'];

?>


        <ul class="breadcrumb">
          <li><a href="<?php echo sti('adm');  ?>">Home</a></li>
          <li>Editar texto - info
          <li class="active"><?php echo $lin['info']; ?> </li>
        </ul>
<div class='row'>

  <div class='col-md-8'>
 <form class="form-horizontal" method="post" action="edita.php" id='depform'  enctype="multipart/form-data">

        <fieldset>


               <input type='hidden'  id='uf' name='uf'>
               <input type='hidden'  id='cidade' name='cidade'>

                  <div class="control-group">
            <label class="control-label"  for="nome">Nacional</label>
            <div class="controls">
              <input type="checkbox"  <?php  if($lin['nacional']==1) { echo 'checked'; }  ?>  name='nacional' >
            </div>
          </div> 

                  <div class="control-group">
            <label class="control-label"  for="nome">Destaque</label>
            <div class="controls">
              <input type="checkbox"  <?php  if($lin['destaque']==1) { echo 'checked'; }  ?>  name='destaque' >
            </div>
          </div> 

              <select id='estados' name='estados' class="form-control">
             <option>- Estado -</option>

                <?php while($line = mysql_fetch_assoc($sqle)){ ?>                
                  <option value='<?php  echo $line['id'];  ?>' <?php if(isset($id_uf)){ if($id_uf==$line['id']) {echo 'selected';}    } ?> ><?php  echo $line['estado'];  ?></option>
                <?php } ?>   

              </select>  <br />

                <div id='retc'>


                <select id='cidades' name='cidades' class="form-control">
              <option> - Cidade - </option>
                <?php while($line = mysql_fetch_assoc($sqlc)){ ?>                
                  <option value='<?php  echo $line['id'];  ?>' <?php if(isset($id_cidade)){ if($id_cidade==$line['id']) {echo 'selected';}    } ?> ><?php  echo $line['cidade'];  ?></option>
                <?php } ?>   

              </select>  
            </div>

                   <div class="control-group">
            <label class="control-label" for="nome">Data da notícia</label>
            <div class="controls">
              <input type="text" class="input-xlarge data" name='data' id='data' value='<?php echo troca_data2($lin['data_cad']);  ?>'  >
            </div>
          </div>          
          <div class="control-group">
            <label class="control-label" for="input01">Imagem</label>
            <div class="controls">
              <img width='200' src='<?php echo sti('up')."noticias/".$lin['imagem'];  ?>'  />

            </div>
          </div>
       
          <div class="control-group">
            <label class="control-label" for="titulop">Título</label>
            <div class="controls">
              <input type="text" class="input-xlarge" name='titulop'size='45' id="titulop" value='<?php echo $lin['titulo_pt'];  ?>' >
            </div>
          </div>
          <div class="control-group">

          <div class="control-group">
            <label class="control-label" for="nome">Slug</label>
            <div class="controls">
              <input type="hidden" class="input-xlarge" name='id' size='45' id="id" value='<?php echo $lin['id'];  ?>' >
              <input type="text" class="input-xlarge" name='slug' size='45' id="slug" value='<?php echo $lin['slug'];  ?>' >
            </div>
          </div>             
          <div class="control-group">
            <label class="control-label"  for="depp">Notícia</label>
            <div class="controls">
              <?php


                    $substitute = "src=\"".sti('urlbase')."assets/uploads/noticias/";
          
                    $src = str_replace('src="images/',$substitute,$lin['texto_pt']);

  

              ?>
              <textarea name='depp' id="myArea2" cols='20' style='width:800px' rows='40'><?php echo $src; ?></textarea>
            </div>
          </div>
                 
          <div class="control-group">
            <label class="control-label" for="imagem">Imagem</label>
            <div class="controls">
              <input id="imagem" name='imagem' accept="image/*" type="file">
            </div>
          </div>

          <div class="form-actions">
            <input  type="submit" class="btn btn-primary" value='Salvar' />
            <a class="btn btn-warning pull-right" href="index.php">Voltar</a>
          </div>
        </fieldset>
      </form>

</div>

<div class='col-md-4'>
<!-- <a class="btn btn-warning pull-right" target='_blank' href="../foto/index.php">Fotos</a> -->


              
</div>
</div>
 <script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
    <script type="text/javascript">
      //<![CDATA[
      var area1;

      function toggleArea1() {
      
            area1 = new nicEditor({fullPanel : true}).panelInstance('myArea2',{hasPanel : true});

      }


      bkLib.onDomLoaded(function() { 
      
          new nicEditor({buttonList : ['fontFormat','bold','italic','underline','strikeThrough','subscript','superscript','html','image','link','ul']}).panelInstance('myArea2');
      
      toggleArea1(); 

    });

     
       $("#estados").change(function(){
        var uf = $("#estados").val();

    $.ajax({   
      url: "retCidades.php?uf="+uf,
      type: 'GET',
      beforeSend: function() {    


      },
    success: function(data)
    {
 
        $('#retc').html(data);  
        $("#uf").val(uf);
 
    }
  });

      });


       function aha(){

        var uf = $("#estados").val();

    $.ajax({   
      url: "retCidades.php?uf="+uf,
      type: 'GET',
      beforeSend: function() {    


      },
    success: function(data)
    {
 
        $('#retc').html(data);  
        $("#uf").val(uf);

 
    }
  });


       }
 $("#cidade").val('<?php  echo $id_cidade;  ?>');

//aha();
      </script>

 

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