diff --git a/app/controllers/admin/patchfiles_controller.rb b/app/controllers/admin/patchfiles_controller.rb
index 92c9203..36611c1 100644
--- a/app/controllers/admin/patchfiles_controller.rb
+++ b/app/controllers/admin/patchfiles_controller.rb
@@ -30,6 +30,15 @@ class Admin::PatchfilesController < OrbitAdminController
end
end
end
+ if params["filefield"]["refresh_btn"] == "true"
+ @last_message = @file_to_show.last_message
+ @active_file_arr = @file_to_show.file_show.values.map{|hash| hash.values.first}.map{|hash| hash.keys.zip(hash.values.map{|hash| hash[:status]}).to_h}.select{|hash| hash.values.include?(1)}.flat_map{|hash| hash.values.map.with_index{|status,i| (status != 1) ? nil : i}.select{|index| !index.nil?}.map{|index| hash.keys[index]}}
+ @file_to_show.destroy
+ @file_to_show = Filefield.new()
+ @file_to_show.last_message = @last_message
+ @active_file_arr.each{|active_file| @file_to_show.file_show.keys.each{|file_group| (@file_to_show.file_show[file_group][:files].keys.include?(active_file)) ? (@file_to_show.file_show[file_group][:files][active_file][:status] = 1) : nil }}
+ @file_to_show.save
+ end
if params["filefield"]["recovery_btn"] == "true"
@file_to_show.recovery = "true"
else
diff --git a/app/models/filefield.rb b/app/models/filefield.rb
index 860d5d7..869a75e 100644
--- a/app/models/filefield.rb
+++ b/app/models/filefield.rb
@@ -34,7 +34,8 @@ class Filefield
'preference@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/admin/', :dest=>@views_path+'admin/sites/'}
},:status=>0} ,
"member"=>{:files=>{'member_profile@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@model_path},
- 'members_controller@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/admin/', :dest=>@controller_path+'admin/'},
+ 'admin/members_controller@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@controller_path},
+ 'members_controller@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@controller_path},
'_user_basic_passwd@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/admin/', :dest=>@views_path+'admin/members/'}
},:status=>0} ,
"accessibility"=>{:files=>{'back_end@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>@views_path+'layouts/'},
@@ -57,7 +58,7 @@ class Filefield
def backup_file(file_name,file_path)
FileUtils.cd(file_path)
- if (file_name.include? "/") == false
+ if file_name[-1] != "/"
FileUtils.cp(file_name , file_name+'_back')
else
FileUtils.cd('..')
@@ -68,7 +69,7 @@ class Filefield
end
def recover_file(file_name,file_path)
FileUtils.cd(file_path)
- if (file_name.include? "/") == false
+ if file_name[-1] != "/"
FileUtils.cp(file_name+'_back', file_name)
else
FileUtils.cd('..')
@@ -82,8 +83,10 @@ class Filefield
end
def copy_file(file_name,source_file_path,dest_file_path)
FileUtils.cd(source_file_path)
- if (file_name.include? "/") == false
- FileUtils.cp(file_name , dest_file_path)
+ if file_name[-1] != "/"
+ @file_name = Pathname.new(file_name)
+ FileUtils.cd(@file_name.dirname.to_s)
+ FileUtils.cp(@file_name.basename.to_s , dest_file_path+@file_name.dirname.to_s)
else
if !Dir.exist?(dest_file_path)
FileUtils.mkdir_p dest_file_path
diff --git a/updatefiles/admin/members_controller.rb b/updatefiles/admin/members_controller.rb
index d9f2585..e0cfc61 100644
--- a/updatefiles/admin/members_controller.rb
+++ b/updatefiles/admin/members_controller.rb
@@ -4,17 +4,40 @@ class Admin::MembersController < OrbitMemberController
helper MemberHelper
helper OrbitBackendHelper
-
+ Rack::Utils.key_space_limit = 5000000
require 'spreadsheet'
require 'rubyXL'
-
+ require 'fileutils'
+ load File.expand_path(__dir__)+'/zipgenerator.rb'
+ def sort_role_attr_field
+ Role.all.map{|v| v}.each do |role|
+ role.attribute_fields.asc(:id).each_with_index do |attribute_field,index1|
+ key = attribute_field.key
+ if key.to_i.to_s != key.to_s
+ attr_f = attribute_field
+ attr_f.key = index1 + 1
+ attr_f.save
+ end
+ end
+ end
+ MemberInfo.all.each do |member_info|
+ member_info.member_profile_fields.each_with_index do |attribute_field,index1|
+ key = attribute_field.key
+ if key.to_i.to_s != key.to_s
+ attr_f = attribute_field
+ attr_f.key = index1 + 1
+ attr_f.save
+ end
+ end
+ end
+ end
def index
@roles = Role.excludes(disabled: true)
@member_tags = MemberTag.all
page_num = params[:page] || 1
param_temp = request.fullpath.split("?")
@edit_params = (param_temp.count > 1 ? "?" + param_temp.last : "") rescue ""
-
+
@filter = params[:filter]
@mq = params[:mq]
@new_filter = params[:new_filter]
@@ -63,40 +86,41 @@ class Admin::MembersController < OrbitMemberController
"index"
end
- elsif !@filter.blank? and @mq.blank?
-
+ elsif !@filter.blank? && @mq.blank?
+ @filter_role = @filter['role'].flat_map{|role_id| (role_id == 'no_role') ? [[],nil] : role_id} if !@filter['role'].nil?
+ @filter_tag = @filter['tag'].flat_map{|tag_id| (tag_id == 'no_tag') ? [[],nil] : tag_id} if !@filter['tag'].nil?
render case params[:at]
when 'summary'
case (@new_filter["type"] rescue @filter.keys.first)
when "role"
- @members=MemberProfile.all.any_in(:role_ids=>@filter['role']).page(page_num).per(12).desc("_id")
+ @members=MemberProfile.all.any_in(:role_ids=>@filter_role).page(page_num).per(12).desc("_id")
"index_summary"
when "tag"
- @members=MemberProfile.all.any_in(:member_tag_ids=>@filter['tag']).page(page_num).per(12).desc("_id")
+ @members=MemberProfile.all.any_in(:member_tag_ids=>@filter_tag).page(page_num).per(12).desc("_id")
"index_summary"
end
when 'thumbnail'
case (@new_filter["type"] rescue @filter.keys.first)
when "role"
- @members=MemberProfile.all.any_in(:role_ids=>@filter['role']).page(page_num).per(36).desc("_id")
+ @members=MemberProfile.all.any_in(:role_ids=>@filter_role).page(page_num).per(36).desc("_id")
"index_thumbnail"
when "tag"
- @members=MemberProfile.all.any_in(:member_tag_ids=>@filter['tag']).page(page_num).per(36).desc("_id")
+ @members=MemberProfile.all.any_in(:member_tag_ids=>@filter_tag).page(page_num).per(36).desc("_id")
"index_thumbnail"
end
else
case (@new_filter["type"] rescue @filter.keys.first)
when "role"
- @members=MemberProfile.all.any_in(:role_ids=>@filter['role']).page(page_num).per(10).desc("_id")
+ @members=MemberProfile.all.any_in(:role_ids=>@filter_role).page(page_num).per(10).desc("_id")
"index"
when "tag"
- @members=MemberProfile.all.any_in(:member_tag_ids=>@filter['tag']).page(page_num).per(10).desc("_id")
+ @members=MemberProfile.all.any_in(:member_tag_ids=>@filter_tag).page(page_num).per(10).desc("_id")
"index"
end
end
end
-
+
end
def show
@@ -133,70 +157,99 @@ class Admin::MembersController < OrbitMemberController
if number < @numeric.size
@a = @numeric[number]
else
- @dev_by = (number/@numeric.size).floor
+ @dev_by = (number/@numeric.size).floor
@a = "#{make_alpha_from_numbers(@dev_by-1)}#{make_alpha_from_numbers(number-(@dev_by*@numeric.size))}";
end
end
- def import_data_check(file)
-
- profile_data_row = ["email","sid","office_tel","sex","birthday"]
- profile_lang_data_row = ["first_name","last_name","address","autobiography"]
-
+ def import_data_check(tempfile,filename)
+ profile_data_row = ["user_id","password","email","sid","office_tel","sex","birthday","avatar"]
+ profile_lang_data_row = ["first_name","last_name","address","autobiography","fax","mobile_no"]
@field_type = {'text_field' => 'typeA', 'select' => 'typeB', 'date' => 'typeC', 'text_area' => 'typeD', 'radio_button' => 'typeE', 'checkbox' => 'typeE', 'address' => ''}
-
@date_type = {'format1' => '%Y/%m/%d %H:%M', 'format2' => '%Y/%m/%d', 'format3' => '%Y/%m', 'format4' => '%Y'}
-
@error_msg = Array.new
-
- workbook = RubyXL::Parser.parse(file.tempfile)
- sheet = workbook['Member'].extract_data
- sheet.each_with_index do |row,index|
+ @filename = filename.nil? ? tempfile.path : filename
+ begin
+ workbook = RubyXL::Parser.parse(tempfile)
+ rescue
+ @error_msg << filename+'格式錯誤'
+ return @error_msg
+ end
+ sheet = workbook['Member'].sheet_data.rows
+ sheet.each_with_index do |raw_row,index|
+ begin
+ row = raw_row.cells.map{ |cell| cell.value rescue nil}
+ rescue
+ (@error_msg << filename+'格式錯誤')
+ return @error_msg
+ end
if index == 0
@field_data = row
end
+ if index == 1
+ @row_index_hash = {}
+ profile_data_row.each do |row_key|
+ @row_index_hash[row_key] = @field_data.index(row_key)
+ end
+ profile_lang_data_row.each do |lang_row_key|
+ current_site.in_use_locales.each do |locale_name|
+ @row_index_hash[lang_row_key+"(#{locale_name})"] = @field_data.index(lang_row_key+"(#{locale_name})")
+ end
+ end
+ end
if index > 2
-
- @user_id = row[@field_data.index('user_id')]
- if !@user_id.blank?
- check_id = User.where(:user_name => @user_id).first
- @error_msg << "#{make_alpha_from_numbers(@field_data.index('user_id'))}#{index+1}欄位帳號已存在。" if !check_id.blank?
- @error_msg << "#{make_alpha_from_numbers(@field_data.index('user_id'))}#{index+1}欄位格式不符。" if @user_id.size < 3
- end
-
- @password = row[@field_data.index('password')]
- if !@password.blank? and !@user_id.blank?
- @error_msg << "#{make_alpha_from_numbers(@field_data.index('password'))}#{index+1}欄位格式不符。" if @password.size < 8
- elsif @password.blank? and !@user_id.blank?
- @error_msg << "#{make_alpha_from_numbers(@field_data.index('password'))}#{index+1}欄位格式不符。"
- end
-
- @error_msg << "#{make_alpha_from_numbers(@field_data.index('birthday'))}#{index+1}欄位日期格式不符。" if row[@field_data.index("birthday")].class.to_s != 'DateTime' and !row[@field_data.index('birthday')].blank?
+ @user_id = row[@row_index_hash['user_id']]
+ @name_lang = current_site.in_use_locales.map{|locale| ['first_name','last_name'].map{|name| row[@row_index_hash["#{name}(#{locale})"]].strip rescue ''}.select{|field| !field.blank? && !field.nil?}}
+ #@error_msg << current_site.in_use_locales.map{|locale| ['first_name','last_name'].map{|name| row[@row_index_hash["#{name}(#{locale})"]].strip rescue ''}.select{|field| !field.blank? && !field.nil?}}
+ if !@user_id.blank?
+ if !@name_lang.select{|field| !field.empty?}.empty?
+ check_id = User.where(:user_name => @user_id).first
+ # @error_msg << @filename+"中#{make_alpha_from_numbers(@field_data.index('user_id'))}#{index+1}欄位帳號已存在。" if !check_id.blank?
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash['user_id'])}#{index+1}欄位格式不符(長度不足,請超過3個字)。" if @user_id.size < 3
+ @password = row[@row_index_hash['password']]
+ if !@password.blank?
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash['password'])}#{index+1}欄位格式不符(長度不足,請至少8碼以上)。" if @password.to_s.size < 8
+ elsif @password.blank? && User.where(:user_name => @user_id).first.nil?
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash['password'])}#{index+1}欄位格式不符,請填入使用者密碼,以建立該位於#{make_alpha_from_numbers(@row_index_hash['user_id'])}#{index+1}欄位的使用者。"
+ end
+ else
+ @empty_locales = []
+ @name_lang.each_with_index{|empty_locale,i| (empty_locale.empty?) ? (@empty_locales << current_site.in_use_locales[i]) : nil}
+ @empty_locales.each do |empty_locale|
+ @name_fields_position = ['first_name','last_name'].map{|name| make_alpha_from_numbers(@row_index_hash["#{name}(#{empty_locale.to_s})"])}
+ @error_msg << @filename+"中#{@name_fields_position.join((index+1).to_s+'或')}#{index+1}欄位(#{I18n.t(empty_locale)}#{I18n.t('users.name')}})格式不符,該橫列(#{index+1}列)中有會員名(user_id欄位有值),故該橫列(#{index+1}列)之名稱不可為空。"
+ end
+ end
+ end
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash['birthday'])}#{index+1}欄位日期格式不符。" if row[@row_index_hash["birthday"]].class.to_s != 'DateTime' and !row[@row_index_hash['birthday']].blank?
@infos = MemberInfo.all
@infos.each do |info|
info.member_profile_fields.each do |member_profile_field|
-
-
-
+
+
+
if member_profile_field.markup == 'select' or member_profile_field.markup == 'radio_button'
@option_list = member_profile_field[@field_type[member_profile_field.markup]]['option_list'].collect{|p| p[0]}
@rowname = "#{info.key}-#{member_profile_field.key}"
- @error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位格式不符。" if !@option_list.include?("#{row[@field_data.index(@rowname)]}") and !row[@field_data.index(@rowname)].blank?
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash[@rowname])}#{index+1}欄位格式不符。" if !@option_list.include?("#{row[@row_index_hash[@rowname]]}") && !row[@row_index_hash[@rowname]].blank?
elsif member_profile_field.markup == 'checkbox'
@rowname = "#{info.key}-#{member_profile_field.key}"
- @error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位格式不符。" if row[@field_data.index(@rowname)].to_s.split(',').last == row[@field_data.index(@rowname)] and !row[@field_data.index(@rowname)].blank?
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash[@rowname])}#{index+1}欄位格式不符。" if row[@row_index_hash[@rowname]].to_s.split(',').last != row[@row_index_hash[@rowname]] && !row[@row_index_hash[@rowname]].blank?
elsif member_profile_field.markup == 'date'
@rowname = "#{info.key}-#{member_profile_field.key}"
- @error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位日期格式不符。" if row[@field_data.index(@rowname)].class.to_s != 'DateTime' and !row[@field_data.index(@rowname)].blank?
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash[@rowname])}#{index+1}欄位日期格式不符。" if row[@row_index_hash[@rowname]].class.to_s != 'DateTime' && !row[@row_index_hash[@rowname]].blank?
end
end
@@ -208,34 +261,39 @@ class Admin::MembersController < OrbitMemberController
@roles.each do |role|
role_statuses = RoleStatus.where(role_id: role.id, :disable=> false)
+ role_name = role.key
if !role_statuses.blank?
@rowname = "#{role.key}-status"
- if !@field_data.index(@rowname).blank?
- @error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位格式不符。" if row[@field_data.index(@rowname)].to_s.split(',').last == row[@field_data.index(@rowname)] and !row[@field_data.index(@rowname)].blank?
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ if !@row_index_hash[@rowname].blank?
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash[@rowname])}#{index+1}欄位格式不符。" if row[@row_index_hash[@rowname]].to_s.split(',').last != row[@row_index_hash[@rowname]] && !row[@row_index_hash[@rowname]].blank?
end
end
role.attribute_fields.asc(:created_at).each do |attribute_field|
-
-
+
+
if attribute_field.markup == 'select' or attribute_field.markup == 'radio_button'
@option_list = attribute_field[@field_type[attribute_field.markup]]['option_list'].collect{|p| p[0]}
@rowname = "#{role.key}-#{attribute_field.key}"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
if !@field_data.index(@rowname).blank?
- @error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位格式不符。" if !@option_list.include?("#{row[@field_data.index(@rowname)]}") and !row[@field_data.index(@rowname)].blank?
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash[@rowname])}#{index+1}欄位格式不符。" if !@option_list.include?("#{row[@row_index_hash[@rowname]]}") && !row[@row_index_hash[@rowname]].blank?
end
elsif attribute_field.markup == 'checkbox'
@rowname = "#{role.key}-#{attribute_field.key}"
- if !@field_data.index(@rowname).blank?
- @error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位格式不符。" if row[@field_data.index(@rowname)].to_s.split(',').last == row[@field_data.index(@rowname)] and !row[@field_data.index(@rowname)].blank?
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ if !@row_index_hash[@rowname].blank?
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash[@rowname])}#{index+1}欄位格式不符。" if row[@row_index_hash[@rowname]].to_s.split(',').last != row[@row_index_hash[@rowname]] && !row[@row_index_hash[@rowname]].blank?
end
elsif attribute_field.markup == 'date'
@rowname = "#{role.key}-#{attribute_field.key}"
- if !@field_data.index(@rowname).blank?
- @error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位日期格式不符。" if row[@field_data.index(@rowname)].class.to_s != 'DateTime' and !row[@field_data.index(@rowname)].blank?
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ if !@row_index_hash[@rowname].blank?
+ @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash[@rowname])}#{index+1}欄位日期格式不符。" if row[@row_index_hash[@rowname]].class.to_s != 'DateTime' && !row[@row_index_hash[@rowname]].blank?
end
end
@@ -245,213 +303,669 @@ class Admin::MembersController < OrbitMemberController
end
end
-
+ return @error_msg
+ end
+ def export_members
+ end
+ def read_xlsx_temp_file_and_import_members(tempfile,unzip_path = nil,filename = nil)
+ @text = ''
+ if !tempfile.blank?
+ @error_msg = import_data_check(tempfile,filename)
+ if @error_msg.blank?
+ @members_list_tmp = []
+ profile_data_row = ["user_id","password","email","sid","office_tel","sex","birthday","avatar"]
+ profile_lang_data_row = ["first_name","last_name","address","autobiography","fax","mobile_no"]
+ @field_type = {'text_field' => 'typeA', 'select' => 'typeB', 'date' => 'typeC', 'text_area' => 'typeD', 'radio_button' => 'typeE', 'checkbox' => 'typeE', 'address' => ''}
+ @date_type = {'format1' => '%Y/%m/%d %H:%M', 'format2' => '%Y/%m/%d', 'format3' => '%Y/%m', 'format4' => '%Y'}
+ workbook = RubyXL::Parser.parse(tempfile)
+ sheet = workbook['Member'].sheet_data.rows
+ sheet.each_with_index do |raw_row,index|
+ row = raw_row.cells.map{ |cell| cell.value rescue nil}
+ if index == 0
+ @field_data = row
+ end
+ if index == 1
+ @row_index_hash = {}
+ profile_data_row.each do |row_key|
+ @row_index_hash[row_key] = @field_data.index(row_key)
+ end
+ profile_lang_data_row.each do |lang_row_key|
+ current_site.in_use_locales.each do |locale_name|
+ @row_index_hash[lang_row_key+"(#{locale_name})"] = @field_data.index(lang_row_key+"(#{locale_name})")
+ end
+ end
+ end
+ if index > 2
+ @member_profile = MemberProfile.new
+ @site_in_use_locales.each_with_index do |locale, i|
+ # profile_lang_data_row.each do |profile_lang|
+ #(@member_profile.send(profile_lang+'_translations'+'=' , @member_profile.send(profile_lang+'_translations').merge("#{locale}" => row[@field_data.index("#{profile_lang}(#{locale})")]))) if !row[@field_data.index("#{profile_lang}(#{locale})")].blank?
+ @member_profile.first_name_translations = @member_profile.first_name_translations.merge!( "#{locale}" => row[@row_index_hash["first_name(#{locale})"]]) if !row[@row_index_hash["first_name(#{locale})"]].blank?
+ @member_profile.last_name_translations = @member_profile.last_name_translations.merge!( "#{locale}" => row[@row_index_hash["last_name(#{locale})"]]) if !row[@row_index_hash["last_name(#{locale})"]].blank?
+ @member_profile.address_translations = @member_profile.address_translations.merge!( "#{locale}" => row[@row_index_hash["address(#{locale})"]]) if !row[@row_index_hash["address(#{locale})"]].blank?
+ @member_profile.autobiography_translations = @member_profile.autobiography_translations.merge!( "#{locale}" => row[@row_index_hash["autobiography(#{locale})"]]) if !row[@row_index_hash["autobiography(#{locale})"]].blank?
+ # end
+ end
+ @member_profile.email = row[@row_index_hash["email"]]
+ @member_profile.sid = row[@row_index_hash["sid"]]
+ @member_profile.office_tel = row[@row_index_hash["office_tel"]]
+ @member_profile.sex = ( row[@row_index_hash["sex"]] == 'male' or row[@row_index_hash["sex"]] == 'female' ) ? row[@row_index_hash["sex"]] : 'unknown'
+ @member_profile.birthday = row[@row_index_hash["birthday"]].class.to_s == 'DateTime' ? row[@row_index_hash["birthday"]] : ''
+ @avatar = row[@row_index_hash["avatar"]] rescue ''
+ if @avatar != '' && !@avatar.nil?
+ @cache_dir = @member_profile.avatar.cache_dir
+ FileUtils.cp @avatar,@cache_dir
+ Dir.chdir(@cache_dir) do
+ @member_profile.avatar = File.open(@avatar)
+ end
+ end
+ @member = @members_list.select{|member| member.name == @member_profile.name}.first
+ if !@member.nil?
+ @member_profile = @member
+ else
+ @member_profile.save
+ @members_list_tmp << @member_profile
+ end
+ @infos = MemberInfo.all
+ @infos.each do |info|
+ info.member_profile_fields.each do |member_profile_field|
+ value = member_profile_field.member_profile_field_values.build
+ value.member_profile_id = @member_profile.id
+ if member_profile_field.markup == 'text_field' or member_profile_field.markup == 'text_area'
+ if member_profile_field[@field_type[member_profile_field.markup]]['cross_lang'] == 'true'
+ @rowname = "#{info.key}-#{member_profile_field.key}"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ value["val"] = row[@row_index_hash[@rowname]] if !row[@row_index_hash[@rowname]].blank?
+ else
+ @site_in_use_locales.each_with_index do |locale, i|
+ @rowname = "#{info.key}-#{member_profile_field.key}(#{locale})"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ value["#{locale}"] = row[@row_index_hash[@rowname]] if !row[@row_index_hash[@rowname]].blank?
+ end
+ end
+ elsif member_profile_field.markup == 'checkbox'
+ @rowname = "#{info.key}-#{member_profile_field.key}"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ value["val"] = row[@row_index_hash[@rowname]].to_s.split(',') if !row[@row_index_hash[@rowname]].blank?
+ elsif member_profile_field.markup == 'date'
+ @rowname = "#{info.key}-#{member_profile_field.key}"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ value["val"] = row[@row_index_hash[@rowname]].class.to_s == 'DateTime' ? row[@row_index_hash[@rowname]].to_datetime.strftime(@date_type[member_profile_field['typeC']['format']]) : ''
+ elsif member_profile_field.markup == 'address'
+ @site_in_use_locales.each_with_index do |locale, i|
+ @rowname = "#{info.key}-#{member_profile_field.key}(#{locale})"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ value["#{locale}"] = row[@row_index_hash[@rowname]] if !row[@row_index_hash[@rowname]].blank?
+ end
+ else
+ @rowname = "#{info.key}-#{member_profile_field.key}"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ value["val"] = "#{row[@row_index_hash[@rowname]]}"
+ end
+ value.save
+ end
+ end
+ @role_status_data = []
+ @roles = Role.all
+ @roles.each do |role|
+ role_statuses = RoleStatus.where(role_id: role.id, :disable=> false).asc(:_id)
+ if !role_statuses.blank?
+ @rowname = "#{role.key}-status"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ if !@row_index_hash[@rowname].blank?
+ if !row[@row_index_hash[@rowname]].blank?
+ @status_value = row[@row_index_hash[@rowname]].to_s.split(',')
+ role_statuses.each do |role_status|
+ if @status_value.include?(role_status.key)
+ @role_status_data << role_status.id
+ end
+ end
+ end
+ end
+ end
+ @role_add_value = 0
+ role.attribute_fields.asc(:created_at).each do |attribute_field|
+ value = attribute_field.attribute_values.build
+ value.member_profile_id = @member_profile.id
+ if attribute_field.markup == 'text_field' or attribute_field.markup == 'text_area'
+ if attribute_field[@field_type[attribute_field.markup]]['cross_lang'] == 'true'
+ @rowname = "#{role.key}-#{attribute_field.key}"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ if !@row_index_hash[@rowname].blank?
+ if !row[@row_index_hash[@rowname]].blank?
+ value["val"] = row[@row_index_hash[@rowname]]
+ @role_add_value = @role_add_value + 1
+ end
+ end
+ else
+ @site_in_use_locales.each_with_index do |locale, i|
+ @rowname = "#{role.key}-#{attribute_field.key}(#{locale})"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ if !@row_index_hash[@rowname].blank?
+ if !row[@row_index_hash[@rowname]].blank?
+ value["#{locale}"] = row[@row_index_hash[@rowname]]
+ @role_add_value = @role_add_value + 1
+ end
+ end
+ end
+ end
+ elsif attribute_field.markup == 'checkbox'
+ @rowname = "#{role.key}-#{attribute_field.key}"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ if !@row_index_hash[@rowname].blank?
+ if !row[@row_index_hash[@rowname]].blank?
+ value["val"] = row[@row_index_hash[@rowname]].to_s.split(',')
+ @role_add_value = @role_add_value + 1
+ end
+ end
+ elsif attribute_field.markup == 'date'
+ @rowname = "#{role.key}-#{attribute_field.key}"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ if !@row_index_hash[@rowname].blank?
+ value["val"] = row[@row_index_hash[@rowname]].class.to_s == 'DateTime' ? row[@row_index_hash[@rowname]].to_datetime.strftime(@date_type[attribute_field['typeC']['format']]) : ''
+ end
+ elsif attribute_field.markup == 'address'
+ @site_in_use_locales.each_with_index do |locale, i|
+ @rowname = "#{role.key}-#{attribute_field.key}(#{locale})"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ if !@row_index_hash[@rowname].blank?
+ if !row[@row_index_hash[@rowname]].blank?
+ value["#{locale}"] = row[@row_index_hash[@rowname]]
+ @role_add_value = @role_add_value + 1
+ end
+ end
+ end
+ else
+ @rowname = "#{role.key}-#{attribute_field.key}"
+ @row_index_hash[@rowname] = @field_data.index(@rowname) if index == 3
+ if !@row_index_hash[@rowname].blank?
+ if !row[@row_index_hash[@rowname]].blank?
+ value["val"] = "#{row[@row_index_hash[@rowname]]}"
+ @role_add_value = @role_add_value + 1
+ end
+ end
+ end
+ value.save
+ end
+ if @role_add_value > 0
+ role.member_profiles << @member_profile
+ role.save
+ end
+ end
+ if !@role_status_data.blank?
+ @member_profile.role_status_ids = @role_status_data
+ @member_profile.save
+ end
+ if !row[@row_index_hash["password"]].to_s.blank? && !row[@row_index_hash["user_id"]].to_s.blank?
+ if !User.where(:user_name=> row[@row_index_hash["user_id"]]).first.nil?
+ @user = User.where(:user_name=> row[@row_index_hash["user_id"]]).first
+ @user.update_password(row[@row_index_hash["password"]].to_s, row[@row_index_hash["password"]].to_s)
+ @user = User.where(:user_name=> row[@row_index_hash["user_id"]]).first
+ @user.member_profile = @member_profile
+ @user.approved = true
+ @user.save
+ else
+ @user = User.new(
+ user_name: row[@row_index_hash["user_id"]],
+ password: row[@row_index_hash["password"]],
+ member_profile: @member_profile,
+ approved: true
+ )
+ @user.save
+ end
+ elsif row[@row_index_hash["password"]].to_s.blank? && !row[@row_index_hash["user_id"]].to_s.blank?
+ @user = User.where(:user_name=> row[@row_index_hash["user_id"]]).first
+ if !@user.nil?
+ @user.member_profile = @member_profile
+ @user.save
+ end
+ end
+ end
+ end
+ @members_list.concat(@members_list_tmp)
+ return true
+ #redirect_to admin_members_path
+ else
+ return false
+ #render 'import_error_msg'
+ end
+ end
end
-
def import_members
+ if !params[:file].blank?
+ #render :html => get_image_extension(params[:file].tempfile.path) and return
+ @members_list = []
+ if( params[:file].original_filename.to_s.reverse.index('.xlsx'.reverse) == 0 rescue false)
+ flag = read_xlsx_temp_file_and_import_members(params[:file].tempfile,nil,params[:file].original_filename)
+ if flag == true
+ redirect_to admin_members_path
+ else
+ render 'import_error_msg'
+ end
+ elsif( params[:file].original_filename.to_s.reverse.index('.zip'.reverse) == 0 rescue false)
+ unzip_path = 'tmp/unzip/'
+ FileUtils.rm_r(unzip_path,:force=>true) if Dir.exist? unzip_path
+ FileUtils.mkdir_p unzip_path
+ ZipFileGenerator.new(params[:file].tempfile.path,unzip_path).extract_zip
+ flag = true
+ Dir.chdir(unzip_path) do
+ @filenames = `ls`.split
+ @filenames.each do |filename|
+ if filename.reverse.index('.xlsx'.reverse) == 0
+ @file = File.open(filename,'r')
+ flag = read_xlsx_temp_file_and_import_members(@file,unzip_path,filename)
+ @file.close
+ end
+ break if flag == false
+ end
+ end
+ #return
+ #zip_data = read_zip(params[:file].tempfile)
+ # zip_data.each do |data|
+ # temp_file = Tempfile.new(['temp','.xlsx'], encoding: 'ascii-8bit')
+ # temp_file << data
+ # #if get_image_extension(temp_file.path) == 'jpg' || get_image_extension(temp_file.path) == 'png' || get_image_extension(temp_file.path) == 'gif'
+ # #File.open(||
+ # #next
+ # #end
+ # #temp_file.close
+ # #render :html => temp_file.path and return
+ # flag = read_xlsx_temp_file_and_import_members(temp_file.open)
+ # temp_file.close
+ # end
+
+ if flag == true
+ redirect_to admin_members_path
+ else
+ render 'import_error_msg'
+ end
+ end
+ end
+ end
+ def get_image_extension(local_file_path)
+ png = Regexp.new("\x89PNG".force_encoding("binary"))
+ jpg = Regexp.new("\xff\xd8\xff\xe0\x00\x10JFIF".force_encoding("binary"))
+ jpg2 = Regexp.new("\xff\xd8\xff\xe1(.*){2}Exif".force_encoding("binary"))
+ case IO.read(local_file_path, 10)
+ when /^GIF8/
+ 'gif'
+ when /^#{png}/
+ 'png'
+ when /^#{jpg}/
+ 'jpg'
+ when /^#{jpg2}/
+ 'jpg'
+ else
+ mime_type = `file #{local_file_path} --mime-type`.gsub("\n", '') # Works on linux and mac
+ raise UnprocessableEntity, "unknown file type" if !mime_type
+ mime_type.split(':')[1].split('/')[1].gsub('x-', '').gsub(/jpeg/, 'jpg').gsub(/text/, 'txt').gsub(/x-/, '')
+ end
+ end
+ def export_members_data
+ @users = User.all
+ @member_role = params[:member_role].blank? ? Role.all.asc(:_id) : params[:member_role]
+ @member_roles = @member_role.collect{|a| a[0]}
+ zip_path = 'tmp/member_tmp/'
+ tmp_filename = ''
+ FileUtils.rm_r(zip_path, :force => true) if Dir.exist?(zip_path)
+ FileUtils.mkdir zip_path #create dir for storing tmp_file
+ if params[:member_role].nil?
+ write_zip = true
+ roles = Role.all.take_while{true}
+ index = 0
+ role_hash_arr = []
+ roles.each do |role|
+ member_info_hash_arr = []
+ if !role.member_profile_ids.nil?
+ role.member_profile_ids.each do |profile_id|
+ member_info_hash = {}
+ member_profile = MemberProfile.find(profile_id) rescue next
+ next if member_profile.nil?
+ if !member_profile.user.nil?
+ member_info_hash['user_id'] = member_profile.user.user_name
+ end
+ attr_field = ['first_name','last_name','email','sid','office_tel','sex','birthday','address','autobiography']
+ attr_field.each do |attr|
+ member_info_hash[attr] = member_profile[attr]
+ end
+ member_info_hash['member_info'] = []
+ if MemberInfo.all.length != 0
+ MemberInfo.all.take_while{true}.each do |info|
+ info.member_profile_fields.each do |member_profile_fields|
+ @member_profile_field_value = member_profile_fields.to_a.map{|member_profile_field| MemberProfileField.find(member_profile_field.id).member_profile_field_values.to_a rescue next}.map{|member_profile_field_value| member_profile_field_value.select{|field_value| field_value.member_profile_id == profile_id}}
+ temp_info = {}
+ if @member_profile_field_value.length != 0
+ current_site.in_use_locales.each do |locale|
+ temp_info[locale] = @member_profile_field_value.first.first[locale] rescue ''
+ end
+ else
+ current_site.in_use_locales.each do |locale|
+ temp_info[locale] = ''
+ end
+ end
+ member_info_hash['member_info'].push(temp_info)
+ end
+ end
+ end
+ member_profile.role_status_ids.each do |role_status_id|
+ role_status = RoleStatus.find(role_status_id) rescue nil
+ next if role_status.nil?
+ member_info_hash.merge!( {"status"=>role_status.key}) if role_status.role_id == role.id
+ end
+ role_keys = member_profile.roles.select{|r| r==role}[0].attribute_fields.where(:disabled=>false).asc(:_id).map{|rf| rf.title} rescue nil
+ role_keys.map{|role_key| member_info_hash[role_key] = {}}
+ current_site.in_use_locales.each do |locale|
+ role_values = member_profile.roles.select{|r| r==role}[0].attribute_fields.where(:disabled=>false).asc(:_id).map{|rf| (member_profile.get_attribute_value(rf,"role").get_value_by_locale(locale.to_s) rescue '')}
+ role_keys.each_with_index do |role_key,i|
+ member_info_hash[role_key][locale] = role_values[i]
+ end
+ end
+ locale_name = current_site.in_use_locales.first
+ role_select_names = role.attribute_fields.map{|field| field.option_list.map{|key,value| value[locale_name]}}
+ role_select_names.each_with_index do |select_name_arr,i|
+ next if select_name_arr.empty?
+ member_info_hash[role_keys[i]] = select_name_arr.index(member_info_hash[role_keys[i]][locale_name]).to_s
+ end
+ member_info_hash['role_keys'] = role_keys
+ if member_profile.avatar.file.nil?
+ member_info_hash['avatar'] = ''
+ else
+ if member_profile.avatar.file.exists?
+ write_zip = true
+ @original_filename = member_profile.avatar.file.filename
+ @picture_name = zip_path+ member_profile.name.delete(' ') + @original_filename[@original_filename.rindex('.')..-1]
+ member_info_hash['avatar'] = member_profile.name.delete(' ') + @original_filename[(@original_filename.rindex('.'))..-1]
+ File.open(@picture_name, 'w:ascii-8bit') do |f|
+ f.write(member_profile.avatar.file.read)
+ end
+ end
+ end
+ member_info_hash_arr.push member_info_hash
+ end
+ end
+ next if member_info_hash_arr == []
+
+ role_hash_arr.push member_info_hash_arr
+ if role.key.to_s == ''
+ role_name = role.title
+ else
+ role_name = role.key.to_s
+ end
+ @filename = zip_path+'member_export_'+role_name+'.xlsx'
+ @member_roles = {'key'=>role.key,'title'=>role.title}
+ if File.exist?(@filename)
+ i = 0
+ while File.exist?(@filename[0..-6]+i.to_s+'.xlsx')
+ i += 1
+ end
+ @filename = @filename[0..-6]+i.to_s+'.xlsx'
+ end
+ File.open(@filename, 'w') do |f|
+ f.write render_to_string( handlers: [:axlsx], formats: [:xlsx] ,partial: 'export_members_data.xlsx',locals: {:@member_roles=>@member_roles,:@member_data_list=>member_info_hash_arr,:@site_in_use_locales=>@site_in_use_locales} )
+ end
+ end
+ no_role_members = []
+ MemberProfile.all.any_in(:role_ids=>[nil,[]]).each do |member_profile|
+ member_info_hash = {}
+ if !member_profile.user.nil?
+ member_info_hash['user_id'] = member_profile.user.user_name
+ end
+ attr_field = ['first_name','last_name','email','sid','office_tel','sex','birthday','address','autobiography']
+ attr_field.each do |attr|
+ member_info_hash[attr] = member_profile[attr]
+ end
+ member_info_hash['member_info'] = []
+ if MemberInfo.all.length != 0
+ MemberInfo.all.take_while{true}.each do |info|
+ info.member_profile_fields.each do |member_profile_fields|
+ @member_profile_field_value = member_profile_fields.to_a.map{|member_profile_field| MemberProfileField.find(member_profile_field.id).member_profile_field_values.to_a rescue next}.map{|member_profile_field_value| member_profile_field_value.select{|field_value| field_value.member_profile_id == member_profile.id}}
+ temp_info = {}
+ if @member_profile_field_value.length != 0
+ current_site.in_use_locales.each do |locale|
+ temp_info[locale] = @member_profile_field_value.first.first[locale] rescue ''
+ end
+ else
+ current_site.in_use_locales.each do |locale|
+ temp_info[locale] = ''
+ end
+ end
+ member_info_hash['member_info'].push(temp_info)
+ end
+ end
+ end
+ if member_profile.avatar.file.nil?
+ member_info_hash['avatar'] = ''
+ else
+ if member_profile.avatar.file.exists?
+ write_zip = true
+ @original_filename = member_profile.avatar.file.filename
+ @picture_name = zip_path+ member_profile.name.delete(' ') + @original_filename[@original_filename.rindex('.')..-1]
+ member_info_hash['avatar'] = member_profile.name.delete(' ') + @original_filename[(@original_filename.rindex('.'))..-1]
+ File.open(@picture_name, 'w:ascii-8bit') do |f|
+ f.write(member_profile.avatar.file.read)
+ end
+ end
+ end
+ member_info_hash['role_keys'] = []
+ no_role_members.push member_info_hash
+ end
+ @filename = zip_path+'member_export_no_role_members.xlsx'
+ if File.exist?(@filename)
+ i = 0
+ while File.exist?(@filename[0..-6]+i.to_s+'.xlsx')
+ i += 1
+ end
+ @filename = @filename[0..-6]+i.to_s+'.xlsx'
+ end
+ File.open(@filename, 'w') do |f|
+ f.write render_to_string( handlers: [:axlsx], formats: [:xlsx] ,partial: 'export_members_data.xlsx',locals: {:@member_roles=>nil,:@member_data_list=>no_role_members,:@site_in_use_locales=>@site_in_use_locales} )
+ end
+ #create zip from dir start
+ zip_file= ZipFileGenerator.new(zip_path,Pathname.new(zip_path).parent.to_s+'/member_export_data.zip')
+ begin
+ zip_file.write
+ rescue
+ File.delete(Pathname.new(zip_path).parent.to_s+'/member_export_data.zip')
+ zip_file.write
+ end
+ #create zip from dir end
+ else
+ write_zip = false
+ write_zip = (true if params[:member_role].keys.length > 1 rescue false)
+ params[:member_role].keys.each do |role_key|
+ if role_key == 'no_role'
+ no_role_members = []
+ MemberProfile.all.any_in(:role_ids=>[nil,[]]).each do |member_profile|
+ member_info_hash = {}
+ if !member_profile.user.nil?
+ member_info_hash['user_id'] = member_profile.user.user_name
+ end
+ attr_field = ['first_name','last_name','email','sid','office_tel','sex','birthday','address','autobiography']
+ attr_field.each do |attr|
+ member_info_hash[attr] = member_profile[attr]
+ end
+ member_info_hash['member_info'] = []
+ if MemberInfo.all.length != 0
+ MemberInfo.all.take_while{true}.each do |info|
+ info.member_profile_fields.each do |member_profile_fields|
+ @member_profile_field_value = member_profile_fields.to_a.map{|member_profile_field| MemberProfileField.find(member_profile_field.id).member_profile_field_values.to_a rescue next}.map{|member_profile_field_value| member_profile_field_value.select{|field_value| field_value.member_profile_id == member_profile.id}}
+ temp_info = {}
+ if @member_profile_field_value.length != 0
+ current_site.in_use_locales.each do |locale|
+ temp_info[locale] = @member_profile_field_value.first.first[locale] rescue ''
+ end
+ else
+ current_site.in_use_locales.each do |locale|
+ temp_info[locale] = ''
+ end
+ end
+ member_info_hash['member_info'].push(temp_info)
+ end
+ end
+ end
+ if member_profile.avatar.file.nil?
+ member_info_hash['avatar'] = ''
+ else
+ if member_profile.avatar.file.exists?
+ write_zip = true
+ @original_filename = member_profile.avatar.file.filename
+ @picture_name = zip_path+ member_profile.name.delete(' ') + @original_filename[@original_filename.rindex('.')..-1]
+ member_info_hash['avatar'] = member_profile.name.delete(' ') + @original_filename[(@original_filename.rindex('.'))..-1]
+ File.open(@picture_name, 'w:ascii-8bit') do |f|
+ f.write(member_profile.avatar.file.read)
+ end
+ end
+ end
+ member_info_hash['role_keys'] = []
+ no_role_members.push member_info_hash
+ end
+ @filename = zip_path+'member_export_no_role_members.xlsx'
+ if File.exist?(@filename)
+ i = 0
+ while File.exist?(@filename[0..-6]+i.to_s+'.xlsx')
+ i += 1
+ end
+ @filename = @filename[0..-6]+i.to_s+'.xlsx'
+ end
+ File.open(@filename, 'w') do |f|
+ f.write render_to_string( handlers: [:axlsx], formats: [:xlsx] ,partial: 'export_members_data.xlsx',locals: {:@member_roles=>nil,:@member_data_list=>no_role_members,:@site_in_use_locales=>@site_in_use_locales} )
+ end
+ else
+ begin
+ role = Role.where(:key=>role_key).first
+ role = Role.where(:title=>role_key).first if role.nil?
+ rescue
+ next
+ end
+ member_info_hash_arr = []
+ if !role.member_profile_ids.nil?
+ role.member_profile_ids.each do |profile_id|
+ member_info_hash = {}
+ member_profile = MemberProfile.find(profile_id) rescue next
+ next if member_profile.nil?
+ if !member_profile.user.nil?
+ member_info_hash['user_id'] = member_profile.user.user_name
+ end
+ attr_field = ['first_name','last_name','email','sid','office_tel','sex','birthday','address','autobiography','fax','office_tel','mobile_no']
+ attr_field.each do |attr|
+ member_info_hash[attr] = member_profile[attr]
+ end
+ member_info_hash['member_info'] = []
+ if MemberInfo.all.length != 0
+ MemberInfo.all.take_while{true}.each do |info|
+ info.member_profile_fields.each do |member_profile_fields|
+ @member_profile_field_value = member_profile_fields.to_a.map{|member_profile_field| MemberProfileField.find(member_profile_field.id).member_profile_field_values.to_a rescue next}.map{|member_profile_field_value| member_profile_field_value.select{|field_value| field_value.member_profile_id == profile_id}}
+ temp_info = {}
+ if @member_profile_field_value.length != 0
+ current_site.in_use_locales.each do |locale|
+ temp_info[locale] = @member_profile_field_value.first.first[locale] rescue ''
+ end
+ else
+ current_site.in_use_locales.each do |locale|
+ temp_info[locale] = ''
+ end
+ end
+ member_info_hash['member_info'].push(temp_info)
+ end
+ end
+ end
+ member_profile.role_status_ids.each do |role_status_id|
+ role_status = RoleStatus.find(role_status_id) rescue nil
+ next if role_status.nil?
+ member_info_hash.merge!( {"status"=>role_status.key}) if role_status.role_id == role.id
+ end
+ role_keys = member_profile.roles.select{|r| r==role}[0].attribute_fields.where(:disabled=>false).asc(:_id).map{|rf| rf.title} rescue nil
+ role_keys.map{|role_key| member_info_hash[role_key] = {}}
+ current_site.in_use_locales.each do |locale|
+ role_values = member_profile.roles.select{|r| r==role}[0].attribute_fields.where(:disabled=>false).asc(:_id).map{|rf| (member_profile.get_attribute_value(rf,"role").get_value_by_locale(locale)) rescue ''}
+ role_keys.each_with_index do |role_key,i|
+ member_info_hash[role_key][locale] = role_values[i]
+ end
+ end
+ locale_name = current_site.in_use_locales.first
+ role_select_names = role.attribute_fields.map{|field| field.option_list.map{|key,value| value[locale_name]}}
+ role_select_names.each_with_index do |select_name_arr,i|
+ next if select_name_arr.empty?
+ member_info_hash[role_keys[i]] = select_name_arr.index(member_info_hash[role_keys[i]][locale_name]).to_s
+ end
+ member_info_hash['role_keys'] = role_keys
+ if member_profile.avatar.file.nil?
+ member_info_hash['avatar'] = ''
+ else
+ if member_profile.avatar.file.exists?
+ write_zip = true
+ @original_filename = member_profile.avatar.file.filename
+ @picture_name = zip_path+ member_profile.name.delete(' ') + @original_filename[(@original_filename.rindex('.'))..-1]
+ member_info_hash['avatar'] = member_profile.name.delete(' ') + @original_filename[(@original_filename.rindex('.'))..-1]
+ File.open(@picture_name, 'w:ascii-8bit') do |f|
+ f.write(member_profile.avatar.file.read)
+ end
+ end
+ end
+ member_info_hash_arr.push member_info_hash
+ end
+ end
+ next if member_info_hash_arr == []
+ if write_zip == false
+ tmp_filename = 'member_export_'+role_key+'.xlsx'
+ end
+ @filename = zip_path+'/member_export_'+role_key+'.xlsx'
+ @member_roles = {'key'=>role.key,'title'=>role.title}
+ if File.exist?(@filename)
+ i = 0
+ while File.exist?(@filename[0..-6]+i.to_s+'.xlsx')
+ i += 1
+ end
+ @filename = @filename[0..-6]+i.to_s+'.xlsx'
+ end
+ File.open(@filename, 'w') do |f|
+ f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'export_members_data.xlsx',:locals=> {:@member_roles=>@member_roles,:@member_data_list=>member_info_hash_arr,:@site_in_use_locales=>@site_in_use_locales} )
+ end
+ end
+ end
+ if write_zip == true
+ #create zip from dir start
+ zip_file= ZipFileGenerator.new(zip_path,Pathname.new(zip_path).parent.to_s+'/member_export_data.zip')
+ begin
+ zip_file.write
+ rescue
+ File.delete(Pathname.new(zip_path).parent.to_s+'/member_export_data.zip')
+ zip_file.write
+ end
+ #create zip from dir end
+ end
+ end
+ Dir.chdir zip_path do
+ if `ls`.split().length == 1
+ write_zip = false
+ tmp_filename = `ls`.split()[0]
+ end
+ end
+ if write_zip == true
+ zip_data = File.read(Pathname.new(zip_path).parent.to_s+'/member_export_data.zip')
+ send_data(zip_data, type: 'application/zip', disposition: 'attachment', filename: "member_export_data.zip")
+ else
+ if tmp_filename != ""
+ tmp_filename_data = File.read(zip_path +tmp_filename)
+ send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: tmp_filename)
+ else
+ redirect_to admin_members_export_members_path+'?error=true'
+ end
+ end
- if !params[:file].blank?
-
- import_data_check(params[:file])
-
- if @error_msg.blank?
-
- profile_data_row = ["email","sid","office_tel","sex","birthday"]
- profile_lang_data_row = ["first_name","last_name","address","autobiography"]
-
- @field_type = {'text_field' => 'typeA', 'select' => 'typeB', 'date' => 'typeC', 'text_area' => 'typeD', 'radio_button' => 'typeE', 'checkbox' => 'typeE', 'address' => ''}
-
- @date_type = {'format1' => '%Y/%m/%d %H:%M', 'format2' => '%Y/%m/%d', 'format3' => '%Y/%m', 'format4' => '%Y'}
-
- workbook = RubyXL::Parser.parse(params[:file].tempfile)
- sheet = workbook['Member'].extract_data
- sheet.each_with_index do |row,index|
- if index == 0
- @field_data = row
- end
- if index > 2
- if !row[0].blank? and !row[1].blank?
-
- @member_profile = MemberProfile.new
-
- @site_in_use_locales.each_with_index do |locale, i|
-
- @member_profile.first_name_translations = @member_profile.first_name_translations.merge!( "#{locale}" => row[@field_data.index("first_name(#{locale})")]) if !row[@field_data.index("first_name(#{locale})")].blank?
- @member_profile.last_name_translations = @member_profile.last_name_translations.merge!( "#{locale}" => row[@field_data.index("last_name(#{locale})")]) if !row[@field_data.index("last_name(#{locale})")].blank?
- @member_profile.address_translations = @member_profile.address_translations.merge!( "#{locale}" => row[@field_data.index("address(#{locale})")]) if !row[@field_data.index("address(#{locale})")].blank?
- @member_profile.autobiography_translations = @member_profile.autobiography_translations.merge!( "#{locale}" => row[@field_data.index("autobiography(#{locale})")]) if !row[@field_data.index("autobiography(#{locale})")].blank?
-
- end
-
- @member_profile.email = row[@field_data.index("email")]
- @member_profile.sid = row[@field_data.index("sid")]
- @member_profile.office_tel = row[@field_data.index("office_tel")]
- @member_profile.sex = ( row[@field_data.index("sex")] == 'male' or row[@field_data.index("sex")] == 'female' ) ? row[@field_data.index("sex")] : 'unknown'
- @member_profile.birthday = row[@field_data.index("birthday")].class.to_s == 'DateTime' ? row[@field_data.index("birthday")] : ''
-
- @member_profile.save
-
- @infos = MemberInfo.all
- @infos.each do |info|
- info.member_profile_fields.each do |member_profile_field|
-
- value = member_profile_field.member_profile_field_values.build
- value.member_profile_id = @member_profile.id
-
- if member_profile_field.markup == 'text_field' or member_profile_field.markup == 'text_area'
- if member_profile_field[@field_type[member_profile_field.markup]]['cross_lang'] == 'true'
- @rowname = "#{info.key}-#{member_profile_field.key}"
- value["val"] = row[@field_data.index(@rowname)] if !row[@field_data.index(@rowname)].blank?
- else
- @site_in_use_locales.each_with_index do |locale, i|
- @rowname = "#{info.key}-#{member_profile_field.key}(#{locale})"
- value["#{locale}"] = row[@field_data.index(@rowname)] if !row[@field_data.index(@rowname)].blank?
- end
- end
- elsif member_profile_field.markup == 'checkbox'
- @rowname = "#{info.key}-#{member_profile_field.key}"
- value["val"] = row[@field_data.index(@rowname)].to_s.split(',') if !row[@field_data.index(@rowname)].blank?
- elsif member_profile_field.markup == 'date'
- @rowname = "#{info.key}-#{member_profile_field.key}"
- value["val"] = row[@field_data.index(@rowname)].class.to_s == 'DateTime' ? row[@field_data.index(@rowname)].to_datetime.strftime(@date_type[member_profile_field['typeC']['format']]) : ''
- elsif member_profile_field.markup == 'address'
- @site_in_use_locales.each_with_index do |locale, i|
- @rowname = "#{info.key}-#{member_profile_field.key}(#{locale})"
- value["#{locale}"] = row[@field_data.index(@rowname)] if !row[@field_data.index(@rowname)].blank?
- end
- else
- @rowname = "#{info.key}-#{member_profile_field.key}"
- value["val"] = "#{row[@field_data.index(@rowname)]}"
- end
-
- value.save
-
- end
-
- end
-
- @role_status_data = []
- @roles = Role.all
- @roles.each do |role|
-
- role_statuses = RoleStatus.where(role_id: role.id, :disable=> false).asc(:_id)
- if !role_statuses.blank?
- @rowname = "#{role.key}-status"
-
- if !@field_data.index(@rowname).blank?
- if !row[@field_data.index(@rowname)].blank?
- @status_value = row[@field_data.index(@rowname)].to_s.split(',')
- role_statuses.each do |role_status|
- if @status_value.include?(role_status.key)
- @role_status_data << role_status.id
- end
- end
- end
- end
-
- end
-
- @role_add_value = 0
-
- role.attribute_fields.asc(:created_at).each do |attribute_field|
-
- value = attribute_field.attribute_values.build
- value.member_profile_id = @member_profile.id
-
- if attribute_field.markup == 'text_field' or attribute_field.markup == 'text_area'
- if attribute_field[@field_type[attribute_field.markup]]['cross_lang'] == 'true'
- @rowname = "#{role.key}-#{attribute_field.key}"
- if !@field_data.index(@rowname).blank?
- if !row[@field_data.index(@rowname)].blank?
- value["val"] = row[@field_data.index(@rowname)]
- @role_add_value = @role_add_value + 1
- end
- end
- else
- @site_in_use_locales.each_with_index do |locale, i|
- @rowname = "#{role.key}-#{attribute_field.key}(#{locale})"
- if !@field_data.index(@rowname).blank?
- if !row[@field_data.index(@rowname)].blank?
- value["#{locale}"] = row[@field_data.index(@rowname)]
- @role_add_value = @role_add_value + 1
- end
- end
- end
- end
- elsif attribute_field.markup == 'checkbox'
- @rowname = "#{role.key}-#{attribute_field.key}"
- if !@field_data.index(@rowname).blank?
- if !row[@field_data.index(@rowname)].blank?
- value["val"] = row[@field_data.index(@rowname)].to_s.split(',')
- @role_add_value = @role_add_value + 1
- end
- end
- elsif attribute_field.markup == 'date'
- @rowname = "#{role.key}-#{attribute_field.key}"
- if !@field_data.index(@rowname).blank?
- value["val"] = row[@field_data.index(@rowname)].class.to_s == 'DateTime' ? row[@field_data.index(@rowname)].to_datetime.strftime(@date_type[attribute_field['typeC']['format']]) : ''
- end
- elsif attribute_field.markup == 'address'
- @site_in_use_locales.each_with_index do |locale, i|
- @rowname = "#{role.key}-#{attribute_field.key}(#{locale})"
- if !@field_data.index(@rowname).blank?
- if !row[@field_data.index(@rowname)].blank?
- value["#{locale}"] = row[@field_data.index(@rowname)]
- @role_add_value = @role_add_value + 1
- end
- end
- end
- else
- @rowname = "#{role.key}-#{attribute_field.key}"
- if !@field_data.index(@rowname).blank?
- if !row[@field_data.index(@rowname)].blank?
- value["val"] = "#{row[@field_data.index(@rowname)]}"
- @role_add_value = @role_add_value + 1
- end
- end
- end
-
- value.save
-
- end
-
- if @role_add_value > 0
- role.member_profiles << @member_profile
- role.save
- end
-
- end
-
- if !@role_status_data.blank?
- @member_profile.role_status_ids = @role_status_data
- @member_profile.save
- end
-
- @user = User.new(
- user_name: row[@field_data.index("user_id")],
- password: row[@field_data.index("password")],
- member_profile_id: @member_profile.id,
- approved: true
- )
- @user.save
-
- end
-
- end
-
- end
-
- redirect_to admin_members_path
-
- else
-
- render 'import_error_msg'
-
- end
-
- end
end
+ def read_zip(zip_path)
+ zip_data = []
+ Zip::File.open(zip_path) do |zipfile|
+ zipfile.each do |entry|
+ # Read into memory
+ content = entry.get_input_stream.read
+ zip_data.push content
+ end
+ end
+ return zip_data #it's ascii-8bit data
+ end
def download_export
@users = User.all
@@ -466,6 +980,7 @@ class Admin::MembersController < OrbitMemberController
end
def new
+ sort_role_attr_field
if has_access?
@member = MemberProfile.new
get_info_and_roles
@@ -477,7 +992,8 @@ class Admin::MembersController < OrbitMemberController
end
def edit
- param_temp = request.fullpath.split("?")
+ sort_role_attr_field
+ param_temp = request.fullpath.split("?")
@edit_params = (param_temp.count > 1 ? "?" + param_temp.last : "") rescue ""
if has_access?
@form_index = 0
@@ -532,7 +1048,7 @@ class Admin::MembersController < OrbitMemberController
respond_to do |format|
if @member.user.present?
@user = @member.user
- @user.update(user_params)
+ @user.update(user_params)
else
if user_params["user_name"] != ""
@user = User.new(user_params) rescue nil
@@ -542,8 +1058,18 @@ class Admin::MembersController < OrbitMemberController
@user = User.new(user_params) rescue nil
end
end
- if @member.update_attributes(member_profile_params)
- if params[:edit_type]!="edit_privilege" and (params[:member_profile].nil? or params[:member_profile][:role_status_ids].nil?)
+
+ # quick fix for preventing user delete their own role_status_ids
+ # NOTE: new_member_profile_params will overwrite member_profile_params
+ new_member_profile_params = member_profile_params
+ if request_from_regular_user?(current_user, @user)
+ new_member_profile_params[:role_status_ids] = @user.member_profile.role_status_ids
+ end
+
+ if @member.update_attributes(new_member_profile_params)
+ if params[:edit_type]!="edit_privilege" and (member_profile_params.nil? or member_profile_params[:role_status_ids].nil?)
+ # condition member_profile_params[:role_status_ids].nil? become useless when current_user is not admin,
+ # wait for git commit #e94ee506748 issue showing up again
@member.update_attributes(role_status_ids: [])
end
mpfv_params = member_profile_field_values_params
@@ -568,7 +1094,7 @@ class Admin::MembersController < OrbitMemberController
if params[:edit_type]=="edit_privilege"
@member.user.update_attributes(workgroup_id: params[:workgroup_id])
end
-
+
format.html { redirect_to admin_members_path() + @edit_params, notice: 'Successfully Updated the User' }
format.json { head :no_content }
@@ -700,12 +1226,18 @@ class Admin::MembersController < OrbitMemberController
end
def save_autobiography
- content = params[:content]
member = MemberProfile.find(params["member-id"]) rescue nil
+ now_locale = I18n.locale
if !member.nil?
- member.autobiography = content
- member.save
+ params[:content].each do |content_key,content_value|
+ locale = content_key.split('bio_text_')[1]
+ I18n.locale = locale
+ member.autobiography = content_value
+ member.save
+ puts ['key',content_key.inspect,'value',content_value.inspect]
+ end
end
+ I18n.locale = now_locale
render :json => {"success" => true}.to_json
end
@@ -802,6 +1334,12 @@ class Admin::MembersController < OrbitMemberController
params.require(:member_tag).permit!
end
+ def request_from_regular_user?(current_user, user_for_update)
+ (!current_user.is_admin? &&
+ !user_for_update.member_profile.role_status_ids.nil? &&
+ !user_for_update.member_profile.role_status_ids.empty? &&
+ params[:member_profile][:role_status_ids].nil?)
+ end
protected
@@ -811,7 +1349,7 @@ class Admin::MembersController < OrbitMemberController
else
@roles = current_user.member_profile.roles
end
- @infos = MemberProfileField.excludes(disabled: true)
+ @infos = MemberProfileField.excludes(disabled: true).sort_by{|v| v.key.to_i}
end
def set_attribute
diff --git a/updatefiles/members_controller.rb b/updatefiles/members_controller.rb
new file mode 100644
index 0000000..85ba707
--- /dev/null
+++ b/updatefiles/members_controller.rb
@@ -0,0 +1,464 @@
+class MembersController < ApplicationController
+ helper_method :current_user
+ def index
+ page_roles = OrbitHelper.page_categories
+ page_role_status = OrbitHelper.page_role_status
+ params = OrbitHelper.params
+ page = Page.where(:page_id => params[:page_id]).first rescue nil
+ fields_to_show = page.custom_array_field if !page.nil? rescue []
+ fields_to_show = [
+ {"key"=>"name", "type"=>"profile","sort_order"=>2,"link_to_show"=>true},
+ {"key"=>"email", "type"=>"profile"},
+ {"key"=>"office_tel", "type"=>"profile"}
+ ] if fields_to_show.blank?
+
+ member_sort_position = OrbitHelper.member_sort_position
+ sort = nil
+ if !member_sort_position
+ # sort = "data['list_order']"
+ # else
+ # sort = fields_to_show
+ # .collect.with_index{|field,idx| {'sort_order'=>field['sort_order'], 'index'=>idx}}
+ # .select{|field|!field['sort_order'].blank?}
+ # .sort_by{|field|field['sort_order']}
+ # .collect.with_index{|field| "data['profile_data'][#{field['index']}]['sort_value'] rescue 0"}
+ # # sort = "[(data['first_name'][0])]"
+
+ # sort = '[('+sort.join('),(')+')]'
+ fields_to_show.each_with_index do |field, idx|
+ if field["key"] == "name"
+ # sort = "[(data['profile_data'][idx]['sort_value'] rescue 0)]"
+ sort = idx
+ end
+ end
+ end
+ if page_roles.include?("all")
+ roles = Role.all.asc(:key).collect do |role|
+ { "title" => role.title, "id" => role.id }
+ end
+ else
+ page_role_status.each do |status_id|
+ page_roles << RoleStatus.find(status_id).role.id.to_s
+ end
+ roles = Role.where(:id.in => page_roles.uniq).asc(:key).collect do |role|
+ { "title" => role.title, "id" => role.id, "status" => RoleStatus.where(:role_id=>role, :_id.in=>page_role_status).asc(:key).to_a }
+ end
+ end
+ tag = nil
+ role_list = []
+ roles.each do |role|
+ status_list = []
+ if !role['status'].blank?
+ role['status'].each do |status|
+ member_profiles = get_members_by_status(status, sort, fields_to_show, member_sort_position, params)
+ status_list << { "status-title" => status.title, "members" => member_profiles } if !member_profiles.blank?
+ end
+ else
+ # Members with status
+ role_status = RoleStatus.order_by(:key=>"asc").where(:role_id=>role['id'])
+ role_status_ids = role_status.collect{|status| status.id.to_s}
+
+ role_status.each do |status|
+ member_profiles = get_members_by_status(status, sort, fields_to_show, member_sort_position, params)
+ next if member_profiles.blank?
+ status_list << { "status-title" => status.title, "members" => member_profiles }
+ end
+
+ # Members without status
+ member_profiles = []
+
+ if params[:tag].blank?
+ MemberProfile.not_in(:role_status_ids.in=>role_status_ids).where(:role_ids.in=>[role['id']]).collect do |profile|
+ if profile.user.nil?
+ member_profiles << get_member_data(profile, fields_to_show)
+ elsif profile.user.approved
+ member_profiles << get_member_data(profile, fields_to_show)
+ end
+ end
+ else
+ tag = MemberTag.find(params[:tag]) rescue nil
+ MemberProfile.not_in(:role_status_ids.in=>role_status_ids).where(:role_ids.in=>[role['id']], :member_tag_ids.in => [tag.id]).collect do |profile|
+ if profile.user.nil?
+ member_profiles << get_member_data(profile, fields_to_show)
+ elsif profile.user.approved
+ member_profiles << get_member_data(profile, fields_to_show)
+ end
+ end if !tag.nil?
+ end
+ if member_sort_position
+ member_profiles = member_profiles.sort_by{|data| (data['list_order'])} rescue member_profiles
+ else
+ member_profiles = member_profiles.sort_by{|data| (data['profile_data'][sort]['sort_value'] rescue 0)} rescue member_profiles
+ end
+ status_list << { "status-title" => role['title'], "members" => member_profiles } if !member_profiles.blank?
+ end
+ role_list << { "role-title" => role['title'], "status-list" => status_list }
+ end
+ {
+ "roles" => role_list,
+ "extras" => {
+ "widget-title"=>((params[:tag].blank? ? t(:member_) : (tag.nil? ? "Tag not found" : t(:member_) + " - Filtered by #{tag.title}")) rescue t(:member_))
+ }
+ }
+ end
+
+ def get_members_by_status(status, sort=nil, fields_to_show, member_sort_position, params)
+ member_profiles = []
+ mps = []
+ if params[:tag].blank?
+ mps = status.member_profiles.asc(:first_name)
+ else
+ tag = MemberTag.find(params[:tag]) rescue nil
+ mps = status.member_profiles.where(:member_tag_ids.in => [tag.id]).asc(:first_name) if !tag.nil?
+ end
+
+ mps.each do |member|
+ if member.user.nil?
+ member_profiles << get_member_data(member, fields_to_show)
+ elsif member.user.approved
+ member_profiles << get_member_data(member, fields_to_show)
+ end
+ end
+ if member_sort_position
+ return member_profiles.sort_by{|data| (data['list_order'])} rescue member_profiles
+ else
+ return member_profiles.sort_by{|data| (data['profile_data'][sort]['sort_value'] rescue 0)} rescue member_profiles
+ end
+ end
+
+ def get_member_data(member, fields_to_show)
+ image = member.avatar.present? ? member.avatar.thumb.url : ActionController::Base.helpers.asset_path('member-pic.png')
+ {
+ 'profile_data'=>member_data(member, fields_to_show),
+ 'list_order' => member.position,
+ 'name' => member.name,
+ 'image'=>image,
+ "link_to_show" => OrbitHelper.url_to_show(member.to_param)
+ }
+ end
+
+ def show
+ params = OrbitHelper.params
+ member = MemberProfile.find_by(uid: params[:uid])
+ page = Page.where(:page_id => params[:page_id]).first rescue nil
+
+ profile_data = []
+ fields_to_show = []
+
+ fields_to_show = page.custom_array_field_for_show rescue []
+
+ #role status
+ member.roles.where(:disabled => false).asc("_id").collect do |role|
+ role_status = member.role_statuses.where(role_id: role.id).map{|t|t.title.to_s}.join(',') rescue ''
+ profile_data = profile_data.push({"key"=>"role_status", "title"=>"", "value"=> role_status, "title_class"=>"member-data-title-role-status", "value_class"=>"member-data-value-role-status"}) if !role_status.blank?
+ if fields_to_show.blank?
+ attribute_field = role.attribute_fields.where(:key => 'job_title').first
+ profile_data = profile_data + member_data(member, [{"id"=> attribute_field.id.to_s, "key"=> attribute_field.key, "type"=>"role"}]) if !attribute_field.blank? and !attribute_field.to_show.blank?
+ end
+ end
+ if fields_to_show.blank?
+ fields_to_show = [
+ {"key"=>"name", "type"=>"profile"},
+ {"key"=>"office_tel", "type"=>"profile"},
+ {"key"=>"email", "type"=>"profile"}
+ ]
+
+ profile_data = profile_data + member_data(member, fields_to_show)
+
+ profile_fields_to_show = []
+
+ # member info
+ infos = MemberInfo.order('created_at DESC')
+ infos.each do |info|
+ info.member_profile_fields.each do |member_profile_field|
+ profile_fields_to_show << {"id"=> member_profile_field.id.to_s, "key"=> member_profile_field.key, "type"=>"custom"} if !member_profile_field.to_show.blank?
+ end
+ end
+ profile_data = profile_data + member_data(member, profile_fields_to_show)
+
+ # member role
+ role_fields_to_show = []
+ member.roles.where(:disabled => false).asc("_id").collect do |role|
+ role.attribute_fields.where(:key.ne => 'job_title').asc("_id").each do |attribute_field|
+ role_fields_to_show << {"id"=> attribute_field.id.to_s, "key"=> attribute_field.key, "type"=>"role"} if !attribute_field.to_show.blank?
+ end
+ end
+ profile_data = profile_data + member_data(member, role_fields_to_show)
+ else
+ profile_data = profile_data + member_data(member, fields_to_show)
+ auto = profile_data.select{|pd| pd if pd["key"] == "autobiography"}
+ if !auto.blank?
+ auto = auto.first
+ profile_data.delete(auto)
+ end
+ end
+
+ # member plugin
+ # plugins = (current_site.personal_plugins_sort.blank? ? OrbitApp::Plugin::Registration.all : OrbitApp::Plugin::Registration.sort_by_array(current_site.personal_plugins_sort)) rescue nil
+ if current_site.personal_plugins_sort.blank?
+ plugins = OrbitApp::Plugin::Registration.all rescue nil
+ else
+ plugin_list = OrbitApp::Plugin::Registration.all.collect{|p| p.module_app_name}
+ plugin_list = current_site.personal_plugins_sort | plugin_list
+ plugins = OrbitApp::Plugin::Registration.sort_by_array(plugin_list) rescue nil
+ end
+ plugin_list = plugins.collect.with_index do |plugin, idx|
+
+ intro = PersonalPluginIntro.find_by(member_profile_id: member.id, _type: "#{plugin.app_name}Intro") rescue nil
+
+ if intro.nil? or intro.complete_list
+
+ plugin_data = plugin.app_name.constantize.where(member_profile_id: member,:is_hidden=>false) rescue nil
+ # pd = plugin_data.collect do |p|
+ # slug_title = ["JournalPaper","WritingConference"].include?(plugin.app_name) ? p.create_link : p.slug_title
+ # {
+ # "data_title" => slug_title,
+ # "link_to_show" => OrbitHelper.url_to_plugin_show(p.to_param,plugin.module_app_name.underscore)
+ # }
+ # end
+ pd = []
+ has_plugin_method = plugin.app_name.constantize.respond_to?("get_plugin_datas_to_member") rescue false
+
+ if !has_plugin_method && (plugin.app_name == 'JournalPaper' or plugin.app_name == 'WritingConference' or plugin.app_name == 'Book')
+
+ pd_title = {}
+
+ temp_pds = plugin_data.sort_for_frontend rescue nil
+ temp_pds = plugin_data.where(:is_hidden=>false).desc(:year) if temp_pds.nil? # for old sites without plugins update
+
+ plugin_datas = temp_pds.collect do |p|
+ {
+ "pd_datas" => [{ "data_title" => "#{p.create_link}" }]
+ }
+ end
+
+ else
+
+ datas = plugin.app_name.constantize.get_plugin_datas_to_member(plugin_data)
+ pd_title = datas[0] rescue {}
+ plugin_datas = datas[1] rescue {}
+
+ end
+
+ end
+
+ if !intro.blank?
+
+ if !intro.brief_intro.blank?
+ pdi = []
+ pdi << {"data_intro_title" => intro.text.html_safe}
+ end
+
+ if intro.complete_list.blank?
+ complete_display = "hide"
+
+ pd_title = {}
+ plugin_datas = {}
+ end
+
+ if intro.brief_intro.blank?
+ brief_display = "hide"
+ pdi = {}
+ end
+ else
+
+ pdi = [{"data_intro_title" => ''}] if !plugin_datas.blank?
+
+ end
+
+
+ {
+ "plugin_data" => pd,
+ "pd_title" => pd_title,
+ "plugin_datas" => plugin_datas,
+ "plugin_data_intro" => pdi,
+ "complete_display" => complete_display,
+ "brief_display" => brief_display,
+ "plugin_name" => plugin.module_app_name.underscore,
+ "plugin_title" => t('module_name.'+plugin.module_app_name.underscore),
+ "plugin_class" => idx==0 ? "active" : ""
+ }
+
+ end
+ plugin_list = plugin_list.reject{|plugin| plugin['plugin_datas'].blank? and plugin['plugin_data_intro'].blank?}
+
+ vlog_module = ModuleApp.find_by_key("vlog") rescue nil
+
+ if !vlog_module.nil? && !member.user.nil?
+ plugin_data = VLog.where(create_user_id: member.user.id) rescue nil
+ if plugin_data.count > 0
+ datas = VLog.get_plugin_datas_to_member(plugin_data)
+ pd_title = datas[0] rescue {}
+ plugin_datas = datas[1] rescue {}
+
+ plugin_list << {
+ "plugin_data" => [],
+ "pd_title" => pd_title,
+ "plugin_datas" => plugin_datas,
+ "plugin_data_intro" => {},
+ "complete_display" => nil,
+ "brief_display" => nil,
+ "plugin_name" => vlog_module.get_registration.key,
+ "plugin_title" => t("vlog.vlog"),
+ "plugin_class" => ""
+ }
+ end
+ end
+
+ if !auto.blank?
+ if plugin_list.empty?
+ plugin_list << {"plugin_data"=>[], "pd_title"=>[{"plugin_data_title"=>auto["title"]}], "plugin_datas"=>[{"pd_datas"=>[{"data_title"=>auto["value"]}]}], "plugin_name" => auto["key"],"plugin_class" => "active", "plugin_title" => auto["title"], "plugin_data_intro"=>[{"data_intro_title"=>""}], "complete_display"=>nil, "brief_display"=>nil}
+ else
+ plugin_list.first["plugin_class"] = ""
+ plugin_list.unshift({"plugin_data"=>[], "pd_title"=>[{"plugin_data_title"=>auto["title"]}], "plugin_datas"=>[{"pd_datas"=>[{"data_title"=>auto["value"]}]}], "plugin_name" => auto["key"],"plugin_class" => "active", "plugin_title" => auto["title"], "plugin_data_intro"=>[{"data_intro_title"=>""}], "complete_display"=>nil, "brief_display"=>nil})
+ end
+ end
+
+ {
+ "plugins" => plugin_list,
+ "profile_data" => profile_data,
+ "data" => {
+ "image" => member.avatar.present? ? member.avatar.url : ActionController::Base.helpers.asset_path('member-pic.png'),
+ "name" => member.name
+ }
+ }
+ end
+
+ def member_data(member, fields_to_show)
+ profile_data = []
+ fields_to_show.each do |field|
+ privacy_approved_status = true
+ if field['type'] != 'role'
+ field_key = field["key"]
+ else
+ field_key = field["id"]
+ end
+ privacy_approved_status = false if member.get_privacy_type_for_field(field_key) != "public"
+ if !OrbitHelper.current_user.nil?
+ if(member.get_privacy_type_for_field(field_key) == "logged_in")
+ privacy_approved_status = true
+ elsif(member.get_privacy_type_for_field(field_key) == "locked")
+ if member.user.id == OrbitHelper.current_user.id || OrbitHelper.current_user.is_admin?
+ privacy_approved_status = true
+ end
+ end
+ end
+ if member.get_privacy_type_for_field(field_key) == "default"
+ if field['type'] != 'role'
+ privacy_approved_status = true #Todo: set not role field's default privacy_approved_status
+ else
+ case AttributeField.find(field["id"]).privacy_default
+ when 'public'
+ privacy_approved_status = true
+ when 'logged_in'
+ privacy_approved_status = true if !OrbitHelper.current_user.nil?
+ when 'locked'
+ if !OrbitHelper.current_user.nil?
+ privacy_approved_status = true if member.user.id == OrbitHelper.current_user.id || OrbitHelper.current_user.is_admin?
+ end
+ end
+ end
+ end
+ case field['type']
+ when 'profile'
+ next if !privacy_approved_status
+ field_data = member.get_attribute_data(field) rescue {}
+ when 'custom'
+ if !field['id'].blank?
+ next if !privacy_approved_status
+ field_data = member.member_profile_field_values.find_by(:member_profile_field_id=>field['id'],:key=>field['key']).get_field_value rescue {"value" => " "}
+ else
+ field_data = member.member_profile_field_values.find_by(:key=>field['key']).get_field_value rescue {"value" => " "}
+ end
+ when 'role'
+ if !field['id'].blank?
+ next if !privacy_approved_status
+ av = member.attribute_values.find_by(:attribute_field_id=>field['id'],:key=>field['key']) rescue nil
+ field_data = {"value" => " "}
+ if !av.nil?
+ r = av.attribute_field.role rescue nil
+ if !r.nil?
+ if member.roles.include?(r)
+ field_data = av.get_field_value rescue {"value" => " "}
+ else
+ field_data = {"value" => " "}
+ end
+ else
+ field_data = {"value" => " "}
+ end
+ else
+ field_data = {"value" => " "}
+ end
+ else
+ avs = member.attribute_values.where(:key=>field['key']) rescue nil
+ field_data = {"value" => " "}
+ avs.each do |av|
+ if !av.nil?
+ r = av.attribute_field.role rescue nil
+ if !r.nil?
+ if member.roles.include?(r)
+ field_data = av.get_field_value rescue {"value" => " "}
+ break
+ else
+ field_data = {"value" => " "}
+ end
+ else
+ field_data = {"value" => " "}
+ end
+ else
+ field_data = {"value" => " "}
+ end
+ end
+ end
+ end
+ next if field_data.blank? or field_data['value'].blank? or (OrbitHelper.params[:target_action] == "show" && field_data['value'] == " ")
+
+ if field['sort_order']
+ field_data['sort_value'] = field_data['val'].blank? ? field_data['value'] : field_data['val']
+ if !field_data['sort_value'].is_a?(Hash)
+ if field_data['sort_value'].is_a?(Integer) || (field_data['sort_value'].is_i? rescue false)
+ field_data['sort_value'] = field_data['sort_value'].to_i rescue field_data['sort_value']
+ else
+ if I18n.locale == :zh_tw
+ field_data['sort_value'] = field_data['sort_value'].strip.encode("Big5") rescue "簡".encode("Big5")
+ end
+ end
+ end
+ end
+ @current_field_value = field_data['value']
+ if (@current_field_value.gsub(' ','').strip rescue nil) == ""
+ @locale = I18n.locale
+ @site_in_use_locales = current_site.in_use_locales
+ @new_field_data = Hash.new
+ @site_in_use_locales.each_with_index do |locale,i|
+ I18n.locale = locale
+ @new_field_data = member.get_attribute_data(field) rescue {}
+ break if @new_field_data['value'].to_s.gsub(' ','').strip !=""
+ end
+ field_data['value'] = @new_field_data['value'].nil? ? " " :@new_field_data['value']
+ I18n.locale = @locale
+ end
+ if field['link_to_show']
+ if field_data['value'] == ' ' #需jquery刪除空白欄位
+ field_data['value'] = "" #若無網站連結,刪除實驗室網站字樣
+ field_data['title'] = "" #無網站連結,則不顯示
+ elsif field_data['value'].include? 'href='
+ field_data['value'] = ""
+ else
+ field_data['value'] = "#{field_data['value']}"
+ end
+ #field_data['value'] = "#{field_data['value']}"
+ end
+
+ if field['max_length']
+ field_data['value'] = (field_data['value'].length > field['max_length']) ? field_data['value'][0..field['max_length']]+'...' : field_data['value']
+ end
+
+ field_data['title_class'] = "member-data-title-"+field['key'].underscore.gsub('_','-')
+ field_data['value_class'] = "member-data-value-"+field['key'].underscore.gsub('_','-')
+ next if field_data['value'] == "" || field_data['value'] == ' '
+ profile_data.push(field_data)
+ end
+ return profile_data
+ end
+end