#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# アンケート集計
#

require 'al_form'
require 'al_template'
require '../../enquete'
require '../../enquete_totalize'


class AlController
  
  ##
  # デフォルト動作
  #
  def action_index()
    @enquete = Enquete.create_by_posted_id()
    raise "id error."  if ! @enquete

    @total = @enquete.totalize()
    
    AlTemplate.run( "v_index.rhtml" )
  end


  ##
  # 結果のダウンロード
  #
  def action_download()
    @enquete = Enquete.create_by_posted_id()
    raise "id error."  if ! @enquete

    Alone::add_http_header( "Content-Type: text/csv" )
    Alone::add_http_header( "Content-Disposition: attachment; filename=enquete_#{@enquete[:enquete_id]}.csv" )
    @enquete.download()
  end

end
