class Admin::RegistrantsController < ApplicationController
  layout "admin"
  

  
  def index
    @annonce_accounts = AnnonceAccount.enableds.all
    
    respond_to do |format|
      format.html {
        render :inline => "csv ?"
      }
    
    
    
      format.csv { 
      
        @file = ""
      
        elements = {
        
          "sideplace_id" => "id",
          "organisation" => "organisation.to_s.slice(0,1).capitalize.to_s + trans.organisation.to_s.slice(1..-1).to_s",
          "Last Name" => "name.to_s.capitalize",
          "First Name" => "firstname.to_s.capitalize",
          "email" => "email",
          "affiliation" => "mlm_token",
          "provider" => "provider",
          "inscription" => "created_at",
          "pro" => "pro"
          
          
        
        }
      
   
      
        headers = []
        attributes = []
      
        elements.each do |key, value|
          headers << key
          attributes << value
        end
      
        @csv = CSV.generate(:headers => true, :col_sep => "\t") do |csv|
          csv << headers
        
          @annonce_accounts.each do |trans|
        
              csv << attributes.map{ |attr| eval("trans."+attr.to_s) }

          end
        
        end
    
    
    send_data @csv.encode('iso-8859-1', :undef => :replace, :replace => ''), :filename => "export-sidepace-#{Date.today.to_s.to_slug}.csv", :type => 'text/csv; charset=iso-8859-1; header=present'
  }
end
    
  end



end
