class SeminarsController < ApplicationController helper MemberHelper include ActionView::Context include Admin::SeminarsHelper # include SimpleCaptcha::ControllerHelpers def index time_now = Time.now seminars = SeminarMain.filter_by_categories.desc(:signup_start_date).page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) { "seminars" => seminars, 'time_now' => time_now, "total_pages" => seminars.total_pages } end def show_privacy params = OrbitHelper.params seminar = SeminarMain.where(uid: params[:uid]).first 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]) if !seminar.registration_status.blank? && seminar.signup_start_date <= time_now && ( seminar.signup_end_date.nil? || seminar.signup_end_date+1 >= time_now ) sign_up = ('' + t('seminar.signup') + '').html_safe 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 ) if !@@session[:seminar_signup_id].blank? if @@session[:seminar_main_id] == seminar.id contribute_action = ('' + t('seminar_signup.uploads') + '').html_safe else contribute_action = ('' + t('seminar_signup.con_login') + '').html_safe end else contribute_action = ('' + t('seminar_signup.con_login') + '').html_safe 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 seminar_signup = SeminarSignup.new time_now = Time.now { "seminar" => seminar, "seminar_signup" => seminar_signup, "time_now" => time_now } end def check_email params = OrbitHelper.params if !params[:email].blank? count = SeminarSignup.where(:email => params[:email], :seminar_main_id => params[:no]).count result = count > 0 ? '已存在' : '可使用' else result = '請輸入email' end { "result" => result } 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 @signup = SeminarSignup.where(email: params[:seminar_signup][:email], seminar_main_id: params[:seminar_signup][:seminar_main_id] ).first @seminar_signup = SeminarSignup.new(seminar_signup_params) if gotcha_valid? if @signup.blank? && @seminar_signup.save # if gotcha_valid? && @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) end end redirect_to "#{params[:referer_url]}/?method=signup_ok" else if !@signup.blank? redirect_to "#{params[:referer_url]}", :notice => 'mail已存在' else redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') end end else redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') end end def signup_ok end def add_file_proc @con = SeminarSignupContribute.new(seminar_signup_contribute_params) if @con.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 = SeminarSignupContribute.find(params[:seminar_signup_contribute][:id]) @con.update_attributes(seminar_signup_contribute_params) if @con.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 = 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 ) con.destroy redirect_to "#{params[:referer_url]}/?method=con_upload" end def add_file session = OrbitHelper.get_session 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 con = SeminarSignupContribute.new { 'con' => con, 'seminar' => seminar, 'seminar_signup' => seminar_signup } end def edit_file params = OrbitHelper.params con = SeminarSignupContribute.find(params[:con_no]) { 'con' => con } end def con_upload time_now = Time.now session = OrbitHelper.get_session 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 { 'time_now' => time_now, 'seminar' => seminar, 'seminar_signup' => seminar_signup } end 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 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 redirect_to "#{params[:referer_url]}/?method=con_upload" else redirect_to "#{params[:referer_url]}/?method=con_login", :notice => '登入失敗' end end 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 end