# -*- encoding : utf-8 -*-

class Public::FileTunelDownloadsController < ApplicationController
  layout "public"
 
  

  def create
    @file_tunel_download = FileTunelDownload.new(params.require(:file_tunel_download).permit!)
    @file_tunel_send = @file_tunel_download.file_tunel_send
    
    
    
    if @file_tunel_download.save
      @file_tunel_download.send_mail_type("envoi_fichier")
    
      
      redirect_to thank_public_file_tunel_download_path(@file_tunel_download.token)
      
      
      
    else
      render :template => "public/file_tunel_sends/show"
 
    end

  end


  def thank
    @file_tunel_download = FileTunelDownload.where(:token => params[:id]).first
    @file_tunel_send = @file_tunel_download.file_tunel_send
    
    
  end

  def show
    @file_tunel_download = FileTunelDownload.where(:token => params[:id]).first
    @file_tunel_send = @file_tunel_download.file_tunel_send
    
    
  end
  
  
  def download
    @file_tunel_download = FileTunelDownload.where(:token => params[:id]).first
    @file_tunel_send = @file_tunel_download.file_tunel_send
    
    
    @data_to_send = File.open(@file_tunel_download.generate_pdf).read
    
    
    #params[:inline] = true
    
    
    send_data @data_to_send, :filename =>"#{@file_tunel_download.token}.pdf" , :type => 'application/pdf',:disposition => (params[:inline] ? 'inline' : "attachment")
    #render :inline => "y"
    
  end
  
  def fili
    @file_tunel_download = FileTunelDownload.where(:token => params[:id]).first
    @file_tunel_send = @file_tunel_download.file_tunel_send
    @file_tunel = @file_tunel_send.file_tunel
    
    
    
  end


end
