seminar2/app/controllers/seminars_controller.rb

964 lines
38 KiB
Ruby
Raw Normal View History

2016-06-29 06:57:45 +00:00
class SeminarsController < ApplicationController
helper MemberHelper
2021-06-17 10:07:43 +00:00
include MemberHelper
include ActionView::Context #vary important (only add this can access @@session from view)
2016-06-29 06:57:45 +00:00
include Admin::SeminarsHelper
FrontendMethods = ["show_privacy", "show_data", "check_email", "check_availability", "signup_ok", "add_file", "edit_file", "con_login", "con_upload", "con_logout","confirm_email_page","reset_password_page","edit_login_seminar_signup"]
# include SimpleCaptcha::ControllerHelpers
2016-06-29 06:57:45 +00:00
def index
time_now = Time.now
2023-10-04 16:38:24 +00:00
2020-01-22 13:52:32 +00:00
seminars = SeminarMain.all.desc(:seminar_start_date).filter_by_categories
2016-06-29 06:57:45 +00:00
{
"seminars" => seminars,
'time_now' => time_now,
"total_pages" => seminars.total_pages
2023-10-04 16:38:24 +00:00
}
2016-06-29 06:57:45 +00:00
end
def widget
cats = OrbitHelper.widget_categories || []
widget_data_count = OrbitHelper.widget_data_count
seminars = SeminarMain.all.desc(:seminar_start_date).filter_by_categories(cats)
time_now = DateTime.now
session = OrbitHelper.request.session
seminars = seminars.map do |seminar|
2023-01-11 09:44:40 +00:00
registration_is_open = seminar.registration_status.present?
2023-04-12 03:33:32 +00:00
sign_up_not_yet = seminar.signup_start_date && time_now && seminar.signup_start_date > time_now
sign_up_overdue = seminar.signup_end_date && time_now && (seminar.signup_end_date + 1.day <= time_now)
2023-01-11 09:46:06 +00:00
signup_is_full = seminar.signup_is_full?
2023-05-12 00:01:49 +00:00
seminar_url = (@prefix_url ? @prefix_url : OrbitHelper.url_to_plugin_show(seminar.to_param, 'seminar'))
2023-01-11 09:44:40 +00:00
if !registration_is_open
sign_up = t('seminar.sign_up_not_open')
elsif sign_up_not_yet
sign_up = t('seminar.sign_up_not_yet')
elsif sign_up_overdue
sign_up = t('seminar.sign_up_overdue')
2023-01-11 09:46:06 +00:00
elsif signup_is_full
sign_up = t('seminar.sign_up_is_full')
else
2023-01-11 09:44:40 +00:00
sign_up_text = t('seminar.signup')
2023-05-12 00:01:49 +00:00
sign_up = link_to(sign_up_text, seminar.get_frontend_url(seminar_url), :target=>'_blank', :title=>sign_up_text)
end
if !seminar.registration_status.blank? && seminar.registration_status.include?('C') && (seminar.contribute_start_date <= time_now rescue false) && ( seminar.contribute_end_date.nil? || (seminar.contribute_end_date+1 >= time_now rescue false) )
2023-01-11 09:44:40 +00:00
sign_up += content_tag :span, :style=> "margin-left: 1em;" do
if session[:seminar_signup_id].present? && session[:seminar_main_id] == seminar.id
button_text = t('seminar_signup.uploads')
2023-05-12 00:01:49 +00:00
link_to(button_text, seminar.get_frontend_url(seminar_url, :con_upload), {:title=>button_text})
else
2023-01-11 09:44:40 +00:00
button_text = t('seminar_signup.con_login')
2023-05-12 00:01:49 +00:00
link_to(button_text, seminar.get_frontend_url(seminar_url, :con_login), {:title=>button_text})
end
end
end
files = seminar.seminar_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } } rescue []
2023-01-11 09:44:40 +00:00
links = seminar.seminar_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title rescue '') } } rescue []
{"title" => seminar.title,
"subtitle" => sign_up,
"category" => (seminar.category.title rescue ""),
2023-05-12 00:01:49 +00:00
"link_to_show" => (OrbitHelper.instance_variable_get(:@url_to_plugin_show_blank) ? 'javascript:void(0)' : seminar.get_frontend_url(seminar_url, :show_data)),
"postdate" => seminar.seminar_start_date,
"statuses" => {},
"bulletin_links" => links,
"bulletin_files" => files
}
end
{
"seminars" => seminars,
"extras" => {
"date-head" => I18n.t("seminar.seminar_start_date"),
"category-head" => I18n.t(:category),
"title-head" => I18n.t("seminar.title")
}
}
end
2021-06-17 10:07:43 +00:00
def custom_frontend_data
params = OrbitHelper.params
seminar = SeminarMain.find_by(:uid=>params[:uid])
@seminar = seminar
2021-07-14 07:42:37 +00:00
@site_in_use_locales = Site.first.in_use_locales rescue I18n.available_locales
2021-06-17 10:07:43 +00:00
seminar_template_setting = seminar.seminar_template_setting
2021-11-30 01:57:52 +00:00
@seminar_template_setting = seminar_template_setting
2021-06-17 10:07:43 +00:00
home_page = Page.where(:parent_page_id=>seminar.id).first
2022-04-14 04:42:39 +00:00
OrbitHelper.set_page(home_page) rescue nil
2021-06-17 10:07:43 +00:00
prefix_url = OrbitHelper.request.path.split("-").first + "-#{params[:uid]}"
@prefix_url = prefix_url
2022-04-14 04:42:39 +00:00
@registration_postfix = "/home/registration"
2023-10-04 16:38:24 +00:00
header_data = "<a href=\"#{prefix_url}#{home_page.url}\">Home</a> | " +
2021-06-17 10:07:43 +00:00
"<a href=\"/\">Main Site</a>"
content_style = seminar_template_setting.content_style
background_style = seminar_template_setting.background_style
background_style_info = SeminarTemplateSetting.background_style_infos[background_style].to_h
content_style_info = SeminarTemplateSetting.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"]
2021-07-14 04:57:47 +00:00
template_info = content_style_info["info"]
2021-06-17 10:07:43 +00:00
custom_footer = seminar_template_setting.footer_info
2021-10-26 14:01:36 +00:00
if seminar_template_setting.seminar_banner_images.count != 0 || background_style_info["default_logo"]
2021-06-17 10:07:43 +00:00
banner_title = seminar.title
external_link = prefix_url + "/home"
2021-10-26 14:01:36 +00:00
images = []
if seminar_template_setting.seminar_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 = seminar_template_setting.seminar_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
2021-06-17 10:07:43 +00:00
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[:seminar_main_id] = @seminar.id
if params[:method].present?
main_content = render_other_method
elsif params[:current_page_module] == "seminars_home"
seminar = SeminarMain.where(uid: params[:uid]).first
time_now = Time.now
data = {
"seminar" => seminar,
"time_now" => time_now
}
@_request = OrbitHelper.request
2022-04-14 05:07:15 +00:00
@registration_postfix = ""
2021-07-14 04:57:47 +00:00
if template_info["main_content"]
main_content = render_other_method("show_data",template_info["main_content"])
else
main_content = render_to_string("seminars/custom_home",:locals=>{:seminar=>seminar,
2021-06-17 10:07:43 +00:00
:params=>params,:session=>OrbitHelper.request.session},:layout=>false)
2021-07-14 04:57:47 +00:00
end
2021-06-17 10:07:43 +00:00
elsif params[:current_page_module] == "seminars_page"
time_now = Time.now
params = OrbitHelper.params
seminar = SeminarMain.find_by(uid: params[:uid])
2022-06-08 14:22:24 +00:00
registration_url = prefix_url + @registration_postfix
submission_url = prefix_url + '/home/submission'
2021-06-17 10:07:43 +00:00
if !seminar.registration_status.blank? && seminar.signup_start_date <= time_now && ( seminar.signup_end_date.nil? || seminar.signup_end_date+1 >= time_now )
2022-06-08 14:22:24 +00:00
sign_up = ('<a href="'+ registration_url + '" target="_blank">' + t('seminar.signup') + '</a>').html_safe
2021-06-17 10:07:43 +00:00
elsif seminar.registration_status.blank?
sign_up = t('seminar.sign_up_not_open')
elsif seminar.signup_start_date > time_now
sign_up = t('seminar.sign_up_not_yet')
else
sign_up = t('seminar.sign_up_overdue')
end
if !seminar.registration_status.blank? && seminar.registration_status.include?('C') && seminar.contribute_start_date <= time_now && ( seminar.contribute_end_date.nil? || seminar.contribute_end_date+1 >= time_now )
2023-01-11 09:44:40 +00:00
if @@session[:seminar_signup_id].present? && @@session[:seminar_main_id] == seminar.id
button_text = t('seminar_signup.uploads')
contribute_action = link_to(button_text, submission_url + '?method=con_upload', :title=>button_text)
2021-06-17 10:07:43 +00:00
else
2023-01-11 09:44:40 +00:00
button_text = t('seminar_signup.con_login')
contribute_action = link_to(button_text, submission_url + '?method=con_login', :title=>button_text)
2021-06-17 10:07:43 +00:00
end
end
data = {
'seminar' => seminar,
'sign_up' => sign_up,
'contribute_action' => contribute_action,
'time_now' => time_now,
'contribute_time_range' => SeminarMain.time_range(seminar.contribute_start_date, seminar.contribute_end_date),
'sign_up_time_range' => SeminarMain.time_range(seminar.signup_start_date, seminar.signup_end_date),
'seminar_time_range' => SeminarMain.time_range(seminar.seminar_start_date, seminar.seminar_end_date)
}
@_request = OrbitHelper.request
main_content = render_to_string("seminars/show_data",:locals=>{:action_data=>data,
:request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
:params=>params,:session=>OrbitHelper.request.session},:layout=>false)
else
2021-11-30 01:57:52 +00:00
main_content = render_other_method("render_"+params[:current_page_module]) rescue nil
2021-06-17 10:07:43 +00:00
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
2022-03-24 03:47:15 +00:00
return {
"extra_body_class" => "seminar_custom_page background_style_#{background_style} content_style_#{content_style}",
"main_content"=>main_content,
2021-06-17 10:07:43 +00:00
"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_seminar_registration
action_data = show
@_request = OrbitHelper.request
action_data["prefix_url"] = @prefix_url
render_to_string("seminars/show",:locals=>{:action_data=>action_data,
:request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
:params=>params,:session=>OrbitHelper.request.session},:layout=>false)
end
2021-11-30 01:57:52 +00:00
def render_seminar_registered_participants
action_data = {"seminar"=>@seminar, "seminar_template_setting"=>@seminar_template_setting}
@_request = OrbitHelper.request
action_data["prefix_url"] = @prefix_url
render_to_string("seminars/registered_participants",:locals=>{:action_data=>action_data,
:request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
:params=>params,:session=>OrbitHelper.request.session},:layout=>false)
end
2021-07-14 04:57:47 +00:00
def render_other_method(render_method=nil,render_template=nil)
params = OrbitHelper.params
2021-11-30 01:57:52 +00:00
if render_method && render_template.nil?
2023-05-12 00:01:49 +00:00
return self.send(render_method)
2021-11-30 01:57:52 +00:00
end
2021-07-14 04:57:47 +00:00
render_method = render_method || params[:method]
render_template = render_template || render_method
2021-06-17 10:07:43 +00:00
params = OrbitHelper.params
2023-05-12 00:01:49 +00:00
action_data = self.send(render_method)
2021-06-17 10:07:43 +00:00
@seminar_main_url = @prefix_url + '/home/introduction'
if action_data
2021-07-14 04:57:47 +00:00
if render_method == "con_upload" || render_method == "signup_ok"
2021-06-17 10:07:43 +00:00
action_data["prefix_url"] = @prefix_url + '/home/submission'
else
action_data["prefix_url"] = @prefix_url
end
end
@_request = OrbitHelper.request
2021-07-14 04:57:47 +00:00
render_to_string("seminars/#{render_template}",:locals=>{:action_data=>action_data,
2021-06-17 10:07:43 +00:00
:request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
:params=>params,:session=>OrbitHelper.request.session},:layout=>false).html_safe
end
def render_seminar_submission
if @@session[:seminar_signup_id]
action_data = con_upload
action_data["prefix_url"] = @prefix_url + '/home/submission'
@_request = OrbitHelper.request
render_to_string("seminars/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("seminars/con_login",:locals=>{:action_data=>action_data,
:request=>OrbitHelper.request,:flash=>OrbitHelper.request.flash,
:params=>params,:session=>@@session},:layout=>false).html_safe
end
end
2023-01-11 09:44:40 +00:00
def get_referer_url_for_notice(notice_words)
referer_url = params[:referer_url].to_s
split_path = referer_url.split("/")
last_path = split_path.last
if last_path.include?("?")
referer_url = split_path[0...-1].join('/') + '/' + last_path.split('?')[0]
uri_query = last_path.split("?")[1..-1].join('?')
2023-10-10 14:49:16 +00:00
uri_query = uri_query.gsub(/notice=[^&]*/,'').gsub(/&+$/,'')
2023-01-11 09:44:40 +00:00
if uri_query.blank?
referer_url = referer_url + "?notice=#{notice_words}"
else
referer_url = referer_url + "?#{uri_query}&notice=#{notice_words}"
end
else
referer_url = referer_url + "?notice=#{notice_words}"
end
end
2016-06-29 06:57:45 +00:00
def show_privacy
params = OrbitHelper.params
seminar = SeminarMain.where(uid: params[:uid]).first
2016-06-29 06:57:45 +00:00
seminar_agreement = SeminarAgreement.first
{
'seminar' => seminar,
"seminar_agreement" => seminar_agreement
}
end
def show_data
time_now = Time.now
params = OrbitHelper.params
seminar = SeminarMain.find_by(uid: params[:uid])
2023-01-11 09:44:40 +00:00
registration_is_open = seminar.registration_status.present?
2023-04-12 03:33:32 +00:00
sign_up_not_yet = seminar.signup_start_date && time_now && seminar.signup_start_date > time_now
sign_up_overdue = seminar.signup_end_date && time_now && (seminar.signup_end_date + 1.day <= time_now)
2023-01-11 09:46:06 +00:00
signup_is_full = seminar.signup_is_full?
2023-05-12 00:01:49 +00:00
seminar_url = (@prefix_url ? @prefix_url : OrbitHelper.url_to_show(seminar.to_param))
2023-01-11 09:44:40 +00:00
if !registration_is_open
2016-06-29 06:57:45 +00:00
sign_up = t('seminar.sign_up_not_open')
2023-01-11 09:44:40 +00:00
elsif sign_up_not_yet
2016-06-29 06:57:45 +00:00
sign_up = t('seminar.sign_up_not_yet')
2023-01-11 09:44:40 +00:00
elsif sign_up_overdue
2016-06-29 06:57:45 +00:00
sign_up = t('seminar.sign_up_overdue')
2023-01-11 09:46:06 +00:00
elsif signup_is_full
sign_up = t('seminar.sign_up_is_full')
2023-01-11 09:44:40 +00:00
else
sign_up_text = t('seminar.signup')
sign_up = link_to(sign_up_text, seminar.get_frontend_url(seminar_url), :target=>'_blank', :title=>sign_up_text)
2016-06-29 06:57:45 +00:00
end
if !seminar.registration_status.blank? && seminar.registration_status.include?('C') && seminar.contribute_start_date <= time_now && ( seminar.contribute_end_date.nil? || seminar.contribute_end_date+1 >= time_now )
2023-01-11 09:44:40 +00:00
if @@session[:seminar_signup_id].present? && @@session[:seminar_main_id] == seminar.id
button_text = t('seminar_signup.uploads')
contribute_action = link_to(button_text, seminar.get_frontend_url(seminar_url, :con_upload), :title=>button_text)
2016-06-29 06:57:45 +00:00
else
2023-01-11 09:44:40 +00:00
button_text = t('seminar_signup.con_login')
contribute_action = link_to(button_text, seminar.get_frontend_url(seminar_url, :con_login), :title=>button_text)
2016-06-29 06:57:45 +00:00
end
end
{
'seminar' => seminar,
'sign_up' => sign_up,
'contribute_action' => contribute_action,
'time_now' => time_now,
'contribute_time_range' => SeminarMain.time_range(seminar.contribute_start_date, seminar.contribute_end_date),
'sign_up_time_range' => SeminarMain.time_range(seminar.signup_start_date, seminar.signup_end_date),
'seminar_time_range' => SeminarMain.time_range(seminar.seminar_start_date, seminar.seminar_end_date)
}
end
def show
params = OrbitHelper.params
module_app = ModuleApp.where(:key => "seminar").first
categories = module_app.categories
seminar = SeminarMain.where(uid: params[:uid]).first
2016-06-29 06:57:45 +00:00
seminar_signup = SeminarSignup.new
2023-10-10 14:49:16 +00:00
time_now = Time.now
referer_url = OrbitHelper.request.referer
if (referer_url.nil? || referer_url.match(/(\?|&)method=show_privacy/).nil?) && !OrbitHelper.request.params[:notice]
2023-10-10 14:49:16 +00:00
return {
"seminar" => seminar,
"seminar_signup" => seminar_signup,
"time_now" => time_now,
"redirect_to" => "#{OrbitHelper.url_to_show(seminar.to_param)}?method=show_privacy"
}
end
2016-06-29 06:57:45 +00:00
{
"seminar" => seminar,
"seminar_signup" => seminar_signup,
"time_now" => time_now
}
end
def check_email
params = OrbitHelper.params
2023-10-10 02:14:57 +00:00
success = true
2023-10-04 16:38:24 +00:00
if !params[:email].blank?
2016-06-29 06:57:45 +00:00
count = SeminarSignup.where(:email => params[:email], :seminar_main_id => params[:no]).count
result = count > 0 ? t('seminar.already_used') : t('seminar.available')
2023-10-10 02:14:57 +00:00
success = count > 0 ? false : true
2016-06-29 06:57:45 +00:00
end
2023-10-10 02:14:57 +00:00
render :json => {
"result" => result,
"success" => success
}.to_json
2016-06-29 06:57:45 +00:00
end
def check_availability
params = OrbitHelper.params
response = {}
case params[:type]
when "seminar_signup_email"
response["success"] = SeminarSignup.where(:email => params[:value], :seminar_main_id => params[:no]).count > 0 ? false : true
end
render :json => response.to_json
end
def create
2023-10-15 15:21:00 +00:00
OrbitHelper.set_page(nil)
2023-10-10 14:49:16 +00:00
referer_url = request.referer
if referer_url
params[:url] = URI.parse(referer_url).path.sub(/\/[^\/]*$/, '').sub(/^\/#{I18n.locale}/, '')
end
OrbitHelper.set_params(params, current_user)
2023-01-11 09:44:40 +00:00
seminar_id = params[:seminar_signup][:seminar_main_id]
@seminar = SeminarMain.where(id: seminar_id).first
if @seminar.enable_recaptcha && (!gotcha_valid?)
notice_words = t('recaptcha.errors.verification_failed')
referer_url = get_referer_url_for_notice(notice_words)
show_alert(notice_words)
2023-01-11 09:44:40 +00:00
return
end
2023-01-11 09:46:06 +00:00
signup_limit = @seminar.signup_limit
has_counter = false
if signup_limit
if defined?(OrbitHelper::SharedMutex)
OrbitHelper::SharedMutex.synchronize do
signup_count = OrbitHelper::SharedHash['seminar'][:counter][seminar_id]
if signup_count.nil?
signup_count = SeminarSignup.where(:seminar_main_id=>@seminar.id).count
OrbitHelper::SharedHash['seminar'][:counter][seminar_id] = signup_count
end
if signup_limit > signup_count
OrbitHelper::SharedHash['seminar'][:counter][seminar_id] = signup_count + 1
has_counter = true
else
notice_words = t('seminar.sign_up_is_full')
referer_url = get_referer_url_for_notice(notice_words)
show_alert(notice_words)
2023-01-11 09:46:06 +00:00
return
end
end
else
signup_count = SeminarSignup.where(:seminar_main_id=>@seminar.id).count
if signup_limit <= signup_count
notice_words = t('seminar.sign_up_is_full')
referer_url = get_referer_url_for_notice(notice_words)
show_alert(notice_words)
2023-01-11 09:46:06 +00:00
return
end
end
end
2023-01-11 09:44:40 +00:00
@signup = SeminarSignup.where(email: params[:seminar_signup][:email], seminar_main_id: seminar_id ).first
2016-06-29 06:57:45 +00:00
@seminar_signup = SeminarSignup.new(seminar_signup_params)
2023-01-11 09:44:40 +00:00
not_signup_yet = @signup.blank?
if not_signup_yet && @seminar_signup.save
if !params[:seminar_signup_values].nil?
seminar_signup_values_params.each_with_index do |r,i|
field_value = r.last[:id].present?
@custom_field_value = SeminarSignupValue.put_field_values(@seminar_signup, r.last, r.last[:seminar_signup_field_id], field_value)
2016-08-04 08:25:40 +00:00
end
2023-01-11 09:44:40 +00:00
seminar_reviews = SeminarReview.where(:seminar_main_id=>@seminar.id).to_a
seminar_reviews.each{|sr| sr.save}
@seminar = @seminar_signup.seminar_main
unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s}
unassigned_seminar_signup_ids.push(@seminar_signup.id.to_s)
seminar_reviews = SeminarReview.where(:seminar_main_id=>@seminar.id).to_a
seminar_reviews.each do |sr|
unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids
end
2023-01-11 09:44:40 +00:00
@seminar.unassigned_seminar_signup_ids << @seminar_signup.id.to_s
@seminar.unassigned_mode_1_seminar_signup_ids << @seminar_signup.id.to_s
@seminar.save
2016-08-04 08:25:40 +00:00
else
2023-01-11 09:44:40 +00:00
@seminar.unassigned_seminar_signup_ids << @seminar_signup.id.to_s
@seminar.unassigned_mode_1_seminar_signup_ids << @seminar_signup.id.to_s
@seminar.save
2016-06-29 06:57:45 +00:00
end
2023-01-11 09:44:40 +00:00
extra_text = "<br>#{I18n.t('seminar_signup.serial_number')}: #{@seminar_signup.display_serial_number}"
# extra_text += render_to_string("seminars/signup_email_contents",:locals=>{:seminar=>@seminar, :seminar_signup=>@seminar_signup},:layout=>false)
2023-01-11 09:44:40 +00:00
if params['seminar_signup']['status']=='C'
status_param = '&status='
2023-10-04 16:38:24 +00:00
if(@seminar.seminar_email_sets.where(:field_name => "signup").first.is_confirmation)
extra_text += "<br><div><a href='#{request.protocol + request.host_with_port + OrbitHelper.url_to_show(@seminar.to_param)}?method=confirm_email_page&token=#{@seminar_signup.token}&cid=#{@seminar_signup.id.to_s}'>" + t("seminar.click_here_to_confirm") + "</a></div>"
end
send_mail('signup',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id],extra_text)
2023-01-11 09:44:40 +00:00
else
status_param = ''
if(@seminar.seminar_email_sets.where(:field_name => "signup").first.is_confirmation)
extra_text += "<br><div><a href='#{request.protocol + request.host_with_port + OrbitHelper.url_to_show(@seminar.to_param)}?method=confirm_email_page&token=#{@seminar_signup.token}&cid=#{@seminar_signup.id.to_s}'>" + t("seminar.click_here_to_confirm") + "</a></div>"
end
2023-01-11 09:44:40 +00:00
send_mail('signup',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id],extra_text)
end
redirect_with_js("#{params[:referer_url].to_s.chomp('/').gsub(/\/([^\/?#]+)(|[^\/]+)$/){|f| '/'+$1}}?method=signup_ok#{status_param}&serial_number=#{@seminar_signup.display_serial_number}&seminar=#{@seminar.uid}")
2020-01-12 06:39:32 +00:00
else
2023-01-11 09:46:06 +00:00
if has_counter
OrbitHelper::SharedMutex.synchronize do
OrbitHelper::SharedHash['seminar'][:counter][seminar_id] = OrbitHelper::SharedHash['seminar'][:counter][seminar_id] - 1
end
end
2023-01-11 09:44:40 +00:00
if !not_signup_yet
notice_words = t('seminar.email_exist')
referer_url = get_referer_url_for_notice(notice_words)
show_alert(notice_words)
2021-04-14 11:44:06 +00:00
else
2023-01-11 09:44:40 +00:00
notice_words = t('seminar.sign_up_failed')
referer_url = get_referer_url_for_notice(notice_words)
show_alert(notice_words)
2021-04-14 11:44:06 +00:00
end
2020-01-12 06:39:32 +00:00
end
2016-06-29 06:57:45 +00:00
end
def update_signup_form
2023-10-15 15:21:00 +00:00
OrbitHelper.set_page(nil)
referer_url = request.referer
if referer_url
params[:url] = URI.parse(referer_url).path.sub(/\/[^\/]*$/, '').sub(/^\/#{I18n.locale}/, '')
end
params = OrbitHelper.params
2023-10-10 14:49:16 +00:00
tmp_seminar_signup_params = seminar_signup_params
@seminar_signup = SeminarSignup.find(params[:signup_id])
2023-10-10 14:49:16 +00:00
@seminar_signup.update_attributes(tmp_seminar_signup_params)
@seminar_signup.generate_token
if !params[:seminar_signup_values].nil?
params[:seminar_signup_values].each_with_index do |r,i|
field_value = r.last[:id].present?
@custom_field_value = SeminarSignupValue.put_field_values(@seminar_signup, r.last, r.last[:id], field_value)
end
seminar_reviews = SeminarReview.where(:seminar_main_id=>@seminar_signup.seminar_main_id).to_a
seminar_reviews.each{|sr| sr.save}
@seminar = @seminar_signup.seminar_main
unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s}
@seminar.seminar_reviews.each do |sr|
unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids
end
@seminar.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids
@seminar.save
end
2023-10-10 14:49:16 +00:00
extra_text = "<br>#{I18n.t('seminar_signup.serial_number')}: #{@seminar_signup.display_serial_number}"
if tmp_seminar_signup_params['status']=='C'
status_param = '&status='
if(@seminar.seminar_email_sets.where(:field_name => "signup").first.is_confirmation)
extra_text += "<br><div><a href='#{request.protocol + request.host_with_port + OrbitHelper.url_to_show(@seminar.to_param)}?method=confirm_email_page&token=#{@seminar_signup.token}&cid=#{@seminar_signup.id.to_s}'>" + t("seminar.click_here_to_confirm") + "</a></div>"
end
send_mail('signup',tmp_seminar_signup_params[:email],tmp_seminar_signup_params[:seminar_main_id],extra_text)
else
status_param = ''
if(@seminar.seminar_email_sets.where(:field_name => "signup").first.is_confirmation)
extra_text += "<br><div><a href='#{request.protocol + request.host_with_port + OrbitHelper.url_to_show(@seminar.to_param)}?method=confirm_email_page&token=#{@seminar_signup.token}&cid=#{@seminar_signup.id.to_s}'>" + t("seminar.click_here_to_confirm") + "</a></div>"
end
send_mail('signup',tmp_seminar_signup_params[:email],tmp_seminar_signup_params[:seminar_main_id],extra_text)
end
redirect_with_js("#{params[:referer_url].to_s.chomp('/').gsub(/\/([^\/?#]+)(|[^\/]+)$/){|f| '/'+$1}}?method=signup_ok#{status_param}&serial_number=#{@seminar_signup.display_serial_number}&seminar=#{@seminar.uid}")
end
2016-06-29 06:57:45 +00:00
def signup_ok
2021-03-29 14:27:08 +00:00
params = OrbitHelper.params
msg = SeminarMain.where(:uid => params[:seminar]).first.signup_success
{
"serial_number"=> params[:serial_number],
"message" => msg
}
2016-06-29 06:57:45 +00:00
end
def add_file_proc
update_params = seminar_signup_contribute_params.merge('seminar_submission_values'=>params['seminar_submission_values'])
flag = true
update_params.permit!
2020-04-24 14:26:38 +00:00
if !update_params['seminar_submission_values'].nil?
if update_params['seminar_submission_values']['0']['value'].class==String
value = update_params['seminar_submission_values']['0']['value']
if !value.to_s.blank?
2019-11-28 04:39:36 +00:00
flag = false
end
2020-04-24 14:26:38 +00:00
else
update_params['seminar_submission_values']['0']['value'].each do |key,value|
if !value.to_s.blank?
flag = false
end
end
2019-11-28 04:39:36 +00:00
end
2020-04-24 14:26:38 +00:00
else
flag = false
end
if flag
update_params['seminar_submission_values']['0']['value']['en'] = ' '
end
@con = SeminarSignupContribute.new(update_params)
2016-06-29 06:57:45 +00:00
if @con.save
2020-01-12 06:39:32 +00:00
signup = SeminarSignup.where(id:update_params['seminar_signup_id']).first
seminar_id = signup.seminar_main_id
@seminar = SeminarMain.where(id:seminar_id).first
host_url = Site.first.root_url
if host_url == "http://"
host_url = request.protocol + request.host_with_port
end
extra_text = "<br>"+render_to_string("seminars/con_email_contents",:locals=>{:@seminar=>@seminar,
:@con=>@con,:@host_url=>host_url},:layout=>false)
send_mail('add_file',signup.email,seminar_id,extra_text)
seminar_reviews = SeminarReview.where(:seminar_main_id=>signup.seminar_main_id).to_a
seminar_reviews.each{|sr| sr.save}
@seminar = signup.seminar_main
unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s}
@seminar.seminar_reviews.each do |sr|
unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids
end
@seminar.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids
@seminar.save
2022-10-22 10:43:36 +00:00
redirect_to "#{params[:referer_url].to_s.chomp('/')}/?method=con_upload"
2016-06-29 06:57:45 +00:00
else
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
end
end
def update
@con = SeminarSignupContribute.find(params[:seminar_signup_contribute][:id])
update_params = seminar_signup_contribute_params.merge('seminar_submission_values'=>params['seminar_submission_values'])
update_params.permit!
2022-06-08 13:15:06 +00:00
unless update_params['seminar_submission_values'].nil?
flag = true
if update_params['seminar_submission_values']['0']['value'].class==String
value = update_params['seminar_submission_values']['0']['value']
if !value.to_s.blank?
flag = false
end
2022-06-08 13:15:06 +00:00
else
update_params['seminar_submission_values']['0']['value'].each do |key,value|
if !value.to_s.blank?
flag = false
end
end
end
if flag
update_params['seminar_submission_values']['0']['value']['en'] = ' '
end
end
@con.update_attributes(update_params)
2016-06-29 06:57:45 +00:00
if @con.save
2020-01-12 06:39:32 +00:00
signup = SeminarSignup.where(id:update_params['seminar_signup_id']).first
seminar_id = signup.seminar_main_id
@seminar = SeminarMain.where(id:seminar_id).first
host_url = Site.first.root_url
if host_url == "http://"
host_url = request.protocol + request.host_with_port
end
extra_text = "<br>"+render_to_string("seminars/con_email_contents",:locals=>{:@seminar=>@seminar,
:@con=>@con,:@host_url=>host_url},:layout=>false)
send_mail('edit_file',signup.email,seminar_id,extra_text)
seminar_reviews = SeminarReview.where(:seminar_main_id=>signup.seminar_main_id).to_a
seminar_reviews.each{|sr| sr.save}
@seminar = signup.seminar_main
unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s}
@seminar.seminar_reviews.each do |sr|
unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids
end
@seminar.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids
@seminar.save
2022-10-22 10:43:36 +00:00
redirect_to "#{params[:referer_url].to_s.chomp('/')}/?method=con_upload"
2016-06-29 06:57:45 +00:00
else
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
end
end
def del_file
con = SeminarSignupContribute.find(params[:con_no])
# seminar_signup = SeminarSignup.find_by(_id: con.seminar_signup_id )
# seminar = SeminarMain.find_by(_id: seminar_signup.seminar_main_id )
signup = con.seminar_signup
2016-06-29 06:57:45 +00:00
con.destroy
seminar_reviews = SeminarReview.where(:seminar_main_id=>signup.seminar_main_id).to_a
seminar_reviews.each{|sr| sr.save}
@seminar = SeminarMain.find(signup.seminar_main_id)
unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s}
@seminar.seminar_reviews.each do |sr|
unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids
end
@seminar.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids
@seminar.save
2022-10-22 10:43:36 +00:00
redirect_to "#{params[:referer_url].to_s.chomp('/')}/?method=con_upload"
2016-06-29 06:57:45 +00:00
end
def add_file
if !@@session[:seminar_main_id].blank?
2016-06-29 06:57:45 +00:00
seminar = SeminarMain.find_by(id: @@session[:seminar_main_id])
seminar_signup = SeminarSignup.find_by(_id: @@session[:seminar_signup_id], seminar_main_id: @@session[:seminar_main_id] )
2016-06-29 06:57:45 +00:00
else
seminar = {}
seminar_signup = {}
end
con = SeminarSignupContribute.new
{
'con' => con,
'seminar' => seminar,
'seminar_signup' => seminar_signup
}
end
def edit_file
params = OrbitHelper.params
if !@@session[:seminar_main_id].blank?
seminar = SeminarMain.find_by(id: @@session[:seminar_main_id])
seminar_signup = SeminarSignup.find_by(_id: @@session[:seminar_signup_id], seminar_main_id: @@session[:seminar_main_id] )
else
seminar = {}
seminar_signup = {}
end
2016-06-29 06:57:45 +00:00
con = SeminarSignupContribute.find(params[:con_no])
{
'con' => con,
'seminar' => seminar,
'seminar_signup' => seminar_signup
2016-06-29 06:57:45 +00:00
}
end
def con_upload
time_now = Time.now
if !@@session[:seminar_main_id].blank?
2016-06-29 06:57:45 +00:00
seminar = SeminarMain.find_by(id: @@session[:seminar_main_id])
2016-06-29 06:57:45 +00:00
2021-06-17 10:07:43 +00:00
seminar_signup = SeminarSignup.find_by(_id: @@session[:seminar_signup_id], seminar_main_id: @@session[:seminar_main_id] ) rescue nil
2016-06-29 06:57:45 +00:00
show = true
seminar.seminar_submission_field_sets.each do |ssf|
if ssf.disabled && ssf.hidden
show = false
else
show = true
break
end
end
2016-06-29 06:57:45 +00:00
else
seminar = {}
seminar_signup = {}
end
{
'time_now' => time_now,
'seminar' => seminar,
'seminar_signup' => seminar_signup,
"show" => show
2016-06-29 06:57:45 +00:00
}
end
2023-10-10 14:49:16 +00:00
def edit_login_seminar_signup #copy from show
if !@@session[:seminar_main_id].blank?
seminar = SeminarMain.find_by(id: @@session[:seminar_main_id])
seminar_signup = SeminarSignup.find_by(_id: @@session[:seminar_signup_id], seminar_main_id: @@session[:seminar_main_id] ) rescue nil
else
seminar = {}
seminar_signup = {}
end
module_app = ModuleApp.where(:key => "seminar").first
categories = module_app.categories
time_now = Time.now
{
"seminar" => seminar,
"seminar_signup" => seminar_signup,
"time_now" => time_now
}
end
2016-06-29 06:57:45 +00:00
def con_logout
# redirect_to page_for_seminar_url
end
def con_login
time_now = Time.now
params = OrbitHelper.params
seminar = SeminarMain.find_by(uid: params[:uid])
{
'seminar' => seminar,
'time_now' => time_now
}
end
2023-10-04 16:38:24 +00:00
def reset_email
end
def reset_password_page
params = OrbitHelper.params
seminar = SeminarMain.find_by(uid: params[:uid])
seminar_signup = seminar.seminar_signups.where(:status=>'C', :id=> params[:cid], :token => params[:token]).first
2023-10-10 16:17:13 +00:00
password_pattern = ""
if(seminar.seminar_signup_field_sets.count != 0)
password_pattern = seminar.seminar_signup_field_sets.where(:field_name => "password").first.validator rescue ""
end
2023-10-04 16:38:24 +00:00
status = false
if(!seminar_signup.nil?)
status = true
end
{
"status" => status,
"seminar" => seminar,
2023-10-10 16:17:13 +00:00
"pattern" => password_pattern,
2023-10-04 16:38:24 +00:00
"cid" => params[:cid],
"token" => params[:token]
}
end
def confirm_email_page
confirm = false
params = OrbitHelper.params
2023-10-10 14:49:16 +00:00
uid = params[:uid]
if uid.nil?
uid = params[:page].split('-').last
end
seminar = SeminarMain.where(:uid => uid).first
2023-10-04 16:38:24 +00:00
if(!seminar.nil?)
signup = seminar.seminar_signups.where(:id => params[:cid], :token => params[:token]).first
2023-10-04 16:38:24 +00:00
if(!signup.nil?)
signup.token = nil
signup.is_confirmed = true
signup.is_confirmed_date = DateTime.now
signup.signup_confirmed_counter = signup.signup_confirmed_counter + 1
2023-10-04 16:38:24 +00:00
signup.save
confirm = true
end
end
{
"confirm" => confirm,
"url" => OrbitHelper.url_to_show(seminar.to_param)
}
end
2016-06-29 06:57:45 +00:00
def con_login_proc
seminar = SeminarMain.find_by(id: params[:seminar_signup][:seminar_main_id])
@seminar_signup = SeminarSignup.where(:status=>'C', :email=> params[:user_name], :password => params[:password], :seminar_main_id => params[:seminar_signup][:seminar_main_id]).first
if !@seminar_signup.blank?
session[:seminar_signup_id] = @seminar_signup.id
session[:seminar_main_id] = @seminar_signup.seminar_main_id
2022-10-22 10:43:36 +00:00
redirect_to "#{params[:referer_url].to_s.chomp('/')}/?method=con_upload"
2016-06-29 06:57:45 +00:00
else
2022-10-22 10:43:36 +00:00
redirect_to "#{params[:referer_url].to_s.chomp('/')}/?method=con_login", :notice => '登入失敗'
2016-06-29 06:57:45 +00:00
end
end
2023-10-04 16:38:24 +00:00
def reset_confirm_password_proc
params = OrbitHelper.params
seminar = SeminarMain.find(params[:seminar_id])
redirect_to "#{params[:referer_url].to_s.chomp('/')}/?method=reset_password_page" if seminar.nil?
seminar_signup = seminar.seminar_signups.where(:status =>'C', :token => params[:reset_token], :id => params[:cid]).first
if !seminar_signup.blank?
seminar_signup.password = params[:password]
seminar_signup.token = nil
seminar_signup.save
redirect_to "#{params[:referer_url].to_s.chomp('/')}/?method=con_login", :notice => t('seminar_signup.password_changed')
else
redirect_to "#{params[:referer_url].to_s.chomp('/')}/?method=con_login", :notice => t('seminar_signup.password_changed_not_ok')
end
end
def reset_password_proc
@seminar = SeminarMain.find_by(id: params[:seminar_signup][:seminar_main_id])
seminar_signup = SeminarSignup.where(:status=>'C', :email=> params[:user_name], :seminar_main_id => params[:seminar_signup][:seminar_main_id]).first
if !seminar_signup.blank?
token = seminar_signup.generate_token
extra_text = "<br><a href='#{request.protocol + request.host_with_port + params[:referer_url].to_s.chomp('/')}/?method=reset_password_page&token=#{token}&cid=#{seminar_signup.id.to_s}'>#{t("seminar.click_here_to_confirm")}</a>"
2023-10-04 16:38:24 +00:00
send_mail('reset_password', seminar_signup.email, @seminar.id.to_s, extra_text)
redirect_to "#{params[:referer_url].to_s.chomp('/')}/?method=reset_email", :notice => t('seminar_signup.reset_email_sent')
else
redirect_to "#{params[:referer_url].to_s.chomp('/')}/?method=reset_email", :notice => t('seminar_signup.email_not_found')
end
end
2016-06-29 06:57:45 +00:00
def seminar_signup_params
params.require(:seminar_signup).permit!
end
def seminar_signup_contribute_params
params.require(:seminar_signup_contribute).permit!
end
def seminar_signup_values_params
params.require(:seminar_signup_values).permit!
end
private
def show_alert(notice_words)
respond_to do |format|
format.js{
2023-10-11 14:42:04 +00:00
render :js => "$('.rucaptcha-image').click();alert('#{notice_words}');"
}
end
end
def redirect_with_js(url)
respond_to do |format|
format.js{
render :js => "window.location.href = '#{url}';"
}
end
end
end