<?php
session_start();
if(strpos(strtolower($_SERVER['REQUEST_URI']), 'phpsessid') !== false)
{
  session_destroy();
  session_regenerate_id();
  session_start();
                              
}
include "../phpconfig/config.php";
include "../phpconfig/valida_login.php";
include "../phpconfig/slugfy.php";

	


$sql_las_c = mysql_query("SELECT * FROM empresas ORDER BY id DESC LIMIT 1");

$lasc = mysql_fetch_assoc($sql_las_c);

$lastc = $lasc['id'];

$leo = 'Telefone';

mysql_query("INSERT INTO cadastros SET last_empresa='$lastc', data_cad=NOW()");


$texto = array();

$cidade = '';
$uf     = '';

$handle = fopen("ha.txt", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
      $line = trim($line);

        if($line!='') { 

          if(strpos($line,']]')){

          $cuf = explode('||', $line);
          $cidade = str_replace('[[', '', $cuf[0]);
          $uf = str_replace(']]', '', $cuf[1]);
          $autotag = str_replace(']]', '', $cuf[2]);


       
         } else{
        
            $texto[] = ($line).'<br>';

         }


        }
    }


    fclose($handle);

    echo "<pre>";

    foreach ($texto as $a) {



    	$bomba = explode('///', $a);

    	if(sizeof($bomba)>1){ 
    	
      
      
  
      
  	   
    	$slug = slugfyURL(trim($bomba['0']));
    	$n5 = trim(strip_tags($bomba['0']));
    	
    	$cnae = trim(strip_tags($bomba['1']));
    	$nivel_5 = trim(strip_tags($bomba['2']));
    	 
    	 
    
        
                



		mysql_query("INSERT INTO atividade_nivel_5 SET
		
	
        n5 = '$n5', 
        cnae = '$cnae',
        nivel_5 = '$nivel_5'
  
       
	    ", $con) or die(mysql_error());


   

}
    }

} else {
 
} 


if(file_exists('ha.txt')){
  unlink('ha.txt');
}
header("location:multi-nivel.php?cad=1");