2020-02-01 16:37:59 +00:00
|
|
|
class OlympiamanagementsController < PagesController
|
|
|
|
include ActionView::Context #vary important (only add this can access @@session from view)
|
|
|
|
include ApplicationHelper
|
|
|
|
before_action :set_sign_up_setting
|
|
|
|
#include "#{Rails.root}/app/helpers/application_helper.rb"
|
2020-01-31 13:46:35 +00:00
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = "olympiamanagement"
|
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
def set_sign_up_setting
|
|
|
|
@sign_up_setting = SignUpSetting.last
|
|
|
|
data_arr = [{:url=>'/olympiamanagements/school_connection_data',:name=>t('olympiamanagement.school_connection_data')},
|
|
|
|
{:url=>'/olympiamanagements/add_sign_up_student_data',:name=>t('olympiamanagement.add_sign_up_student_data')},
|
|
|
|
{:url=>'/olympiamanagements/sign_up_student_data_list',:name=>t('olympiamanagement.sign_up_student_data_list')},
|
|
|
|
{:url=>'/olympiamanagements/edit_password',:name=>t('olympiamanagement.edit_password')},
|
|
|
|
{:url=>'/olympiamanagements/print_registration_form',:name=>t('olympiamanagement.print_registration_form')},
|
|
|
|
{:url=>'/olympiamanagements/logout',:name=>t('olympiamanagement.logout')}]
|
|
|
|
@breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr})
|
|
|
|
end
|
2020-01-22 14:03:38 +00:00
|
|
|
def index
|
2020-01-31 13:46:35 +00:00
|
|
|
uid = OrbitHelper.params[:uid] rescue ""
|
|
|
|
tags = OrbitHelper.widget_tags
|
|
|
|
categories = OrbitHelper.widget_categories || []
|
2020-02-02 11:25:42 +00:00
|
|
|
set_sign_up_setting
|
|
|
|
@time_arr = ["year","month","day","o_clock","minute"]
|
|
|
|
start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
|
|
|
|
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
|
|
|
|
time_now_str = Time.now.strftime("%Y %m %d %H %M")
|
|
|
|
@instructions_name = {}
|
|
|
|
Site.first.in_use_locales.each do |locale|
|
|
|
|
I18n.with_locale(locale) do
|
|
|
|
@instructions_name[locale.to_s] = I18n.t('olympiamanagement.registration_instructions')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first
|
|
|
|
@instructions_pages = Page.where(:parent_page_id=>@page.id).select{|page| page.name_translations==@instructions_name}
|
2020-01-31 14:56:46 +00:00
|
|
|
case OrbitHelper.params[:layout_type]
|
|
|
|
when "olympia_managements_instructions_index"
|
2020-02-02 11:25:42 +00:00
|
|
|
if !(time_now_str <= end_time_str && time_now_str >= start_time_str)
|
|
|
|
@olympiamanagement_instruction = @sign_up_setting.registration_instructions[I18n.locale.to_s].to_s
|
|
|
|
@sign_up_setting.attributes.to_h.each do |key,value|
|
|
|
|
@olympiamanagement_instruction = @olympiamanagement_instruction.gsub("{{#{key}}}",value.to_s)
|
|
|
|
end
|
|
|
|
if !OrbitHelper.current_user.nil?
|
|
|
|
@edit_link = '/admin/olympiamanagements/sign_up_setting#registration_instructions'
|
|
|
|
@edit_text = (I18n.locale.to_s == "zh_tw") ? "編輯" : "Edit"
|
|
|
|
if !OrbitHelper.current_user.nil?
|
|
|
|
@olympiamanagement_instruction += '<p class="admin-edit text-right"><a class="btn btn-primary" href="'+@edit_link+'" title="'+@edit_text+'"><i class="icon-edit"></i> '+@edit_text+'</a></p>'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
data_arr = @page.child_page.map{|page| {:url=>"/#{I18n.locale}#{page.url}",:name=>page.name}}
|
|
|
|
@breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr})
|
|
|
|
@olympiamanagement_instruction = @breadcumb + @olympiamanagement_instruction.html_safe
|
|
|
|
else
|
|
|
|
if !@instructions_pages.empty?
|
|
|
|
@instructions_pages.each{|page| page.destroy}
|
|
|
|
end
|
|
|
|
@olympiamanagement_instruction = '<h3 style="margin: 20px 0px 10px; padding: 0px; color: rgb(0, 153, 153); font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: bold; font-stretch: normal; font-size: 0.9375em; line-height: 20px; font-family: 微軟正黑體, sans-serif;">'+t('olympiamanagement.sign_up_hint')+'</h3>'
|
2020-01-31 14:56:46 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"olympiamanagement" => [],
|
|
|
|
"extras"=>{"instructions"=> @olympiamanagement_instruction}
|
|
|
|
}
|
|
|
|
when "olympia_managements_index"
|
2020-02-02 11:25:42 +00:00
|
|
|
if Page.where(:parent_page_id=>@page.id,:name=>@page.name).length == 0
|
|
|
|
@newpage = Page.create(:layout=> @page.layout,:data_count=>@page.data_count,:parent_page_id=>@page.id,:url=>@page.url,
|
|
|
|
:menu_enabled_for=>@page.menu_enabled_for,:enabled_for_sitemap=>@page.enabled_for_sitemap,:enabled_for=>@page.enabled_for,:module=>@page[:module],:page_id=>@page.page_id)
|
|
|
|
@newpage.name_translations = @page.name_translations
|
|
|
|
@newpage.save
|
|
|
|
@newpage = Page.create(:layout=> "olympia_managements_instructions_index",:data_count=>@page.data_count,:parent_page_id=>@page.id,:url=>"/olympia_instructions",
|
|
|
|
:menu_enabled_for=>@page.menu_enabled_for,:enabled_for_sitemap=>@page.enabled_for_sitemap,:enabled_for=>@page.enabled_for,:module=>@page[:module],:page_id=>'olympia_instructions')
|
|
|
|
@newpage.name_translations = @instructions_name
|
|
|
|
@newpage.save
|
|
|
|
end
|
|
|
|
@error = nil
|
|
|
|
@page_content
|
|
|
|
if !(time_now_str <= end_time_str && time_now_str >= start_time_str)
|
|
|
|
if @instructions_pages.empty?
|
|
|
|
@newpage = Page.create(:layout=> "olympia_managements_instructions_index",:data_count=>@page.data_count,:parent_page_id=>@page.id,:url=>"/olympia_instructions",
|
|
|
|
:menu_enabled_for=>@page.menu_enabled_for,:enabled_for_sitemap=>@page.enabled_for_sitemap,:enabled_for=>@page.enabled_for,:module=>@page[:module],:page_id=>'olympia_instructions')
|
|
|
|
@newpage.name_translations = @instructions_name
|
|
|
|
@newpage.save
|
|
|
|
elsif @instructions_pages.length != 1
|
|
|
|
@instructions_pages.slice(1,@instructions_pages.length).each{|page| page.destroy}
|
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
if !OrbitHelper.params[:login_id].to_s.blank?
|
|
|
|
if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).length == 0
|
|
|
|
@error = "no_account"
|
|
|
|
else
|
|
|
|
if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).first.password != OrbitHelper.params[:login_pw]
|
|
|
|
@error = "password_error"
|
|
|
|
else
|
|
|
|
@@session[:olympia_login_id] = OrbitHelper.params[:login_id]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if @@session[:olympia_login_id].to_s.blank?
|
|
|
|
@page_content = render_to_string(:formats=> [:html] ,:partial=>'login')
|
|
|
|
else
|
|
|
|
@page_content = @breadcumb
|
|
|
|
|
|
|
|
end
|
|
|
|
else
|
2020-02-02 11:25:42 +00:00
|
|
|
if !@instructions_pages.empty?
|
|
|
|
@instructions_pages.each{|page| page.destroy}
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
2020-02-02 11:25:42 +00:00
|
|
|
data_arr = @page.child_page.map{|page| {:url=>"/#{I18n.locale}#{page.url}",:name=>page.name}}
|
|
|
|
@breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr})
|
|
|
|
@page_content = @breadcumb+'<h3 style="margin: 20px 0px 10px; padding: 0px; color: rgb(0, 153, 153); font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: bold; font-stretch: normal; font-size: 0.9375em; line-height: 20px; font-family: 微軟正黑體, sans-serif;">'+t('olympiamanagement.sign_up_hint')+'</h3>'
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
2020-02-02 11:25:42 +00:00
|
|
|
{
|
|
|
|
"olympiamanagement" => [],
|
|
|
|
"extras"=>{"page_content"=> @page_content}
|
|
|
|
}
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def school_connection_data
|
|
|
|
@time_arr = ["year","month","day","o_clock","minute"]
|
|
|
|
start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
|
|
|
|
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
|
|
|
|
time_now_str = Time.now.strftime("%Y %m %d %H %M")
|
|
|
|
if !(time_now_str <= end_time_str && time_now_str >= start_time_str) || session[:olympia_login_id].to_s.blank?
|
2020-02-02 11:25:42 +00:00
|
|
|
@school_data_fields = [{'account_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'school_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'school_code'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'school_address'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'class_number'=>{'type'=>'String','size'=>'5','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'enrollment_limited'=>{'type'=>'Fixnum','size'=>'5','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'school_contact_person_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
|
|
|
|
{'department_job_title'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
|
|
|
|
{'office_tel_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
|
|
|
|
{'fax'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
|
|
|
|
{'mobile_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
|
|
|
|
{'email'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}]
|
|
|
|
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
|
|
|
|
@page_content = render_to_string(:formats=> [:html] ,:partial=>'edit_school_data.html',:locals=>{:@school_data_fields=>@school_data_fields,:@olympia_school_data_field=>@olympia_school_data_field})
|
|
|
|
render_contents_in_index_page(@breadcumb+@page_content)#redirect_to :back
|
2020-02-01 16:37:59 +00:00
|
|
|
else
|
2020-02-02 11:25:42 +00:00
|
|
|
redirect_to :back
|
2020-01-31 13:46:35 +00:00
|
|
|
end
|
2020-01-22 14:03:38 +00:00
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
def add_sign_up_student_data
|
|
|
|
@time_arr = ["year","month","day","o_clock","minute"]
|
|
|
|
start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
|
|
|
|
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
|
|
|
|
time_now_str = Time.now.strftime("%Y %m %d %H %M")
|
2020-02-02 11:25:42 +00:00
|
|
|
if !(!(time_now_str <= end_time_str && time_now_str >= start_time_str) || session[:olympia_login_id].to_s.blank?)
|
2020-02-01 16:37:59 +00:00
|
|
|
redirect_to :back
|
|
|
|
else
|
2020-02-02 11:25:42 +00:00
|
|
|
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
|
2020-02-01 16:37:59 +00:00
|
|
|
redirect_to :back if @olympia_school_data_field.nil?
|
|
|
|
@required_fields = [:school_contact_person_name,:department_job_title,:office_tel_number,:fax,:mobile_number,:email]
|
|
|
|
@flag = true
|
|
|
|
@required_fields.each do |field|
|
|
|
|
if @olympia_school_data_field[field].to_s.blank?
|
|
|
|
@flag = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2020-02-02 11:25:42 +00:00
|
|
|
if !@flag
|
|
|
|
I18n.t('olympiamanagement.please_set_school_connect_data')
|
|
|
|
render_contents_in_index_page(@breadcumb+"<p><a href=#{school_connection_data_olympiamanagements_path}>#{I18n.t('olympiamanagement.please_set_school_connect_data')}</a></p>".html_safe)
|
|
|
|
else
|
|
|
|
render_contents_in_index_page(@breadcumb)
|
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
#if @flag = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def sign_up_student_data_list
|
|
|
|
end
|
|
|
|
def edit_password
|
2020-02-02 11:25:42 +00:00
|
|
|
if !session[:olympia_login_id].to_s.blank?
|
|
|
|
if params[:confirm_password].nil? && params[:new_password].nil?
|
|
|
|
@page_content = render_to_string(:formats=> [:html] ,:partial=>'edit_password.html',:locals=>{:@error=>(@@error rescue nil)})
|
|
|
|
render_contents_in_index_page(@breadcumb+@page_content)
|
|
|
|
else
|
|
|
|
@@error = nil
|
|
|
|
if params[:confirm_password].to_s != params[:new_password].to_s
|
|
|
|
@@error = "confirm_password_error"
|
|
|
|
elsif params[:confirm_password].to_s.blank? && params[:new_password].to_s.blank?
|
|
|
|
@@error = "password_all_empty"
|
|
|
|
elsif params[:confirm_password].to_s.blank?
|
|
|
|
@@error = "confirm_password_empty"
|
|
|
|
elsif params[:new_password].to_s.blank?
|
|
|
|
@@error = "new_password_empty"
|
|
|
|
else
|
|
|
|
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
|
|
|
|
@olympia_school_data_field.password = params[:new_password]
|
|
|
|
@olympia_school_data_field.save
|
|
|
|
end
|
|
|
|
redirect_to edit_password_olympiamanagements_path
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first
|
|
|
|
redirect_to "/#{I18n.locale}#{@page.url}"
|
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
|
|
|
def print_registration_form
|
|
|
|
end
|
|
|
|
def logout
|
|
|
|
session[:olympia_login_id] = ""
|
2020-02-02 11:25:42 +00:00
|
|
|
@page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first
|
|
|
|
redirect_to "/#{I18n.locale}#{@page.url}"#render :html => session.to_hash
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
2020-01-22 14:03:38 +00:00
|
|
|
def widget
|
2020-01-31 13:46:35 +00:00
|
|
|
uid = OrbitHelper.params[:uid] rescue ""
|
|
|
|
tags = OrbitHelper.widget_tags
|
|
|
|
categories = OrbitHelper.widget_categories || []
|
|
|
|
@sign_up_setting = SignUpSetting.last
|
|
|
|
@olympiamanagement_instruction = @sign_up_setting.registration_instructions[I18n.locale.to_s].to_s
|
|
|
|
@sign_up_setting.attributes.to_h.each do |key,value|
|
|
|
|
@olympiamanagement_instruction = @olympiamanagement_instruction.gsub("{{#{key}}}",value.to_s)
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"olympiamanagement" => [],
|
|
|
|
"extras"=>{"instructions"=> @olympiamanagement_instruction}
|
|
|
|
}
|
|
|
|
end
|
2020-01-31 14:56:46 +00:00
|
|
|
def download_school_code
|
2020-02-02 11:25:42 +00:00
|
|
|
@OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id)
|
2020-01-31 14:56:46 +00:00
|
|
|
dir_path = 'tmp/olypiamanagement/'
|
|
|
|
#FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
|
|
|
|
FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
|
|
|
|
@filename = 'download_school_code.xlsx'
|
|
|
|
Dir.chdir(dir_path) do
|
|
|
|
File.open(@filename, 'w') do |f|
|
|
|
|
f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'school_code.xlsx',:locals=> {:@OlympiaSchoolDataFields=>@OlympiaSchoolDataFields} )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
tmp_filename_data = File.read(dir_path +@filename)
|
|
|
|
send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: "#{Time.now.year}#{Time.now.month}#{Time.now.day}_download_school_code.xlsx")
|
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
def render_contents_in_index_page(contents=@breadcumb)
|
|
|
|
doc = Nokogiri::HTML(render_final_page("page",Page.where(:layout=>"olympia_managements_index").first,true), nil, "UTF-8")
|
|
|
|
viewarea = doc.css("*[data-content='true']")[0]
|
2020-02-02 11:25:42 +00:00
|
|
|
viewarea.inner_html = contents
|
2020-02-01 16:37:59 +00:00
|
|
|
render :html => doc.to_html.html_safe
|
|
|
|
end
|
2020-01-31 13:46:35 +00:00
|
|
|
def updata_school_data
|
2020-02-02 11:25:42 +00:00
|
|
|
@readonly_fields = ['account_number','password','school_name','school_code','school_address','class_number','enrollment_limited']
|
|
|
|
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>params[:olympia_user_name]).first
|
|
|
|
redirect_to :back if @olympia_school_data_field.nil?
|
|
|
|
params['add_school_data'].keys.each do |field|
|
|
|
|
if !@readonly_fields.include?(field)
|
|
|
|
@olympia_school_data_field[field] = params['add_school_data'][field]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@olympia_school_data_field.save
|
|
|
|
redirect_to add_sign_up_student_data_olympiamanagements_path
|
|
|
|
#render_contents_in_index_page(@olympia_school_data_field.attributes.to_s)
|
2020-01-31 13:46:35 +00:00
|
|
|
end
|
|
|
|
def updata_student_data
|
|
|
|
#render :html => '123'
|
2020-01-22 14:03:38 +00:00
|
|
|
end
|
|
|
|
end
|