Application_Form/app/controllers/application_forms_controlle...

811 lines
36 KiB
Ruby
Raw Normal View History

2022-03-10 02:11:18 +00:00
class ApplicationFormsController < ApplicationController
helper MemberHelper
include MemberHelper
include ActionView::Context #vary important (only add this can access @@session from view)
include Admin::ApplicationFormsHelper
2022-10-24 08:34:14 +00:00
FrontendMethods = ["show_privacy", "show_data", "check_email", "check_availability", "signup_ok", "edit_file", "con_login", "con_upload", "con_logout"]
2022-03-10 02:11:18 +00:00
# include SimpleCaptcha::ControllerHelpers
def index
time_now = Time.now
application_forms = ApplicationFormMain.all.desc(:application_form_start_date).filter_by_categories
application_forms = application_forms.any_of({:application_form_start_date.lte=>Time.now, :application_form_end_date.gte=>Time.now},{:application_form_start_date.lte=>Time.now, :application_form_end_date => nil})
2022-03-10 02:11:18 +00:00
{
"application_forms" => application_forms,
'time_now' => time_now,
"total_pages" => application_forms.total_pages
}
end
def widget
cats = OrbitHelper.widget_categories || []
widget_data_count = OrbitHelper.widget_data_count
application_forms = ApplicationFormMain.all.desc(:application_form_start_date).filter_by_categories(cats)
time_now = DateTime.now
session = OrbitHelper.request.session
application_forms = application_forms.map do |application_form|
link_url = OrbitHelper.url_to_show(application_form.to_param)
2022-05-21 13:48:39 +00:00
if (application_form.application_form_start_date <= time_now rescue false) && ( application_form.application_form_end_date.nil? || application_form.application_form_end_date+1 >= time_now )
sign_up = ('<a href="'+ link_url + '">' + I18n.t('application_form.signup') + '</a>').html_safe
2022-03-10 02:11:18 +00:00
elsif application_form.registration_status.blank?
sign_up = I18n.t('application_form.sign_up_not_open')
2022-05-21 13:48:39 +00:00
elsif (application_form.application_form_start_date > @time_now rescue false)
2022-03-10 02:11:18 +00:00
sign_up = I18n.t('application_form.sign_up_not_yet')
else
sign_up = I18n.t('application_form.sign_up_overdue')
end
if !application_form.registration_status.blank? && application_form.registration_status.include?('C') && (application_form.contribute_start_date <= time_now rescue false) && ( application_form.contribute_end_date.nil? || (application_form.contribute_end_date+1 >= time_now rescue false) )
sign_up += "<span style=\"margin-left: 1em;\">".html_safe
if !session[:application_form_signup_id].blank?
if session[:application_form_main_id] == application_form.id
sign_up += ('<a href="'+ link_url + '?method=con_upload">' + t('application_form_signup.uploads') + '</a>').html_safe
else
sign_up += ('<a href="'+ link_url + '?method=con_login">' + t('application_form_signup.con_login') + '</a>').html_safe
end
else
sign_up += ('<a href="'+ link_url + '?method=con_login">' + t('application_form_signup.con_login') + '</a>').html_safe
end
sign_up += "</span>".html_safe
end
files = application_form.application_form_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } } rescue []
files.delete(nil)
links = application_form.application_form_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
{"title" => application_form.title,
"subtitle" => sign_up,
"category" => (application_form.category.title rescue ""),
"link_to_show" => (link_url == "#" ? '' : link_url + "?method=show_data"),
"postdate" => application_form.application_form_start_date,
"statuses" => {},
"bulletin_links" => links,
"bulletin_files" => files
}
end
{
"application_forms" => application_forms,
"extras" => {
"date-head" => I18n.t("application_form.application_form_start_date"),
"category-head" => I18n.t(:category),
"title-head" => I18n.t("application_form.title")
}
}
end
# def custom_frontend_data
# params = OrbitHelper.params
2022-10-24 08:34:14 +00:00
# uid = params[:uid].to_s
# application_form = ApplicationFormMain.find_by(:uid=>uid)
# @application_form = application_form
# @site_in_use_locales = Site.first.in_use_locales rescue I18n.available_locales
# application_form_template_setting = application_form.application_form_template_setting
# @application_form_template_setting = application_form_template_setting
# home_page = Page.where(:parent_page_id=>application_form.id).first
2022-10-24 08:34:14 +00:00
# prefix_url = OrbitHelper.request.path.split("-").first + "-#{uid}"
# @prefix_url = prefix_url
# header_data = "<a href=\"#{prefix_url}#{home_page.url}\">Home</a> | " +
# "<a href=\"/\">Main Site</a>"
# content_style = application_form_template_setting.content_style
# background_style = application_form_template_setting.background_style
# background_style_info = ApplicationFormTemplateSetting.background_style_infos[background_style].to_h
# content_style_info = ApplicationFormTemplateSetting.content_style_infos[content_style].to_h
# extra_css = content_style_info["css"].to_a + background_style_info["css"].to_a
# extra_js = content_style_info["js"].to_a + background_style_info["js"].to_a
# template_path = content_style_info["template"]
# template_info = content_style_info["info"]
# custom_footer = application_form_template_setting.footer_info
# if application_form_template_setting.application_form_banner_images.count != 0 || background_style_info["default_logo"]
# banner_title = application_form.title
# external_link = prefix_url + "/home"
# images = []
# if application_form_template_setting.application_form_banner_images.count == 0
# images = [{
# "image_link" => background_style_info["default_logo"],
# "image_alt" => banner_title,
# "title" => "",
# "alt_title" => banner_title,
# "class" => "active",
# "height" => 0,
# "width" => 0,
# "caption" => '<div class="cycle-overlay"></div><div class="cycle-pager"></div>',
# "context" => "",
# "link" => external_link,
# "target" => ""
# }]
# else
# images = application_form_template_setting.application_form_banner_images.map.with_index do |image,i|
# caption = (i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : "")
# klass = (i == 0 ? "active" : "")
# alt_title = image.description
# context = ""
# image_link = image.file.url
# {
# "image_link" => image_link,
# "image_alt" => alt_title,
# "title" => "",
# "alt_title" => alt_title,
# "class" => klass,
# "height" => 0,
# "width" => 0,
# "caption" => caption,
# "context" => context,
# "link" => external_link,
# "target" => ""
# }
# end
# end
# custom_banner = {
# "extras" => {
# "ad_fx" => "fade",
# "speed" => 500,
# "title" => banner_title,
# "banner-height" => 0,
# "banner-width" => 0,
# "base_image" => 0,
# "timeout" => (5 * 1000),
# "more" => "More"
# },
# "images" => images
# }
# else
# custom_banner = nil
# end
# @@session = OrbitHelper.request.session
# @@session[:application_form_main_id] = @application_form.id
# if params[:method].present?
# main_content = render_other_method
# elsif params[:current_page_module] == "application_forms_home"
2022-10-24 08:34:14 +00:00
# application_form = ApplicationFormMain.where(uid: uid).first
# time_now = Time.now
# data = {
# "application_form" => application_form,
# "time_now" => time_now
# }
# @_request = OrbitHelper.request
# if template_info["main_content"]
# main_content = render_other_method("show_data",template_info["main_content"])
# else
# main_content = render_to_string("application_forms/custom_home",:locals=>{:application_form=>application_form,
# :params=>params,:session=>OrbitHelper.request.session},:layout=>false)
# end
# elsif params[:current_page_module] == "application_forms_page"
# time_now = Time.now
# params = OrbitHelper.params
2022-10-24 08:34:14 +00:00
# application_form = ApplicationFormMain.find_by(uid: uid)
# if application_form.application_form_start_date <= time_now && ( application_form.application_form_end_date.nil? || application_form.application_form_end_date+1 >= time_now )
# sign_up = ('<a href="'+ prefix_url + '" target="_blank">' + t('application_form.signup') + '</a>').html_safe
# elsif application_form.registration_status.blank?
# sign_up = t('application_form.sign_up_not_open')
# elsif application_form.application_form_start_date > time_now
# sign_up = t('application_form.sign_up_not_yet')
# else
# sign_up = t('application_form.sign_up_overdue')
# end
# if !application_form.registration_status.blank? && application_form.registration_status.include?('C') && application_form.contribute_start_date <= time_now && ( application_form.contribute_end_date.nil? || application_form.contribute_end_date+1 >= time_now )
# if !@@session[:application_form_signup_id].blank?
# if @@session[:application_form_main_id] == application_form.id
# contribute_action = ('<a href="'+ prefix_url + '?method=con_upload">' + t('application_form_signup.uploads') + '</a>').html_safe
# else
# contribute_action = ('<a href="'+ prefix_url + '?method=con_login">' + t('application_form_signup.con_login') + '</a>').html_safe
# end
# else
# contribute_action = ('<a href="'+ prefix_url + '?method=con_login">' + t('application_form_signup.con_login') + '</a>').html_safe
# end
# end
# data = {
# 'application_form' => application_form,
# 'sign_up' => sign_up,
# 'contribute_action' => contribute_action,
# 'time_now' => time_now,
# 'contribute_time_range' => ApplicationFormMain.time_range(application_form.contribute_start_date, application_form.contribute_end_date),
# 'sign_up_time_range' => ApplicationFormMain.time_range(application_form.application_form_start_date, application_form.application_form_end_date),
# 'application_form_time_range' => ApplicationFormMain.time_range(application_form.application_form_start_date, application_form.application_form_end_date)
# }
# @_request = OrbitHelper.request
# main_content = render_to_string("application_forms/show_data",:locals=>{:action_data=>data,
# :request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
# :params=>params,:session=>OrbitHelper.request.session},:layout=>false)
# else
# main_content = render_other_method("render_"+params[:current_page_module]) rescue nil
# end
# custom_datapp_data = {}
# if custom_banner
# custom_banner["custom_widget_type"] = "module_widget"
# custom_banner["custom_widget_module"] = "ad_banner"
# if custom_banner["images"].count > 1
# custom_banner["custom_widget_file"] = "ad_banner_widget1"
# else
# custom_banner["custom_widget_file"] = "ad_banner_widget4"
# end
# custom_datapp_data["300"] = [custom_banner]
# end
# return {"main_content"=>main_content,
# "extra_css"=>extra_css,
# "extra_js"=>extra_js,
# "header_data" => header_data,
# "prefix_url" => prefix_url,
# "template_path" => template_path,
# "custom_datapp_data" => custom_datapp_data,
# "custom_footer" => (custom_footer.blank? ? nil : custom_footer)
# }
# end
# def render_application_form_registration
# action_data = show
# @_request = OrbitHelper.request
# action_data["prefix_url"] = @prefix_url
# render_to_string("application_forms/show",:locals=>{:action_data=>action_data,
# :request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
# :params=>params,:session=>OrbitHelper.request.session},:layout=>false)
# end
# def render_application_form_registered_participants
# action_data = {"application_form"=>@application_form, "application_form_template_setting"=>@application_form_template_setting}
# @_request = OrbitHelper.request
# action_data["prefix_url"] = @prefix_url
# render_to_string("application_forms/registered_participants",:locals=>{:action_data=>action_data,
# :request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
# :params=>params,:session=>OrbitHelper.request.session},:layout=>false)
# end
# def render_other_method(render_method=nil,render_template=nil)
# params = OrbitHelper.params
# if render_method && render_template.nil?
# return eval(render_method)
# end
# render_method = render_method || params[:method]
# render_template = render_template || render_method
# params = OrbitHelper.params
# action_data = eval(render_method)
# @application_form_main_url = @prefix_url + '/home/introduction'
# if action_data
# if render_method == "con_upload" || render_method == "signup_ok"
# action_data["prefix_url"] = @prefix_url + '/home/submission'
# else
# action_data["prefix_url"] = @prefix_url
# end
# end
# @_request = OrbitHelper.request
# render_to_string("application_forms/#{render_template}",:locals=>{:action_data=>action_data,
# :request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
# :params=>params,:session=>OrbitHelper.request.session},:layout=>false).html_safe
# end
# def render_application_form_submission
# if @@session[:application_form_signup_id]
# action_data = con_upload
# action_data["prefix_url"] = @prefix_url + '/home/submission'
# @_request = OrbitHelper.request
# render_to_string("application_forms/con_upload",:locals=>{:action_data=>action_data,
# :request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
# :params=>params,:session=>@@session},:layout=>false).html_safe
# else
# action_data = con_login
# @_request = OrbitHelper.request
# render_to_string("application_forms/con_login",:locals=>{:action_data=>action_data,
# :request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
# :params=>params,:session=>@@session},:layout=>false).html_safe
# end
# end
2022-03-10 02:11:18 +00:00
def show_privacy
params = OrbitHelper.params
2022-10-24 08:34:14 +00:00
application_form = ApplicationFormMain.where(uid: params[:uid].to_s).first
2022-03-10 02:11:18 +00:00
application_form_agreement = ApplicationFormAgreement.first
{
'application_form' => application_form,
"application_form_agreement" => application_form_agreement
}
end
def show_data
time_now = Time.now
params = OrbitHelper.params
2022-10-24 08:34:14 +00:00
application_form = ApplicationFormMain.find_by(uid: params[:uid].to_s)
2022-03-10 02:11:18 +00:00
2022-05-21 13:48:39 +00:00
if application_form.application_form_start_date <= time_now && ( application_form.application_form_end_date.nil? || application_form.application_form_end_date+1 >= time_now )
sign_up = ('<a href="'+ OrbitHelper.url_to_show(application_form.to_param) + '">' + t('application_form.signup') + '</a>').html_safe
2022-03-10 02:11:18 +00:00
elsif application_form.registration_status.blank?
sign_up = t('application_form.sign_up_not_open')
2022-05-21 13:48:39 +00:00
elsif application_form.application_form_start_date > time_now
2022-03-10 02:11:18 +00:00
sign_up = t('application_form.sign_up_not_yet')
else
sign_up = t('application_form.sign_up_overdue')
end
if !application_form.registration_status.blank? && application_form.registration_status.include?('C') && application_form.contribute_start_date <= time_now && ( application_form.contribute_end_date.nil? || application_form.contribute_end_date+1 >= time_now )
if !@@session[:application_form_signup_id].blank?
if @@session[:application_form_main_id] == application_form.id
contribute_action = ('<a href="'+ OrbitHelper.url_to_show(application_form.to_param) + '?method=con_upload">' + t('application_form_signup.uploads') + '</a>').html_safe
else
contribute_action = ('<a href="'+ OrbitHelper.url_to_show(application_form.to_param) + '?method=con_login">' + t('application_form_signup.con_login') + '</a>').html_safe
end
else
contribute_action = ('<a href="'+ OrbitHelper.url_to_show(application_form.to_param) + '?method=con_login">' + t('application_form_signup.con_login') + '</a>').html_safe
end
end
{
'application_form' => application_form,
'sign_up' => sign_up,
'contribute_action' => contribute_action,
'time_now' => time_now,
'contribute_time_range' => ApplicationFormMain.time_range(application_form.contribute_start_date, application_form.contribute_end_date),
2022-05-21 13:48:39 +00:00
'sign_up_time_range' => ApplicationFormMain.time_range(application_form.application_form_start_date, application_form.application_form_end_date),
2022-03-10 02:11:18 +00:00
'application_form_time_range' => ApplicationFormMain.time_range(application_form.application_form_start_date, application_form.application_form_end_date)
}
end
def show
params = OrbitHelper.params
module_app = ModuleApp.where(:key => "application_form").first
categories = module_app.categories
2022-10-24 08:34:14 +00:00
application_form = ApplicationFormMain.where(uid: params[:uid].to_s).first
2022-03-10 02:11:18 +00:00
application_form_signup = ApplicationFormSignup.new
time_now = Time.now
{
"application_form" => application_form,
"application_form_signup" => application_form_signup,
"time_now" => time_now
}
end
def check_email
params = OrbitHelper.params
if !params[:email].blank?
count = ApplicationFormSignup.where(:email => params[:email], :application_form_main_id => params[:no]).count
result = count > 0 ? t('application_form.already_used') : t('application_form.available')
else
result = t('application_form.please_enter_email')
end
{
"result" => result
}
end
def check_availability
params = OrbitHelper.params
response = {}
case params[:type]
when "application_form_signup_email"
response["success"] = ApplicationFormSignup.where(:email => params[:value], :application_form_main_id => params[:no]).count > 0 ? false : true
end
render :json => response.to_json
end
def render_404
render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => 404, :formats => [:html]
end
def agree_link
signup = ApplicationFormSignup.find(params[:id]) rescue nil
stage_num = signup ? signup.get_stage_num(params[:cipher]) : nil
2022-06-14 14:21:43 +00:00
@error_message = nil
if stage_num.nil?
2022-06-14 14:21:43 +00:00
@error_message = I18n.t('application_form.this_link_has_expired')
else
@type = params[:type]
application_form = signup.application_form_main
@application_form = application_form
form_params_main_id = application_form.id
extra_text = "<br>#{I18n.t('application_form_signup.serial_number')}: #{signup.display_serial_number}"
extra_text += render_to_string("application_forms/signup_email_contents",:locals=>{:application_form=>application_form,
:application_form_signup=>signup},:layout=>false)
signup.agree_reviewer_ids[stage_num.to_s] = params[:reviewer]
signup.agree_reviewer_times[stage_num.to_s] = Time.now
signup.save
if params[:type] == 'agree'
if stage_num == application_form.get_max_stage
signup.update(:review_status => 2)
signup.clean_cipher
@type = 'finish'
mail_to = [signup.email]
extra_email = MemberProfile.find(application_form.organizer_id).email rescue nil
if extra_email
mail_to << extra_email
end
send_mail('edit_file', mail_to, form_params_main_id,extra_text)
else
offset = application_form.reviewer_enables[(stage_num+1)..-1].index(true)
new_stage = stage_num + 1
new_stage += offset if offset
signup.update_process_stage(new_stage)
host_url = Site.first.root_url
if host_url == "http://"
host_url = request.protocol + request.host_with_port
end
agree_link = host_url + Rails.application.routes.url_helpers.xhr_application_forms_agree_link_path(:locale=>I18n.locale, :id=>signup.id.to_s, :cipher=>signup.get_cipher_stage(signup.process_stage))
id_with_email = signup.get_reviewer_email
id_with_email.each do |id, email|
send_mail('submission', email, form_params_main_id,extra_text, {'agree_link'=>agree_link + "&reviewer=#{id}"})
end
end
else
mail_to = [signup.email]
extra_email = MemberProfile.find(application_form.organizer_id).email rescue nil
if extra_email
mail_to << extra_email
end
signup.update(:review_status => 1)
signup.clean_cipher
send_mail('add_file', mail_to, form_params_main_id,extra_text, {'signup_id'=>signup.id})
end
end
end
2022-03-10 02:11:18 +00:00
def create
form_params = params[:application_form_signup]
form_params_email = form_params[:email]
2022-10-24 08:34:14 +00:00
form_params_main_id = form_params[:application_form_main_id].to_s
2022-06-14 14:21:43 +00:00
@signup = nil #ApplicationFormSignup.where(email: form_params_email, application_form_main_id: form_params_main_id ).first
2022-03-10 02:11:18 +00:00
@application_form = ApplicationFormMain.where(id: form_params_main_id).first
email_regex = @application_form.get_email_regex
2022-05-21 13:48:39 +00:00
@application_form_signup = ApplicationFormSignup.new(application_form_signup_params)
@application_form_signup.ip = request.remote_ip
@application_form_signup.application_form_main = @application_form
2022-03-10 02:11:18 +00:00
if @application_form.application_form_signup_field_sets.count!=0
flag = @application_form.application_form_signup_field_sets.select{|v| v.field_name=='recaptcha'}[0].disabled
else
flag = false
end
verification_success = true
unless flag
if gotcha_valid?
flag = true
else
verification_success = false
end
end
email_valid = true
if email_regex
email_valid = !(::Regexp.new(email_regex).match(form_params_email.to_s).nil?)
unless email_valid
flag = false
end
end
referer_url = params[:referer_url].to_s
org_params = CGI.parse(referer_url.split('?')[1].to_s)
referer_url = referer_url.split("?")[0]
org_params.delete("notice")
notice = ''
begin
if flag
2022-03-10 02:11:18 +00:00
if @signup.blank? && @application_form_signup.save
# if gotcha_valid? && @application_form_signup.save
if !params[:application_form_signup_values].nil?
application_form_signup_values_params.each_with_index do |r,i|
field_value = r.last[:id].present?
@custom_field_value = ApplicationFormSignupValue.put_field_values(@application_form_signup, r.last, r.last[:application_form_signup_field_id], field_value)
end
application_form_reviews = ApplicationFormReview.where(:application_form_main_id=>@application_form.id).to_a
application_form_reviews.each{|sr| sr.save}
@application_form = @application_form_signup.application_form_main
unassigned_application_form_signup_ids = @application_form.application_form_signup_ids.map{|s| s.to_s}
unassigned_application_form_signup_ids.push(@application_form_signup.id.to_s)
application_form_reviews = ApplicationFormReview.where(:application_form_main_id=>@application_form.id).to_a
application_form_reviews.each do |sr|
unassigned_application_form_signup_ids = unassigned_application_form_signup_ids - sr.all_application_form_signup_ids
end
@application_form.unassigned_application_form_signup_ids << @application_form_signup.id.to_s
@application_form.unassigned_mode_1_application_form_signup_ids << @application_form_signup.id.to_s
@application_form.save
else
@application_form.unassigned_application_form_signup_ids << @application_form_signup.id.to_s
@application_form.unassigned_mode_1_application_form_signup_ids << @application_form_signup.id.to_s
@application_form.save
end
extra_text = "<br>#{I18n.t('application_form_signup.serial_number')}: #{@application_form_signup.display_serial_number}"
extra_text += render_to_string("application_forms/signup_email_contents",:locals=>{:application_form=>@application_form,
:application_form_signup=>@application_form_signup},:layout=>false)
send_mail('signup', form_params_email, form_params_main_id, extra_text)
host_url = ""
if request.referer.match('//'+request.host).nil?
host_url = request.protocol + request.host_with_port
2022-03-10 02:11:18 +00:00
else
host_url = request.referer.match(/http(s|):\/\/[^\/]+/)[0]
2022-03-10 02:11:18 +00:00
end
agree_link = host_url + Rails.application.routes.url_helpers.xhr_application_forms_agree_link_path(:locale=>I18n.locale, :id=>@application_form_signup.id.to_s, :cipher=>@application_form_signup.get_cipher_stage(1))
id_with_email = @application_form_signup.get_reviewer_email
id_with_email.each do |id, email|
send_mail('submission', email , form_params_main_id,extra_text, {'agree_link'=>agree_link + "&reviewer=#{id}"})
end
redirect_to "#{referer_url}/?method=signup_ok&serial_number=#{@application_form_signup.display_serial_number}" and return
2022-03-10 02:11:18 +00:00
else
if !@signup.blank?
notice = I18n.t('application_form.mail_exist')
2022-03-10 02:11:18 +00:00
end
end
end
if !email_valid
notice = t('application_form.please_check_email_format')
elsif !verification_success
notice = t('recaptcha.errors.verification_failed')
end
org_params['notice'] = notice
referer_url += "?#{org_params.to_query}"
redirect_to referer_url, :notice => notice
rescue => e
render :html => [e.to_s, e.backtrace].to_s
end
2022-03-10 02:11:18 +00:00
end
def signup_ok
params = OrbitHelper.params
{"serial_number"=> params[:serial_number]}
end
def add_file_proc
update_params = application_form_signup_contribute_params.merge('application_form_submission_values'=>params['application_form_submission_values'])
flag = true
update_params.permit!
if !update_params['application_form_submission_values'].nil?
if update_params['application_form_submission_values']['0']['value'].class==String
value = update_params['application_form_submission_values']['0']['value']
if !value.to_s.blank?
flag = false
end
else
update_params['application_form_submission_values']['0']['value'].each do |key,value|
if !value.to_s.blank?
flag = false
end
end
end
else
flag = false
end
if flag
update_params['application_form_submission_values']['0']['value']['en'] = ' '
end
@con = ApplicationFormSignupContribute.new(update_params)
if @con.save
signup = ApplicationFormSignup.where(id:update_params['application_form_signup_id']).first
application_form_id = signup.application_form_main_id
@application_form = ApplicationFormMain.where(id:application_form_id).first
send_mail('add_file',signup.email,application_form_id)
application_form_reviews = ApplicationFormReview.where(:application_form_main_id=>signup.application_form_main_id).to_a
application_form_reviews.each{|sr| sr.save}
@application_form = signup.application_form_main
unassigned_application_form_signup_ids = @application_form.application_form_signup_ids.map{|s| s.to_s}
@application_form.application_form_reviews.each do |sr|
unassigned_application_form_signup_ids = unassigned_application_form_signup_ids - sr.all_application_form_signup_ids
end
@application_form.unassigned_application_form_signup_ids = unassigned_application_form_signup_ids
@application_form.save
redirect_to "#{params[:referer_url]}/?method=con_upload"
else
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
end
end
def update
@con = ApplicationFormSignupContribute.find(params[:application_form_signup_contribute][:id])
update_params = application_form_signup_contribute_params.merge('application_form_submission_values'=>params['application_form_submission_values'])
flag = true
update_params.permit!
if update_params['application_form_submission_values']['0']['value'].class==String
value = update_params['application_form_submission_values']['0']['value']
if !value.to_s.blank?
flag = false
end
else
update_params['application_form_submission_values']['0']['value'].each do |key,value|
if !value.to_s.blank?
flag = false
end
end
end
if flag
update_params['application_form_submission_values']['0']['value']['en'] = ' '
end
@con.update_attributes(update_params)
if @con.save
signup = ApplicationFormSignup.where(id:update_params['application_form_signup_id']).first
application_form_id = signup.application_form_main_id
@application_form = ApplicationFormMain.where(id:application_form_id).first
send_mail('edit_file',signup.email,application_form_id)
application_form_reviews = ApplicationFormReview.where(:application_form_main_id=>signup.application_form_main_id).to_a
application_form_reviews.each{|sr| sr.save}
@application_form = signup.application_form_main
unassigned_application_form_signup_ids = @application_form.application_form_signup_ids.map{|s| s.to_s}
@application_form.application_form_reviews.each do |sr|
unassigned_application_form_signup_ids = unassigned_application_form_signup_ids - sr.all_application_form_signup_ids
end
@application_form.unassigned_application_form_signup_ids = unassigned_application_form_signup_ids
@application_form.save
redirect_to "#{params[:referer_url]}/?method=con_upload"
else
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
end
end
def del_file
con = ApplicationFormSignupContribute.find(params[:con_no])
# application_form_signup = ApplicationFormSignup.find_by(_id: con.application_form_signup_id )
# application_form = ApplicationFormMain.find_by(_id: application_form_signup.application_form_main_id )
signup = con.application_form_signup
con.destroy
application_form_reviews = ApplicationFormReview.where(:application_form_main_id=>signup.application_form_main_id).to_a
application_form_reviews.each{|sr| sr.save}
@application_form = ApplicationFormMain.find(signup.application_form_main_id)
unassigned_application_form_signup_ids = @application_form.application_form_signup_ids.map{|s| s.to_s}
@application_form.application_form_reviews.each do |sr|
unassigned_application_form_signup_ids = unassigned_application_form_signup_ids - sr.all_application_form_signup_ids
end
@application_form.unassigned_application_form_signup_ids = unassigned_application_form_signup_ids
@application_form.save
redirect_to "#{params[:referer_url]}/?method=con_upload"
end
def add_file
if !@@session[:application_form_main_id].blank?
application_form = ApplicationFormMain.find_by(id: @@session[:application_form_main_id])
application_form_signup = ApplicationFormSignup.find_by(_id: @@session[:application_form_signup_id], application_form_main_id: @@session[:application_form_main_id] )
else
application_form = {}
application_form_signup = {}
end
con = ApplicationFormSignupContribute.new
{
'con' => con,
'application_form' => application_form,
'application_form_signup' => application_form_signup
}
end
def edit_file
params = OrbitHelper.params
if !@@session[:application_form_main_id].blank?
application_form = ApplicationFormMain.find_by(id: @@session[:application_form_main_id])
application_form_signup = ApplicationFormSignup.find_by(_id: @@session[:application_form_signup_id], application_form_main_id: @@session[:application_form_main_id] )
else
application_form = {}
application_form_signup = {}
end
con = ApplicationFormSignupContribute.find(params[:con_no])
{
'con' => con,
'application_form' => application_form,
'application_form_signup' => application_form_signup
}
end
def con_upload
time_now = Time.now
if !@@session[:application_form_main_id].blank?
application_form = ApplicationFormMain.find_by(id: @@session[:application_form_main_id])
application_form_signup = ApplicationFormSignup.find_by(_id: @@session[:application_form_signup_id], application_form_main_id: @@session[:application_form_main_id] ) rescue nil
else
application_form = {}
application_form_signup = {}
end
{
'time_now' => time_now,
'application_form' => application_form,
'application_form_signup' => application_form_signup
}
end
def con_logout
# redirect_to page_for_application_form_url
end
def con_login
time_now = Time.now
params = OrbitHelper.params
2022-10-24 08:34:14 +00:00
application_form = ApplicationFormMain.find_by(uid: params[:uid].to_s)
2022-03-10 02:11:18 +00:00
{
'application_form' => application_form,
'time_now' => time_now
}
end
def con_login_proc
2022-10-24 08:34:14 +00:00
application_form_main_id = params[:application_form_signup][:application_form_main_id].to_s
application_form = ApplicationFormMain.find_by(id: application_form_main_id)
2022-03-10 02:11:18 +00:00
2022-10-24 08:34:14 +00:00
@application_form_signup = ApplicationFormSignup.where(:status=>'C', :email=> params[:user_name], :password => params[:password], :application_form_main_id => application_form_main_id).first
2022-03-10 02:11:18 +00:00
if !@application_form_signup.blank?
session[:application_form_signup_id] = @application_form_signup.id
session[:application_form_main_id] = @application_form_signup.application_form_main_id
redirect_to "#{params[:referer_url]}/?method=con_upload"
else
redirect_to "#{params[:referer_url]}/?method=con_login", :notice => '登入失敗'
end
end
def application_form_signup_params
2022-05-21 13:48:39 +00:00
tmp = params.require(:application_form_signup).permit!
tmp['reviewer_ids_list'] = (0..@application_form.reviewer_enables.rindex(true)).map{|k| Array((tmp['reviewer_ids_list'][k.to_s] rescue []))}
2022-05-21 13:48:39 +00:00
tmp
2022-03-10 02:11:18 +00:00
end
def application_form_signup_contribute_params
params.require(:application_form_signup_contribute).permit!
end
def application_form_signup_values_params
params.require(:application_form_signup_values).permit!
end
def send_mail(field_name,email,application_form_id,extra_text="", extra_data={})
return if email.blank?
@application_form = ApplicationFormMain.find(application_form_id) if @application_form.nil?
2022-03-10 02:11:18 +00:00
email_set = @application_form.application_form_email_sets.select{|v| v.field_name == field_name}
if email_set.length==0
mail = Email.create(mail_to:Array(email),
2022-03-10 02:11:18 +00:00
module_app_key:"application_form",
template:"email/#{field_name}_email.html.erb",
mail_sentdate:Time.current,
mail_subject: t("application_form.email_#{field_name}_success"),
template_data:{'application_form_id'=>application_form_id,'locale'=>I18n.locale,'extra_text'=> extra_text}.merge(extra_data),
mail_lang: I18n.locale)
2022-03-10 02:11:18 +00:00
elsif !(email_set[0].disabled)
mail = Email.create(mail_to:Array(email),
2022-03-10 02:11:18 +00:00
module_app_key:"application_form",
template:"email/#{field_name}_email.html.erb",
mail_sentdate:Time.current,
mail_subject: email_set[0].title[I18n.locale],
template_data:{'application_form_id'=>application_form_id,'locale'=>I18n.locale,'extra_text'=> extra_text}.merge(extra_data),
mail_lang: I18n.locale)
2022-03-10 02:11:18 +00:00
end
mail.save
2022-03-10 02:11:18 +00:00
end
end