<?php include_once("sistema/restrito_admin.php");?>
<?php include_once("header.php");?>

 
   <div id="local">
     <div class="caminho">Onde estou : CCIBM &raquo; Painel de Controle &raquo; Cadastrar Notícia</div><!--fecha class caminho-->
     <div class="welcome">Olá, Cleiton &raquo; Hoje: 20/02/2015 | 01:56hs | <a href="../deslogar.php">Deslogar</a></div><!--fecha class welcome-->
     
   </div><!--fecha local-->
 
  <div id="content">
<?php include_once("menu.php");?>  

      

    
    <div id="content_conteudo">
    
    <h1>Cadastrar Notícias</h1>
    
   <?php
   include "../Connections/config.php";
   
   if(isset($_POST['cadastra_noticia']) && $_POST['cadastra_noticia'] == 'cad'){
	   
	   
   
   
	    $IdNot  = $_POST['IdNoticia'];
		  
		  $img = $_FILES['thumb'];
		  $pasta = '../image/slide';
		  $permitido = array('image/jpg', 'image/jpeg', 'image/pjpg');
		  $contarImg = count($ImgNot['name']);
		  $titulo = strip_tags(trim($_POST['titulo']));
		  $data = (trim($_POST['data']));
		  $texto = strip_tags(trim($_POST['texto'])); 
		  require("sistema/upload.php");
		  
		  
		  for($i=0;$i<$contarImg;$i++){
			  
			  $nome = $img['name'][$i]; 
			  $tmp = $img['tmp_name'][$i];
			  $type = $img['type'][$i];
			  
			  $entrada = ("$data");
			  
		  if(!empty($nome) && in_array($type, $permitido)){
			  $name = 'imagem='.$IdNot.'-'.md5(uniqid(rand(), true)).'.jpg';
			  Redimensionar($tmp, $name, 670, $pasta);
			  
			  $sql_noticia  = 'INSERT INTO noticias (IdNoticia, thumb, titulo, data, texto)';
			  $sql_noticia .= 'VALUES (:IdNoticia, :thumb, :titulo, :data, :texto)';
			  
			  try{
				  $query_cadastra = $conecta->prepare($sql_noticia);
				  $query_cadastra->bindValue(':IdNoticia',$IdNot,PDO::PARAM_STR);
				  $query_cadastra->bindValue(':img',$img,PDO::PARAM_STR);
				  $query_cadastra->bindValue(':titulo',$titulo,PDO::PARAM_STR);
				  $query_cadastra->bindValue(':data',$data,PDO::PARAM_STR);
				  $query_cadastra->bindValue(':texto',$texto,PDO::PARAM_STR);
				  $query_cadastra->execute();
				  
			  }catch(PDOexception $error_cadastra){
				echo 'Erro ao cadastrar notícia'.$error_cadastra->getMessage();				               }
				
			  
		  }
		  
		  
		  
	     
	}	  

}
		  
	   ?>
    
    
	<?php include_once("scripts/scripts.php");?><!--chamando o tynemce-->
       <form name="cadastra_noticia" action="" method="post" enctype="multipart/form-data">
          <label>
          <span>Escolha a Imagem da notícia:</span>
          <input type="file" name="thumb" size="60"/>
          </label>
          
          
          <label>
          <span>Digite o título da notícia:</span>
          <input type="text" name="titulo"/>
          </label>
          
          <label>
          <span>Escolha a data da notícia:</span>
          <input type="text" name="data"/>
          </label>
          
          <label>
          <span>Digite o conteúdo da notícia:</span>
           <textarea name="texto"></textarea>

          </label>
          <input type="hidden" name="cadastra_noticia" value="cad" class="btn"/>
          <input type="submit" name="finalizar" value="Finalizar" class="btn"/>

       </form>
      
    </div><!--fecha content conteudo-->
  
  
  </div><!--fecha content-->
 <?php include_once("footer.php");?>