diff --git a/app/assets/stylesheets/contest.css b/app/assets/stylesheets/contest.css new file mode 100644 index 0000000..90ae0c6 --- /dev/null +++ b/app/assets/stylesheets/contest.css @@ -0,0 +1,36 @@ +table.print_contest1, .print_contest2, .print_contest3 { + width: 100%; + margin: 0 0 1em 0; + border-spacing: 0; + border-top: 0.0625em solid black; + border-right: 0.0625em solid black; +} + +table.print_contest1 th, table.print_contest1 td{ + border-collapse:collapse; + border-bottom: 0.0625em solid black; + border-left: 0.0625em solid black; + height:2.5em; + font-size: 1em; + text-align: center; +} + +table.print_contest2 th, table.print_contest2 td{ + border-collapse:collapse; + border-left: 0.0625em solid black; + border-bottom: 0.0625em solid black; + height:2.5em; + font-size: 1em; +} + +table.print_contest3 th, table.print_contest3 td{ + border-collapse:collapse; + border-left: 0.0625em solid black; + border-bottom: 0.0625em solid black; + height:2.5em; + font-size: 1em; + text-align: center; +} +h2{ + margin: 0; +} \ No newline at end of file diff --git a/app/assets/stylesheets/olympiamanagement.scss b/app/assets/stylesheets/olympiamanagement.scss index dc09099..287ec55 100644 --- a/app/assets/stylesheets/olympiamanagement.scss +++ b/app/assets/stylesheets/olympiamanagement.scss @@ -1,6 +1,163 @@ .fieldset_title{ - margin: 0 15px 20px 15px; - padding: 5px; + margin: 0 0.9375em 1.25em 0.9375em; + padding: 0.3125em; font-size: 1.2em; font-weight: bold; + border: 0em; + width: auto; +} +.errMsg { + color: #CC3333; + display: block; + margin: 10px; + padding-left: 20px; + background-image: url(/assets/warning.gif); + background-repeat: no-repeat; + background-position: left center; +} +.fieldset_block{ + padding: 1.25em 0.625em 1.25em 3%; + border-width: 0.125em; + border-style: groove; + border-color: threedface; + border-image: initial; +} +.col { + float: left; + clear: both; + width: 9.125em; + margin: 0 0.625em 0em 0; + padding: 0.0625em 0 0.0625em 0; +} +.col_r { + float: left; + display: inline; + padding-bottom: 0.1875em; +} +.col_input{ + padding: 0; + width: auto; +} +.ts_styled, .ts_rowsonly{ + border-collapse: collapse; + clear: both; + margin: 0 0 10px; + width: 100%; + font-size: 12px; +} +.ts_styled caption, .ts_rowsonly caption{ + color: #009999; + font: bold 15px/20px '微軟正黑體',sans-serif; + margin: 10px 0 10px; + text-align: left; + width: 500px; +} +.ts_styled th, .ts_rowsonly th{ + border-top: 2px solid #999; + border-bottom: 1px solid #999; + color: #666; + padding: 10px 5px; + text-align: left; + white-space: nowrap; + font-size: 13px; + font-family: "微軟正黑體"; +} +.ts_styled td, .ts_rowsonly td{ + border-bottom: 1px solid #e3e3e3; + padding: 6px 5px; + color: #333; +} +.ts_styled a, .ts_rowsonly a{ + color: #333; +} +.ts_styled a:hover, .ts_rowsonly a:hover{ + color: #467cb2; +} +.ts_styled .even, .ts_rowsonly .even{} +.ts_styled tr:hover, .ts_styled tr:hover a { + background: #f5f5f5; + transition: background 0.3s; +} +.ts_vstyled{} +.ts_vstyled caption{ + color: #1db2dd; + font: bold 15px/20px '微軟正黑體',sans-serif; + margin: 0 0 10px; + text-align: left; + width: 500px; +} +.ts_vstyled th{ + border-right: 2px solid #1db2dd; + color: #1db2dd; + padding: 1%; + text-align: left; + width: 13%; +} +.ts_vstyled td{ + padding: 1% 2%; + text-align: left; + width: 81%; +} +.ts_vstyled a{} +.ts_vstyled a:hover{} +.PageDetails { + padding-top: 0.1875em; + padding-bottom: 0.1875em; + font-weight: bold; + font-size: 0.875em; + border-bottom: 0.0625em solid #ddd; + overflow: hidden; + text-align: right; + color: black; + font-size: 1.3em; +} +.PageList { + margin: 0em 0em 0 0.5em; + font-weight: bold; + font-size: 0.875em; + overflow: hidden; + list-style: none; + display: inline; + background: none; + color: #999; +} +ol { + margin: 0 0 0.5em 0; + min-height: 0.625em; + height: auto !important; + height: 0.625em; + padding: 0; + clear: both; + float: right; +} +.PageList li { + display: inline; +} +.wrap-inner{ + font-size: 1.1em; +} +.field-hint-inactive { + color: #999; + margin-left: 0.3125em; + padding-left: 1em; + padding-right: 0.5em; + background-image: url(/assets/fhi.png); + background-repeat: no-repeat; + background-position: left center; + float: left; +} +.required { + font-weight: bold; +} +.lleft{ + float: left; +} +.red_text{ + color: red; +} +.layout-content-inner.container{ + min-height: 38em; +} +li{ + display: block; } \ No newline at end of file diff --git a/app/controllers/admin/olympiamanagements_controller.rb b/app/controllers/admin/olympiamanagements_controller.rb index 60780e3..46ded43 100644 --- a/app/controllers/admin/olympiamanagements_controller.rb +++ b/app/controllers/admin/olympiamanagements_controller.rb @@ -7,6 +7,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController helper Admin::OlympiamanagementsHelper load File.expand_path(__dir__)+'/zipgenerator.rb' def index + session[:sign_up_setting_id] = "" page_num = params[:page] || 1 @sign_up_settings = SignUpSetting.all.desc(:id) @sign_up_settings = @sign_up_settings.page(page_num).per(10) @@ -44,6 +45,16 @@ class Admin::OlympiamanagementsController < OrbitAdminController @error_msg << ((I18n.locale.to_s == "zh_tw") ? "查無資料" : "Not found.") render 'error_message' end + elsif params[:type] == "delete_sign_up_setting" + @sign_up_setting = SignUpSetting.find(params[:id]) rescue nil + if !@sign_up_setting.nil? + @sign_up_setting.destroy + redirect_to :back + else + @error_msg = [] + @error_msg << ((I18n.locale.to_s == "zh_tw") ? "查無資料" : "Not found.") + render 'error_message' + end else render :html => '404' and return end @@ -74,10 +85,27 @@ class Admin::OlympiamanagementsController < OrbitAdminController redirect_to :back end elsif params[:type] == 'add_school_data' - @olympia_school_data_field = (params[:id].nil? ? OlympiaSchoolDataFields.new : ((OlympiaSchoolDataFields.find(params[:id]).nil? rescue true) ? OlympiaSchoolDataFields.new : OlympiaSchoolDataFields.find(params[:id]))) + @olympia_school_data_field = OlympiaSchoolDataFields.find(params[:id]) rescue nil + if @olympia_school_data_field.nil? + if OlympiaSchoolDataFields.where(:account_number => params['add_school_data']['account_number'],:sign_up_setting_id=>@sign_up_setting.id).length != 0 + @error_msg = [] + @error_msg << ((I18n.locale.to_s == "zh_tw") ? "帳號:#{params['add_school_data']['account_number']}已存在(帳號不可重複建立)" : "Account number: #{params['add_school_data']['account_number']} already exist.(Account name can not be created repeatedly.)") + render "error_message" and return + end + @olympia_school_data_field = OlympiaSchoolDataFields.new + else + if @olympia_school_data_field.account_number != params['add_school_data']['account_number'] + if OlympiaSchoolDataFields.where(:account_number => params['add_school_data']['account_number'],:sign_up_setting_id=>@sign_up_setting.id).length != 0 + @error_msg = [] + @error_msg << ((I18n.locale.to_s == "zh_tw") ? "帳號:#{params['add_school_data']['account_number']}已存在(帳號不可重複建立)" : "Account number: #{params['add_school_data']['account_number']} already exist.(Account name can not be created repeatedly.)") + render "error_message" and return + end + end + end params['add_school_data'].keys.each do |field| @olympia_school_data_field[field] = params['add_school_data'][field] end + @olympia_school_data_field.sign_up_setting_id = @sign_up_setting.id @olympia_school_data_field.save redirect_to admin_olympiamanagements_school_data_list_path elsif params[:type] == 'import_class_setting' @@ -131,7 +159,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController @SchoolDataname = @SchoolDataField.school_data_fields.map{|field| field.keys[0]} page_num = params[:page] || 1 @OlympiaSchoolDataFields = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id).asc(:id) - @OlympiaSchoolDataFields = @OlympiaSchoolDataFields.where("school_name" => /#{params[:school_name]}/) if !params[:school_name].to_s.blank? + @OlympiaSchoolDataFields = @OlympiaSchoolDataFields.where("school_name" => /#{params[:school_name].gsub('(','\(').gsub(')','\)').gsub('[','\[').gsub(']','\]')}/) if !params[:school_name].to_s.blank? @OlympiaSchoolDataFields = @OlympiaSchoolDataFields.where("school_code" => /#{params[:school_code]}/) if !params[:school_code].to_s.blank? @OlympiaSchoolDataFields = @OlympiaSchoolDataFields.page(page_num).per(10) end diff --git a/app/controllers/olympiamanagements_controller.rb b/app/controllers/olympiamanagements_controller.rb index 31307f9..98f796d 100644 --- a/app/controllers/olympiamanagements_controller.rb +++ b/app/controllers/olympiamanagements_controller.rb @@ -1,6 +1,6 @@ class OlympiamanagementsController < ApplicationController include ActionView::Context #vary important (only add this can access @@session from view) - before_action :set_sign_up_setting,:create_first_fields + before_action :set_sign_up_setting,:create_first_fields,:check_time prepend_view_path "app/templates" #for_render_pages layout :get_layout #for_render_pages helper Admin::OlympiamanagementsHelper @@ -13,7 +13,16 @@ class OlympiamanagementsController < ApplicationController StudentDataField.create if StudentDataField.all.length == 0 SchoolDataFields.create if SchoolDataFields.all.length == 0 SignUpSetting.create if SignUpSetting.all.length == 0 - @sign_up_setting = SignUpSetting.where(:active=>true).last + end + def check_time + @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") + @page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first + if !(time_now_str <= end_time_str && time_now_str >= start_time_str) + redirect_to "/#{I18n.locale}#{@page.url}" + end end def check_login begin @@ -21,7 +30,7 @@ class OlympiamanagementsController < ApplicationController rescue @@error = nil end - @school = OlympiaSchoolDataFields.where(:account_number=>request.session[:olympia_login_id],:approved=>true).first rescue nil + @school = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id,:account_number=>request.session[:olympia_login_id],:approved=>true).first rescue nil if @school.nil? render_contents_in_index_page(render_to_string(:formats=> [:html] ,:partial=>'login',:locals=>{:@error=>@@error})) and return end @@ -29,10 +38,12 @@ class OlympiamanagementsController < ApplicationController def login @@error = nil if !params[:login_id].to_s.blank? - if OlympiaSchoolDataFields.where(:account_number=>params[:login_id],:approved=>true).length == 0 + if OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id,:account_number=>params[:login_id],:approved=>true).length == 0 @@error = "no_account" else - if OlympiaSchoolDataFields.where(:account_number=>params[:login_id]).first.password != params[:login_pw] + @correct_password = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id,:account_number=>params[:login_id]).first.password + @correct_password = @sign_up_setting.default_password if @correct_password.blank? + if params[:login_pw] != @correct_password @@error = "password_error" else session[:olympia_login_id] = params[:login_id] @@ -219,7 +230,7 @@ class OlympiamanagementsController < ApplicationController def sign_up_student_data_list page_num = params[:page] || 1 @field_infos = StudentDataField.first.student_data_fields - @olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first.id + @olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id).first.id @sign_up_setting_id = @sign_up_setting.id @student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_fields_id,:sign_up_setting_id=>@sign_up_setting_id).asc(:id).page(page_num).per(10) @page_content = render_to_string(:formats=> [:html] ,:partial=>'student_data_list.html',:locals=>{:@student_fields=>(@student_fields rescue [])}).html_safe @@ -260,13 +271,14 @@ class OlympiamanagementsController < ApplicationController @sign_up_setting.attributes.to_h.each do |key,value| @remark_texts = @remark_texts.gsub("{{#{key}}}",value.to_s) end - @record_form_title = ((I18n.locale.to_s == "zh_tw") ? "#{Time.now.year}年國中科學奧林匹亞競賽國家代表隊選拔初選報名表" : "#{Time.now.year} Year International Junior Science Olympiad National Team Selection First Stage Sign up Form") + @remark_texts = @remark_texts.html_safe + @record_form_title = ((I18n.locale.to_s == "zh_tw") ? "#{@sign_up_setting.end_year}年國中科學奧林匹亞競賽國家代表隊選拔初選報名表" : "#{Time.now.year} Year International Junior Science Olympiad National Team Selection First Stage Sign up Form") @school_data = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first @record_fields = [['school_name','school_code'],['school_address'],['class_number','enrollment_limited'], ['office_tel_number','fax'],['mobile_number','email'],['principal_signature','dean_signature']] @student_fields = ['serial_number','StudentName','StudentSex','StudentClass','StudentIDNO','birth_date','StudentArea','StudentIdentity'] @field_infos = StudentDataField.first.student_data_fields - @olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first.id + @olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id).first.id @sign_up_setting_id = @sign_up_setting.id @student_data_list = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_fields_id,:sign_up_setting_id=>@sign_up_setting_id) @head = render_to_string(:formats=>[:html],:file=>"#{Rails.root}/app/templates/#{@key}/partial/_head.html") @@ -668,9 +680,9 @@ class OlympiamanagementsController < ApplicationController if @student_params['StudentIdentity'] == '1' && (@student_params['olympia_student_images']['0']['StudentFile'].nil? rescue true) @error_msg << I18n.t('olympiamanagement.StudentFile') end - @olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first + @olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id).first @enrollment_limited = ((@olympia_school_data_field.enrollment_limited.nil? || @olympia_school_data_field.enrollment_limited == 0) ? ClassSettingFields.all.select{|class_setting_field| class_setting_field.class_number_range[0] <= @olympia_school_data_field.class_number.to_i && class_setting_field.class_number_range[1] >= @olympia_school_data_field.class_number.to_i}.first.enrollment_available.to_i : @olympia_school_data_field.enrollment_limited.to_i) - @student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_field.id,:sign_up_setting_id=>@sign_up_setting_id) + @student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_field.id,:sign_up_setting_id=>@sign_up_setting.id) if @student_fields.length > @enrollment_limited @error_msg << ((I18n.locale.to_s == "zh_tw") ? ("一般身分報名人數上限為 #{@enrollment_limited} 人。") : ("Enrollment limited of General identity is #{@enrollment_limited} people.")) @error_msg << I18n.t('olympiamanagement.already_exceed_enrollment_limited') diff --git a/app/views/admin/olympiamanagements/index.html.erb b/app/views/admin/olympiamanagements/index.html.erb index d893fbb..ab17ffa 100644 --- a/app/views/admin/olympiamanagements/index.html.erb +++ b/app/views/admin/olympiamanagements/index.html.erb @@ -1,7 +1,7 @@ -<% th_name_list = ['sign_up_start_time','sign_up_end_time','enrollment','status','action']%> +<% th_name_list = ['sign_up_start_time','sign_up_end_time','school_number','enrollment','status','action']%> <% time = ['year','month','day'] %>
<%= time.map{|td| sign_up_setting["start_#{td}"]}.join('-') %> | <%= time.map{|td| sign_up_setting["end_#{td}"]}.join('-') %> | +<%= @school_number = OlympiaSchoolDataFields.where(:sign_up_setting_id=>sign_up_setting.id).length %> | <%= @student_number = OlympiaStudentDataField.where(:sign_up_setting_id=>sign_up_setting.id).length %> | <% if sign_up_setting.active%> @@ -31,9 +32,10 @@ | <% if !sign_up_setting.active%> - <%=t('olympiamanagement.active')%> + <%=t('olympiamanagement.active')%> <% end %> - <%=t('olympiamanagement.view')%> + <%=t('olympiamanagement.view')%> + '; }" onkeypress="if( window.confirm('<%=t('olympiamanagement.please_confirm_delete')%>') ) { window.location='<%=admin_olympiamanagements_update_sign_up_data_path + "?type=delete_sign_up_setting&id=#{sign_up_setting.id}"%>'; }"><%=t('olympiamanagement.delete')%> |