1739 lines
70 KiB
Ruby
1739 lines
70 KiB
Ruby
# encoding: utf-8
|
||
class ManagementsController < ApplicationController
|
||
before_filter :require_admin
|
||
layout 'base_management'
|
||
include ManagementsHelper
|
||
include SortHelper
|
||
include UsersHelper
|
||
include ApplicationHelper
|
||
|
||
#用户修改
|
||
def account
|
||
@user = User.find(params[:user_id])
|
||
ue = @user.user_extensions
|
||
# @trail_authentication = ApplyAction.where(:user_id => @user.id, :container_type => "TrialAuthorization").order("created_at desc").first
|
||
# @authentication = @user.authentication
|
||
# if @user.nickname.nil? || @user.lastname.nil? || ue.try(:identity).nil? || ue.try(:location).nil? || ue.try(:location).nil?
|
||
# @require_auth = true
|
||
# else
|
||
# if User.current.certification != 1 && (@trail_authentication.blank? || (@trail_authentication.status == 2 && (@trail_authentication.updated_at.to_i + 5*60) < Time.now.to_i))
|
||
# @require_trail_auth = true
|
||
# end
|
||
# end
|
||
# @s_message = AppliedMessage.where(:status => 3, :user_id => User.current.id, :viewed => 0, :applied_type => 'ApplyAddSchools').first
|
||
# @d_message = AppliedMessage.where(:status => 3, :user_id => User.current.id, :viewed => 0, :applied_type => 'ApplyAddDepartment').first
|
||
|
||
# AppliedMessage.where(:status => 3, :user_id => User.current.id, :viewed => 0, :applied_type => 'ApplyAddSchools').update_all(:viewed => true)
|
||
# AppliedMessage.where(:status => 3, :user_id => User.current.id, :viewed => 0, :applied_type => 'ApplyAddDepartment').update_all(:viewed => true)
|
||
|
||
lg = @user.login
|
||
@pref = @user.pref
|
||
diskfile = disk_filename('User', @user.id)
|
||
diskfile1 = diskfile + 'temp'
|
||
begin
|
||
if request.post?
|
||
@user.nickname = params[:nickname]
|
||
@user.lastname = params[:lastname]
|
||
@user.firstname = ""
|
||
@user.show_realname = params[:show_realname] ? 0 : 1
|
||
@user.pref.attributes = params[:pref]
|
||
@user.mail = params[:mail]
|
||
@user.phone = params[:phone]
|
||
@user.password = params[:new_password]
|
||
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
||
@se = @user.extensions
|
||
@se.school_id = params[:occupation]
|
||
@se.department_id = params[:department_id]
|
||
@se.gender = params[:sex]
|
||
@se.location = params[:province] if params[:province]
|
||
@se.location_city = params[:city] if params[:city]
|
||
@se.identity = params[:identity].to_i if params[:identity]
|
||
if @se.identity == 0
|
||
@se.technical_title = params[:te_technical_title] if params[:te_technical_title]
|
||
@se.student_id = nil
|
||
elsif @se.identity == 1
|
||
@se.student_id = params[:no] if params[:no]
|
||
@se.technical_title = nil
|
||
elsif @se.identity == 2
|
||
@se.technical_title = params[:pro_technical_title] if params[:pro_technical_title]
|
||
@se.student_id = nil
|
||
end
|
||
@se.brief_introduction = params[:brief_introduction]
|
||
|
||
if @user.save && @se.save
|
||
reward_grade(@user, @user.id, 'Account', 500)
|
||
# 头像保存
|
||
FileUtils.mv diskfile1, diskfile, force: true if File.exist? diskfile1
|
||
@user.pref.save
|
||
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
|
||
set_language_if_valid @user.language
|
||
flash[:notice] = l(:notice_account_updated)
|
||
return
|
||
else
|
||
@user.login = lg
|
||
end
|
||
|
||
end
|
||
# 不管前面是否有异常,如果文件已存在就删除
|
||
ensure
|
||
File.delete(diskfile1) if File.exist?(diskfile1)
|
||
end
|
||
@setting_type = 1
|
||
end
|
||
|
||
# 镜像管理
|
||
def mirror_repository
|
||
@menu_type = 3
|
||
@sub_type = 4
|
||
@mirror_types = MirrorType.where("0=0")
|
||
mirror_rep = Redmine::Configuration['mirror_rep']
|
||
uri = "#{mirror_rep}/images/json"
|
||
uri = URI.parse(URI.encode(uri.strip))
|
||
begin
|
||
res = Net::HTTP.get(uri)
|
||
res = JSON.parse(res)
|
||
res.each do |mirror|
|
||
mirrorID = mirror['Id'][7, 12]
|
||
if MirrorRepository.where(:mirrorID => mirrorID).count == 0
|
||
MirrorRepository.create(:mirrorID => mirrorID, :status => 0, :created_at => Time.at(mirror['Created']), :updated_at => Time.at(mirror['Created']))
|
||
end
|
||
end
|
||
rescue
|
||
end
|
||
@mirrors = MirrorRepository.where("0=0").reorder("updated_at desc")
|
||
end
|
||
|
||
def add_mirror_type
|
||
data = {result: 0}
|
||
if params[:name]
|
||
if MirrorType.where(:name => params[:name]).count == 0
|
||
new_type = MirrorType.new(:user_id => User.current.id, :name => params[:name])
|
||
if new_type.save
|
||
data[:result] = 1
|
||
end
|
||
else
|
||
data[:result] = 2
|
||
end
|
||
end
|
||
render :json => data
|
||
end
|
||
|
||
def modify_mirror
|
||
@mirror = MirrorRepository.find params[:mirror_id]
|
||
@mirror_types = MirrorType.where("0=0")
|
||
end
|
||
|
||
def search_mirror_type
|
||
data = {mirror_types: []}
|
||
search = params[:search]
|
||
MirrorType.where("name like '%#{search}%'").each do |mirror_type|
|
||
option = []
|
||
option << mirror_type.name.to_s
|
||
option << mirror_type.id
|
||
data[:mirror_types] << option
|
||
end
|
||
render :json => data
|
||
end
|
||
|
||
def update_mirror
|
||
data = {result: 0, ID:""}
|
||
begin
|
||
mirror = MirrorRepository.find params[:mirror_id]
|
||
if mirror
|
||
last_index = params[:main_type].strip().rindex(";");
|
||
params[:main_type] = last_index.nil? ? "" : params[:main_type].strip()[0 ... last_index]
|
||
if params[:main_type] != ""
|
||
# 判断镜像主类别和小类别是否重复
|
||
if MirrorRepository.where("id != #{mirror.id} and main_type = '#{params[:main_type]}' and tag = '#{params[:tag].strip()}'").count > 0
|
||
data[:result] = 1
|
||
data[:ID] = MirrorRepository.where("id != #{mirror.id} and main_type = #{params[:main_type]} and tag = #{params[:tag].strip()}").first.mirrorID
|
||
else
|
||
main_types = params[:main_type].split(";")
|
||
main_name = main_types.join('-')
|
||
data_tag = params[:tag].strip().gsub(/;/, '-')
|
||
# 更改tag
|
||
mirror_rep = Redmine::Configuration['mirror_rep']
|
||
uri = "#{mirror_rep}/images/"+mirror.mirrorID.to_s+"/tag"
|
||
params = {repo: "#{main_name}", tag: "#{data_tag}"}
|
||
uri = URI.parse(URI.encode(uri.strip))
|
||
res = Net::HTTP.post_form(uri, params).body
|
||
if res == ""
|
||
# 删除原tag
|
||
del_mirror_name = mirror.main_name.to_s + ":" + mirror.tag.gsub(/;/, '-').to_s
|
||
del_uri = "#{mirror_rep}/images/" + del_mirror_name
|
||
del_res = delete_mirror_http del_uri
|
||
if del_res.code == '200'
|
||
# 同步更新数据库的记录
|
||
transaction do
|
||
mirror.mirror_repository_types.destroy_all
|
||
main_types.each do |type|
|
||
mirror_tp = MirrorType.where(:name => type).first
|
||
if mirror_tp
|
||
MirrorRepositoryType.create(:mirror_type_id => mirror_tp.id, :mirror_repository_id => mirror.id)
|
||
end
|
||
end
|
||
MirrorUpdateRecord.create(:user_id => User.current.id, :mirror_repository_id => mirror.id, :newDescription => params[:description], :oldDescription => mirror.description,
|
||
:newName => main_name, :oldName => mirror.name, :newStatus => params[:status], :oldStatus => mirror.status, :newTag => params[:tag], :oldTag => mirror.tag, :newType => params[:main_type], :oldType => mirror.main_type)
|
||
mirror.update_attributes(:name => main_name, :main_type => params[:main_type], :tag => params[:tag], :description => params[:description], :status => params[:status])
|
||
end
|
||
else
|
||
# 删除失败则删除新加的tag
|
||
del_mirror_name = main_name.to_s + ":" + data_tag
|
||
del_uri = "#{mirror_rep}/images/" + del_mirror_name
|
||
del_res = delete_mirror_http del_uri
|
||
data[:result] = 4
|
||
end
|
||
else
|
||
logger.error(res['message'])
|
||
data[:result] = 4
|
||
end
|
||
end
|
||
else
|
||
data[:result] = 2
|
||
end
|
||
else
|
||
data[:result] = 3
|
||
end
|
||
rescue Exception => e
|
||
puts e
|
||
end
|
||
render :json => data
|
||
end
|
||
|
||
def delete_mirror
|
||
mirror = MirrorRepository.find params[:mirror_id]
|
||
mirror_rep = Redmine::Configuration['mirror_rep']
|
||
uri = "#{mirror_rep}/images/" + mirror.mirrorID.to_s
|
||
uri = URI.parse(URI.encode(uri.strip))
|
||
data = {name:mirror.mirrorID.to_s}
|
||
http = Net::HTTP.new uri.host, uri.port
|
||
begin
|
||
req = Net::HTTP::Delete.new(uri.request_uri)
|
||
req.form_data = data
|
||
res= http.start { |http| http.request req }
|
||
if res.code == '200'
|
||
@status = 1
|
||
mirror.destroy
|
||
else
|
||
@status = 0
|
||
end
|
||
rescue =>err
|
||
end
|
||
end
|
||
|
||
# 用户修改界面
|
||
def update_user
|
||
@menu_type = 7
|
||
@sub_type = 1
|
||
# @next_type = 1
|
||
if params[:flag]
|
||
applied_message = AppliedMessage.where(:id => params[:applied_message_id]).first
|
||
applied_message.update_attribute(:viewed, true)
|
||
end
|
||
@user = User.find(params[:user])
|
||
# 创建实训
|
||
@create_num = (@user == User.current ? Shixun.where(:user_id => @user).count : Shixun.where(:user_id => @user).visible.count)
|
||
# 创建课堂
|
||
@create_courses_count = @user.courses.not_deleted_not_end.select{ |course| @user.has_teacher_role(course)}.count
|
||
# 我的所有课程数
|
||
@all_courses_count = @user.courses.not_deleted_not_end.count
|
||
# 参与课堂
|
||
@join_courses_count = @all_courses_count - @create_courses_count
|
||
# 我合作的实训数
|
||
coop_id = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id} and role = 2").map(&:shixun_id) # 合作者的实训id
|
||
@cooperative_num = Shixun.where(:id => coop_id).count
|
||
# 我挑战的实训数
|
||
ch_id = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})")
|
||
@challenge_num = Shixun.where(:id => ch_id).count
|
||
#参与实训
|
||
@join_shixuns = @cooperative_num + @challenge_num
|
||
# 我的关注
|
||
watch_query = User.watched_by(@user.id)
|
||
@user_watchlist_count = watch_query.count()
|
||
# 我的粉丝
|
||
fan_query = @user.watcher_users
|
||
@user_fanlist_count = fan_query.count()
|
||
end
|
||
|
||
#用户信息修改
|
||
def update_user_message
|
||
|
||
end
|
||
|
||
# 实训留言
|
||
def shixun_feedback
|
||
@menu_type = 9
|
||
@sub_type = 1
|
||
@discusses = Discuss.where(:dis_type => "Shixun").reorder("created_at desc")
|
||
@discusses_count = @discusses.count
|
||
@limit = 20
|
||
@is_remote = true
|
||
@page = (params['page'] || 1).to_i
|
||
@discusses_pages = Paginator.new @discusses_count, @limit, @page
|
||
@offset ||= @discusses_pages.offset
|
||
@discusses = paginateHelper @discusses, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 实训反馈
|
||
def shixun_feedback_message
|
||
@menu_type = 8
|
||
@sub_type = 2
|
||
@discusses = Discuss.where(:dis_type => "Shixun").reorder("created_at desc")
|
||
@discusses_count = @discusses.count
|
||
@limit = 20
|
||
@is_remote = true
|
||
@page = (params['page'] || 1).to_i
|
||
@discusses_pages = Paginator.new @discusses_count, @limit, @page
|
||
@offset ||= @discusses_pages.offset
|
||
@discusses = paginateHelper @discusses, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 作业回复
|
||
def leave_message
|
||
@menu_type = 8
|
||
@sub_type = 1
|
||
@jour = JournalsForMessage.where(:jour_type => 'HomeworkCommon').order("created_on desc")
|
||
@jour_count = @jour.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@jour_pages = Paginator.new @jour_count, limit, params['page'] || 1
|
||
@offset ||= @jour_pages.offset
|
||
@jour = paginateHelper @jour, limit
|
||
respond_to do |format|
|
||
format.html
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 课堂讨论区
|
||
def messages_list
|
||
@menu_type = 8
|
||
@sub_type = 3
|
||
@memo = Memo.where("0=0").order("created_at desc")
|
||
@memo_count = @memo.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@memo_pages = Paginator.new @memo_count, limit, params['page'] || 1
|
||
@offset ||= @memo_pages.offset
|
||
@memo = paginateHelper @memo, limit
|
||
respond_to do |format|
|
||
format.html
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 专业列表
|
||
def profession
|
||
@major=Major.where("0=0")
|
||
# @menu_type = 12
|
||
@sub_type = 1
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
major_level_option = params[:major_level] if params[:major_level]
|
||
discipline_category_option = params[:discipline_category_id] if params[:discipline_category_id]
|
||
first_level_discipline_option = params[:first_level_discipline_id] if params[:first_level_discipline_id]
|
||
if major_level_option && major_level_option != '0'
|
||
@major = @major.where(:major_level => major_level_option)
|
||
end
|
||
if discipline_category_option && discipline_category_option != '0'
|
||
@major=@major.where(:discipline_category_id => discipline_category_option)
|
||
end
|
||
if first_level_discipline_option && first_level_discipline_option != '0'
|
||
@major=@major.where(:first_level_discipline_id => first_level_discipline_option)
|
||
end
|
||
|
||
if params[:support_shixuns]
|
||
@major = @major.where(:support_shixuns => params[:support_shixuns].to_i,:major_level=> 2)
|
||
end
|
||
|
||
@major = @major.order("created_at #{@sx_order}")
|
||
@major_count = @major.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@major_pages = Paginator.new @major_count, limit, params['page'] || 1
|
||
@offset ||= @major_pages.offset
|
||
@major = paginateHelper @major, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 新增专业页面
|
||
def new_major
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 新增专业
|
||
def insert_major
|
||
major_list = Major.create(:name=>params[:major],:first_level_discipline_id=>params[:first_level_discipline_id],:major_level=>params[:major_level],:discipline_category_id=>params[:discipline_category_id],:major_code=>params[:major_code])
|
||
redirect_to profession_managements_path
|
||
end
|
||
|
||
# 支撑实训
|
||
def support_shixun
|
||
if params[:syllabus_id]
|
||
major = Major.find params[:syllabus_id]
|
||
major.update_attributes(:support_shixuns => !major.support_shixuns)
|
||
end
|
||
end
|
||
|
||
# 实训适用课程
|
||
def applicable_course
|
||
# @menu_type = 12
|
||
@sub_type = 2
|
||
@major = Major.where(:major_level => 2,:support_shixuns => 1)
|
||
@courselist = CourseList.where("0=0")
|
||
search=params[:search]
|
||
unless search.blank?
|
||
@courselist = @courselist.where("name like '%#{search}%'")
|
||
end
|
||
@courselist = @courselist.reorder("created_at desc")
|
||
@courselist_count = @courselist.count
|
||
|
||
@limit = 15
|
||
@is_remote = true
|
||
@page = params['page'] ? params['page'].to_i : 1
|
||
@courselist_pages = Paginator.new @courselist_count, @limit, @page
|
||
@offset ||=@courselist_pages.offset
|
||
@courselist = paginateHelper @courselist, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 增加课程
|
||
def add_course
|
||
courselist= CourseList.create(:name => params[:course])
|
||
redirect_to applicable_course_managements_path
|
||
end
|
||
|
||
# 增加课程所属专业
|
||
def add_major
|
||
data = {result: 0}
|
||
id = MajorCourse.where(:course_list_id => params[:course_list_id]).first
|
||
if (id.nil?) || (params[:major_id].to_i != '0' && params[:major_id].to_i != id.major_id)
|
||
MajorCourse.create(:course_list_id => params[:course_list_id],:major_id=>params[:major_id])
|
||
data[:result] = 1
|
||
end
|
||
render :json => data
|
||
end
|
||
|
||
# 单位部门列表
|
||
def departments
|
||
@menu_type = 6
|
||
@sub_type = 2
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
@department = Department.where(:is_auth => 1)
|
||
search=params[:search]
|
||
if search.blank?
|
||
@department = @department
|
||
else
|
||
apply = School.where("name like '%#{search}%'").map(&:id)
|
||
@department = @department.where(:school_id => apply)
|
||
end
|
||
@department = @department.reorder("created_at #{@sx_order}")
|
||
@department_count =@department.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@department_pages = Paginator.new @department_count, limit, params['page'] || 1
|
||
@offset ||=@department_pages.offset
|
||
@department = paginateHelper @department, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 新增
|
||
def create_departments
|
||
dep = Department.order("created_at desc").first
|
||
@latest_school = School.find(dep.try(:school_id)).try(:name)
|
||
@school_id = dep.try(:school_id)
|
||
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def add_department
|
||
department = Department.where(:school_id => params[:school], :name => params[:department]).first
|
||
if department.nil?
|
||
department = Department.create(:school_id => params[:school],:name => params[:department])
|
||
ApplyAddDepartment.create(:school_id => params[:school],
|
||
:status => 1,
|
||
:name => params[:department],
|
||
:department_id => department.id,
|
||
:user_id => User.current.id);
|
||
end
|
||
redirect_to departments_managements_path
|
||
end
|
||
|
||
# 修改单位部门列表
|
||
def update_department
|
||
dep = Department.find params[:department_id]
|
||
apply_schools = ApplyAddDepartment.where(:status => 1, :school_id => dep.school_id)
|
||
apply_school_ids = apply_schools.empty? ? "(-1)" : "(" + apply_schools.map{|sc| sc.department_id}.join(',') + ")"
|
||
@edit_id = params[:department_id]
|
||
@search = params[:search]
|
||
if !params[:search].nil?
|
||
search = "%#{params[:search].to_s.strip.downcase}%"
|
||
@departments = Department.where("id in #{apply_school_ids} and #{Department.table_name}.name like :p", :p => search)
|
||
#@schools = School.all
|
||
else
|
||
@departments = Department.where("id in #{apply_school_ids}")
|
||
end
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def edit_departments_school
|
||
begin
|
||
dep = Department.find(params[:department_id])
|
||
alter_dep = Department.find(params[:alter_dep_id])
|
||
apply_dep = ApplyAddDepartment.where(:department_id => params[:alter_dep_id])
|
||
if dep && alter_dep && dep != alter_dep
|
||
# users = UserExtensions.where("department_id = #{dep.id}")
|
||
# users.update_all(:department_id => params[:alter_dep_id])
|
||
# dep.destroy
|
||
# apply_dep.update_all(:status => 2)
|
||
# ApplyAddDepartment.where(:department_id =>params[:departments]).update_all(:department_id=>department_id)
|
||
# users = UserExtensions.where("department_id = #{alt_dep.department_id}")
|
||
# users.update_all(:department_id => department.id)
|
||
apply_dep.destroy_all;
|
||
users = UserExtensions.where(:department_id => params[:alter_dep_id])
|
||
users.update_all(:department_id => dep.id)
|
||
alter_dep.destroy
|
||
end
|
||
rescue Exception => e
|
||
puts e
|
||
end
|
||
redirect_to departments_managements_path
|
||
end
|
||
|
||
# 单位列表
|
||
def departments_part
|
||
@menu_type = 6
|
||
@sub_type = 1
|
||
@schools = School.where("0=0")
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
search=params[:search]
|
||
if search.blank?
|
||
@schools = @schools
|
||
else
|
||
@schools = @schools.where("name like '%#{search}%'")
|
||
end
|
||
@schools = @schools.reorder("created_at #{@sx_order}")
|
||
@schools_count = @schools.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@schools_pages = Paginator.new @schools_count, limit, params['page'] || 1
|
||
@offset ||= @schools_pages.offset
|
||
@schools= paginateHelper @schools, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
|
||
# 新增部门名称
|
||
def add_departments_part
|
||
|
||
end
|
||
|
||
# 修改单位名称
|
||
def upload_logo
|
||
@menu_type = 6
|
||
@sub_type = 1
|
||
@next_type = 1
|
||
@school = School.find(params[:school])
|
||
end
|
||
|
||
# 修改单位名称为其他
|
||
def school_upload_logo
|
||
school = School.where(:id => params[:applied_id]).first
|
||
ApplyAddSchools.where(:school_id => params[:applied_id]).destroy_all
|
||
before_apply_departments = Department.where(:school_id => params[:applied_id])
|
||
after_apply_deparments = Department.where(:school_id => params[:school_id])
|
||
before_apply_departments.each do |department|
|
||
after_dep = Department.where(:school_id => params[:school_id], :name => department.name).first
|
||
if after_dep
|
||
UserExtensions.where(:school_id => params[:applied_id], :department_id => department.id).update_all(:department_id => after_dep.id)
|
||
else
|
||
new_department = Department.create(:name => department.name,:school_id =>params[:school_id], :is_auth => 1)
|
||
UserExtensions.where(:school_id => params[:applied_id]).update_all(:department_id => new_department.id)
|
||
end
|
||
ApplyAddDepartment.where(:department_id => department.id).destroy_all
|
||
department.destroy
|
||
end
|
||
UserExtensions.where(:school_id => params[:applied_id]).update_all(:school_id => params[:school_id])
|
||
school.destroy
|
||
redirect_to departments_part_managements_path
|
||
end
|
||
|
||
# 修改单位信息
|
||
def school_message_update
|
||
school = School.where(:name =>params[:schoolname]).first
|
||
school_id = school.id
|
||
School.where(:id => school_id).update_all(:province => params[:province],:city =>params[:city],:address => params[:address],:shool_code => params[:school_code])
|
||
redirect_to departments_part_managements_path
|
||
end
|
||
|
||
# 删除单位
|
||
def delete_school
|
||
school = School.where(:id => params[:school]).first
|
||
UserExtensions.where(:school_id => params[:school]).update_all(:school_id => nil, :department_id => nil)
|
||
ApplyAddSchools.where(:school_id => params[:school]).destroy_all
|
||
ApplyAddDepartment.where(:school_id => params[:school]).destroy_all
|
||
school.destroy
|
||
redirect_to departments_part_managements_path
|
||
end
|
||
|
||
def save_school
|
||
uploaded_io = params[:logo]
|
||
sl = School.create(:name => params[:schoolname],:province => params[:province],:city => params[:city],:address => params[:address])
|
||
unless uploaded_io.nil?
|
||
File.open(Rails.root.join('public', 'images', 'school', sl.id.to_s+'.png'), 'wb') do |file|
|
||
file.write(uploaded_io.read)
|
||
end
|
||
sl.logo_link = '/images/school/'+sl.id.to_s+'.png'
|
||
sl.save
|
||
end
|
||
|
||
@user = User.current
|
||
@se = @user.extensions
|
||
|
||
# if @user.save && @se.save
|
||
# diskfile1 = disk_filename('school', sl.id , 'id')
|
||
# diskfileID = diskfile1 + 'temp'
|
||
# begin
|
||
# FileUtils.mv diskfileID, diskfile1, force: true if File.exist? diskfileID
|
||
# ensure
|
||
# File.delete(diskfileID) if File.exist?(diskfileID)
|
||
# end
|
||
# end
|
||
redirect_to departments_part_managements_path
|
||
end
|
||
|
||
# 部门审核
|
||
def depart
|
||
@menu_type = 10
|
||
@sub_type = 3
|
||
search = params[:search]
|
||
@apply_status = ApplyAddDepartment.where(:status=>0)
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
if search.blank?
|
||
@apply_status = @apply_status.where("0=0")
|
||
else
|
||
@apply_status= @apply_status.where("name like '%#{search}%'")
|
||
end
|
||
@apply_status = @apply_status.order("created_at #{@sx_order}")
|
||
@apply_status_count = @apply_status.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@apply_status_pages = Paginator.new @apply_status_count, limit, params['page'] || 1
|
||
@offset ||=@apply_status_pages.offset
|
||
@apply_status = paginateHelper @apply_status, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 批准
|
||
def approve_applied_departments
|
||
applied_department = ApplyAddDepartment.find(params[:id])
|
||
applied_message = AppliedMessage.where(:applied_id => applied_department.id, :applied_type => "ApplyAddDepartment")
|
||
applied_message.update_all(:status => 1)
|
||
if applied_department.department
|
||
applied_department.department.update_attributes(:is_auth => 1)
|
||
end
|
||
applied_department.update_attribute(:status, 1) unless applied_department.nil?
|
||
AppliedMessage.create(:user_id => applied_department.user_id, :status => 1, :viewed => 0, :applied_id => applied_department.id, :applied_type => "ApplyAddDepartment", :name => applied_department.name )
|
||
UserExtensions.where(:user_id => applied_department.user_id).update_all(:department_id => applied_department.department_id)
|
||
respond_to do |format|
|
||
format.html{ redirect_to depart_managements_path }
|
||
end
|
||
end
|
||
|
||
# 删除
|
||
def delete_applied_departments
|
||
applied_department = ApplyAddDepartment.find params[:id]
|
||
applied_message = AppliedMessage.where(:applied_id => applied_department.id, :applied_type => "ApplyAddDepartment")
|
||
applied_message.update_all(:status => 3)
|
||
applied_department.update_attribute(:status, 3)
|
||
# 未审批删除
|
||
if params[:tip] == "unapplied"
|
||
AppliedMessage.create(:user_id => applied_department.user_id, :status => 3, :viewed => 0, :applied_id => applied_department.id, :applied_type => "ApplyAddDepartment", :name => applied_department.name )
|
||
# 删除学校的用户
|
||
users = UserExtensions.where("department_id = #{applied_department.department_id}")
|
||
users.update_all(:department_id => nil)
|
||
applied_department.department.destroy
|
||
redirect_to depart_managements_path
|
||
# 已审批删除
|
||
elsif params[:tip] == "applied"
|
||
applied_department.destroy
|
||
redirect_to depart_managements_path
|
||
end
|
||
end
|
||
|
||
# 部门修改
|
||
def all_department
|
||
@edit_id = params[:department_id]
|
||
@search = params[:search]
|
||
dep = ApplyAddDepartment.where(:id => @edit_id).first
|
||
apply_department = ApplyAddDepartment.where(:status => 1, :school_id => dep.school_id)
|
||
apply_department_ids = apply_department.empty? ? "(-1)" : "(" + apply_department.map{|sc| sc.department_id}.join(',') + ")"
|
||
if !params[:search].nil?
|
||
search = "%#{params[:search].to_s.strip.downcase}%"
|
||
@department = Department.where("id in #{apply_department_ids} and #{Department.table_name}.name like :p", :p => search)
|
||
#@schools = School.all
|
||
else
|
||
#@course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)}
|
||
@department = Department.where("id in #{apply_department_ids}")
|
||
end
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
# redirect_to unit_managements_path
|
||
end
|
||
|
||
# 修改
|
||
def edit_applied_department
|
||
aas =ApplyAddDepartment.find(params[:applied_id])
|
||
# aas.update_attribute(:name, params[:name])
|
||
#applied_add_school = ApplyAddSchools.where(:name => aas.name)
|
||
department =Department.find params[:department_id]
|
||
begin
|
||
#更新消息表的status
|
||
if aas.department_id != department.id.to_i
|
||
applied_message_id = aas.department_id
|
||
applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddDepartment")
|
||
applied_message.update_all(:status => 4)
|
||
aas.update_attribute(:status, 2)
|
||
AppliedMessage.create(:user_id => aas.user_id, :status => 2, :viewed => 0, :applied_id => aas.id, :applied_type => "ApplyAddDepartment", :name =>department.name )
|
||
users = UserExtensions.where("department_id = #{aas.department_id}")
|
||
users.update_all(:department_id => department.id)
|
||
aas.department.destroy
|
||
ApplyAddDepartment.where(:department_id => aas.department_id).update_all(:department_id => department.id)
|
||
Department.where(:department_id => aas.department_id).destroy_all
|
||
aas.destroy_all
|
||
end
|
||
rescue Exception => e
|
||
puts e
|
||
end
|
||
redirect_to depart_managements_path
|
||
end
|
||
|
||
# 单位审批
|
||
def unit
|
||
@menu_type = 10
|
||
@sub_type = 4
|
||
search = params[:search]
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
@apply_status = ApplyAddSchools.where(:status=>0)
|
||
if search.blank?
|
||
@apply_status = @apply_status.where("0=0")
|
||
else
|
||
@apply_status= @apply_status.where("name like '%#{search}%'")
|
||
end
|
||
@apply_status = @apply_status.order("created_at #{@sx_order}")
|
||
@apply_status_count = @apply_status.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@apply_status_pages = Paginator.new @apply_status_count, limit, params['page'] || 1
|
||
@offset ||= @apply_status_pages.offset
|
||
@apply_status = paginateHelper @apply_status, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 单位审批批准
|
||
def approve_applied_schools
|
||
applied_school = ApplyAddSchools.where(:id =>params[:id]).first
|
||
applied_message_id = applied_school.school_id
|
||
applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools")
|
||
applied_message.update_all(:status => 1)
|
||
unless applied_school.nil?
|
||
applied_school.update_column('status', 1)
|
||
end
|
||
school = applied_school.school
|
||
school.update_attribute("province", applied_school.province)
|
||
AppliedMessage.create(:user_id => applied_school.user_id, :status => 1, :viewed => 0, :applied_id => applied_school.id, :applied_type => "ApplyAddSchools", :name => applied_school.name )
|
||
redirect_to unit_managements_path
|
||
end
|
||
|
||
# 删除
|
||
def delete_applied_schools
|
||
applied_school = ApplyAddSchools.find(params[:id])
|
||
applied_message_id = applied_school.school_id
|
||
applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools")
|
||
applied_message.update_all(:status => 3)
|
||
applied_school.update_attribute(:status, 3)
|
||
# 单位对应的部门审核也应做删除处理
|
||
applied_departments = ApplyAddDepartment.where(:school_id => applied_school.school_id)
|
||
applied_departments.update_all(:status => 3)
|
||
AppliedMessage.where(:applied_id => applied_departments.map(&:id), :applied_type => "ApplyAddDepartment").update_all(:status => 3)
|
||
# 未审批删除
|
||
if params[:tip] == "unapplied"
|
||
AppliedMessage.create(:user_id => applied_school.user_id, :status => 3, :viewed => 0, :applied_id => applied_school.id, :applied_type => "ApplyAddSchools", :name => applied_school.name )
|
||
if applied_departments.first
|
||
AppliedMessage.create(:user_id => applied_departments.first.user_id, :status => 3, :viewed => 0, :applied_id => applied_departments.first.id, :applied_type => "ApplyAddDepartment", :name => applied_departments.first.name )
|
||
end
|
||
# 删除学校的用户
|
||
users = UserExtensions.where("school_id = #{applied_school.school_id}")
|
||
users.update_all(:school_id => nil, :department_id => nil)
|
||
applied_school.school.destroy
|
||
applied_school.school.departments.destroy_all
|
||
redirect_to unit_managements_path
|
||
# 已审批删除
|
||
elsif params[:tip] == "applied"
|
||
applied_school.destroy
|
||
redirect_to unit_managements_path
|
||
end
|
||
end
|
||
|
||
# 单位审批修改
|
||
def all_schools
|
||
apply_schools = ApplyAddSchools.where("status = 0")
|
||
apply_school_ids = apply_schools.empty? ? "(#{params[:school_id].to_i})" : "(" + apply_schools.map{|sc| sc.school_id}.join(',') + ")"
|
||
if !params[:search].nil?
|
||
search = "%#{params[:search].to_s.strip.downcase}%"
|
||
@schools = School.where("id not in #{apply_school_ids} and id != #{params[:school_id].to_i} and #{School.table_name}.name like :p", :p => search)
|
||
else
|
||
@schools = School.where("id not in #{apply_school_ids} and id != #{params[:school_id].to_i}")
|
||
end
|
||
@edit_id = params[:school_id]
|
||
@search = params[:search]
|
||
@upload = params[:upload]
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 修改
|
||
def edit_applied_schools
|
||
aas = ApplyAddSchools.find(params[:applied_id])
|
||
school = School.find params[:school_id]
|
||
begin
|
||
#更新消息表的status
|
||
if aas.school_id != school.id.to_i
|
||
applied_message_id = aas.school_id
|
||
applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools")
|
||
applied_message.update_all(:status => 4)
|
||
aas.update_attribute(:status, 2)
|
||
AppliedMessage.create(:user_id => aas.user_id, :status => 2, :viewed => 0, :applied_id => aas.id, :applied_type => "ApplyAddSchools", :name => school.name )
|
||
users = UserExtensions.where("school_id = #{aas.school_id}")
|
||
users.update_all(:school_id => school.id)
|
||
ApplyAddDepartment.where(:school_id => aas.school_id).update_all(:school_id => school.id)
|
||
# 判断重复
|
||
before_apply_departments = Department.where(:school_id => params[:applied_id])
|
||
after_apply_deparments = Department.where(:school_id => params[:school_id])
|
||
before_apply_departments.each do |department|
|
||
after_dep = Department.where(:school_id => params[:school_id], :name => department.name).first
|
||
if after_dep
|
||
UserExtensions.where(:school_id => params[:applied_id], :department_id => department.id).update_all(:department_id => after_dep.id)
|
||
else
|
||
UserExtensions.where(:school_id => params[:applied_id]).update_all(:department_id => new_department.id)
|
||
if after_dep.status == 2 ||after_dep.status == 3
|
||
new_department = Department.create(:name => department.name,:school_id =>params[:school_id], :is_auth => 1)
|
||
else
|
||
new_department = Department.create(:name => department.name,:school_id =>params[:school_id], :is_auth => 0)
|
||
end
|
||
end
|
||
ApplyAddDepartment.where(:department_id => department.id).destroy_all
|
||
department.destroy
|
||
end
|
||
UserExtensions.where(:school_id => params[:applied_id]).update_all(:school_id => params[:school_id])
|
||
|
||
# Department.where(:school_id => aas.school_id).update_all(:school_id => school.id)
|
||
aas.school.destroy
|
||
aas.update_attribute(:school_id, school.id)
|
||
end
|
||
rescue Exception => e
|
||
puts e
|
||
end
|
||
redirect_to unit_managements_path
|
||
end
|
||
|
||
# 课堂列表
|
||
def classroom
|
||
@menu_type = 2
|
||
@sub_type = 1
|
||
@courselist = CourseList.where("0=0")
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
keyword = params[:keyword]
|
||
search = params[:search]
|
||
|
||
if params[:support_shixuns_search_title]
|
||
@courselist = @courselist.where(:support_shixuns_search => params[:support_shixuns_search_title].to_i)
|
||
end
|
||
if search.blank?
|
||
@courselist = @courselist
|
||
else
|
||
if "u_name" == keyword
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@courselist = @courselist.includes(:user).where("concat(users.lastname, users.firstname) like '%#{search}%'")
|
||
else
|
||
@courselist = @courselist.where("name like '%#{search}%'")
|
||
end
|
||
end
|
||
@courselist = @courselist.order("created_at #{@sx_order}")
|
||
@courselist_count = @courselist.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@courselist_pages = Paginator.new @courselist_count, limit, params['page'] || 1
|
||
@offset ||= @courselist_pages.offset
|
||
@courselist = paginateHelper @courselist, limit
|
||
|
||
# @courselist = @courselist.order("courselist.created_at #{@sx_order}")
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 支撑实训检索
|
||
def support_shixuns_search
|
||
if params[:shixun_id]
|
||
courselist = CourseList.find params[:shixun_id]
|
||
courselist.update_attributes(:support_shixuns_search => !courselist.support_shixuns_search)
|
||
end
|
||
end
|
||
|
||
# 课堂列表
|
||
def classroom_classment
|
||
@menu_type = 2
|
||
@sub_type = 2
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
@courses = Course.where(:is_delete => 0)
|
||
@timing=Course.where(:is_end=>false).count
|
||
@end=Course.where(:is_end=>true).count
|
||
@course_lists = CourseList.where(:id => Course.where(:is_delete => 0 ).map(&:course_list_id) )
|
||
unless params[:school_id] || params[:search] || params[:keyword] || params[:status]
|
||
user_exs=UserExtensions.where(:school_id=> @courses.map(&:school_id))
|
||
@schools = School.where(:id =>user_exs.map(&:school_id))
|
||
end
|
||
@search = params[:search] # 搜索字
|
||
@keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索
|
||
@status = params[:status]
|
||
@courselist = params[:course_list]
|
||
@school_id = params[:school_id]
|
||
|
||
if params[:school_id] && params[:school_id] != ''
|
||
@courses = Course.joins("join users u on courses.tea_id = u.id").joins("join user_extensions ue on u.id = ue.user_id").where("ue.school_id = #{params[:school_id]}")
|
||
end
|
||
|
||
if params[:homepage_show]
|
||
@courses = @courses.where(:homepage_show => params[:homepage_show].to_i)
|
||
end
|
||
|
||
if params[:course_list] && params[:course_list] != ''
|
||
@courses = @courses.where(:course_list_id => @courselist)
|
||
end
|
||
|
||
if params[:status] && params[:status]!=''
|
||
@courses =@courses.where(:is_end => @status.to_i)
|
||
end
|
||
if "u_name" == @keyword
|
||
if @search.blank?
|
||
@courses = @courses
|
||
else
|
||
user_id = User.where("concat(lastname, firstname) like '%#{@search}%'")
|
||
@courses = @courses.joins("join users u on courses.tea_id = u.id").where("concat(u.lastname, u.firstname) like '%#{@search}%'")
|
||
end
|
||
else
|
||
school = School.where("name like '%#{@search}%'").map(&:id)
|
||
@courses = @courses.where(:school_id => school)
|
||
# @courses= @courses.where("name like '%#{@search}%'")
|
||
end
|
||
@courses = @courses.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").reorder("updatetime #{@sx_order}")
|
||
@export_courses = @courses
|
||
@courses_count = @courses.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@courses_pages = Paginator.new @courses_count, limit, params['page'] || 1
|
||
@offset ||= @courses_pages.offset
|
||
@courses = paginateHelper @courses, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
format.xls{
|
||
@export_courses = @export_courses.all
|
||
filename = "#{l(:label_course_list_xls)}.xls"
|
||
send_data(course_list_xls(@export_courses), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||
}
|
||
end
|
||
end
|
||
|
||
# 班级首页显示
|
||
def course_homepage_show
|
||
if params[:course_id]
|
||
course = Course.find params[:course_id]
|
||
course.update_attributes(:homepage_show => !course.homepage_show)
|
||
end
|
||
end
|
||
|
||
# 课程实训
|
||
def class_shixuns
|
||
@menu_type = 4
|
||
@sub_type = 1
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
@edit_class_sx_num=Subject.where(:status => 0).count
|
||
@audit_class_sx_num=Subject.where(:status => 1).count
|
||
@publish_class_sx_num=Subject.where(:status => 2).count
|
||
search = params[:search] # 搜索字
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索
|
||
status = params[:status].to_i
|
||
if params[:school_id] && params[:school_id] != '0'
|
||
@c_shixuns = Subject.includes(:user => {:user_extensions => []}).where("user_extensions.school_id = #{params[:school_id]}")
|
||
else
|
||
@c_shixuns = Subject.where("0=0")
|
||
end
|
||
if params[:status] && params[:status]!=''
|
||
@c_shixuns= @c_shixuns.where(:status =>status)
|
||
end
|
||
if search.blank?
|
||
@c_shixuns = @c_shixuns
|
||
else
|
||
if "u_name" == keyword
|
||
# user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@c_shixuns = @c_shixuns.includes(:user).where("concat(users.lastname, users.firstname) like '%#{search}%'")
|
||
else
|
||
@c_shixuns= @c_shixuns.where("name like '%#{search}%'")
|
||
end
|
||
end
|
||
unless params[:school_id] || params[:search] || params[:keyword] || params[:status]
|
||
user_exs = UserExtensions.where(:user_id => @c_shixuns.map(&:user_id))
|
||
@schools = School.where(:id => user_exs.map(&:school_id))
|
||
end
|
||
@c_shixuns = @c_shixuns.order("created_at #{@sx_order}")
|
||
|
||
@c_shixuns_count = @c_shixuns.count
|
||
limit = 20
|
||
@c_shixuns_pages = Paginator.new @c_shixuns_count, limit, params['page'] || 1
|
||
@offset ||= @c_shixuns_pages.offset
|
||
@c_shixuns = paginateHelper @c_shixuns, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
def update_subject_hidden
|
||
@subject = Subject.find(params[:subject_id])
|
||
@subject.update_column(:hidden, !@subject.hidden)
|
||
end
|
||
|
||
# 已发布课程实训
|
||
def class_publish_shixuns
|
||
@menu_type = 4
|
||
@sub_type = 2
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
search = params[:search] # 搜索字
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索
|
||
if params[:school_id] && params[:school_id] != '0'
|
||
@c_shixuns = Subject.includes(:user => {:user_extensions => []}).where("subjects.status = 2 and user_extensions.school_id = #{params[:school_id]}")
|
||
else
|
||
@c_shixuns = Subject.where(:status => 2)
|
||
end
|
||
if search.blank?
|
||
elsif "u_name" == keyword
|
||
# 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@c_shixuns = @c_shixuns.includes(:user).where("concat(users.lastname, users.firstname) like '%#{search}%'")
|
||
else
|
||
@c_shixuns= @c_shixuns.where("name like '%#{search}%'")
|
||
end
|
||
unless params[:school_id] || params[:search] || params[:keyword]
|
||
user_exs = UserExtensions.where(:user_id => @c_shixuns.map(&:user_id))
|
||
@schools = School.where(:id => user_exs.map(&:school_id))
|
||
end
|
||
@c_shixuns = @c_shixuns.order("created_at #{@sx_order}")
|
||
@c_shixuns_count = @c_shixuns.count
|
||
limit = 20
|
||
@c_shixuns_pages = Paginator.new @c_shixuns_count, limit, params['page'] || 1
|
||
@offset ||= @c_shixuns_pages.offset
|
||
@c_shixuns = paginateHelper @c_shixuns, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 导出excel
|
||
def export_excel
|
||
@course = params[:course]
|
||
respond_to do |format|
|
||
format.xls {
|
||
@course = @course.reorder("#{Tracker.table_name}.position, #{Course.table_name}.id").all
|
||
filename = "#{l(:label_course_list_xls)}.xls"
|
||
send_data(course_list_xls(@course), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||
}
|
||
end
|
||
end
|
||
|
||
# 0 全部;1 活动的; 2 已注册; 3 锁定
|
||
def users
|
||
@menu_type = 7
|
||
@sub_type = 1
|
||
status = params[:user_status].nil? ? 0 : params[:user_status].to_i
|
||
@us_order = params[:us_order].blank? ? "desc" : params[:us_order] # 排序
|
||
@order_key = params[:order_key].blank? ? "last_login_on" : params[:order_key] # 排序关键字
|
||
condition = (params[:research_condition].nil? || params[:research_condition] == "name") ? "concat(lastname, firstname)" : params[:research_condition]
|
||
if 0 == status
|
||
if params[:research_condition] == "phone" && params[:research_contents].blank?
|
||
@users = User.order("#{@order_key} #{@us_order}")
|
||
else
|
||
@users = User.where("#{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}")
|
||
end
|
||
else
|
||
if params[:research_condition] == "phone" && params[:research_contents].blank?
|
||
@users = User.where(:status => status).order("#{@order_key} #{@us_order}")
|
||
else
|
||
@users = User.where("status = #{status} and #{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}")
|
||
end
|
||
end
|
||
|
||
if params[:school] && params[:school] != ''
|
||
school_name = params[:school]
|
||
school = School.where("name like '%#{school_name}%'")
|
||
school_id = school.map(&:id)
|
||
user_id = UserExtensions.where(:school_id => school_id).map(&:user_id)
|
||
@users = @users.where(:id => user_id).order("#{@order_key} #{@us_order}")
|
||
end
|
||
|
||
@users_count = @users.count
|
||
@limit = 20
|
||
@is_remote = true
|
||
@users_pages = Paginator.new @users_count, @limit, params['page'] || 1
|
||
@offset ||= @users_pages.offset
|
||
@users = paginateHelper @users, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
def shixuns
|
||
@menu_type = 3
|
||
@sub_type = 1
|
||
sx_status = params[:status].blank? ? [0, 1, 2, 3] : params[:status].to_i # 搜索实训的状态
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索
|
||
search = params[:search] # 搜索的字
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序
|
||
|
||
if "u_name" == keyword
|
||
# 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
|
||
if search.blank?
|
||
@shixuns = Shixun.where(:status => sx_status).order("created_at #{@sx_order}")
|
||
else
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@shixuns = Shixun.where(:user_id => user_id, :status => sx_status).order("created_at #{@sx_order}")
|
||
end
|
||
else
|
||
if params[:keyword] == "sx_name"
|
||
@shixuns = Shixun.where("name like '%#{search}%'").where(:status => sx_status).order("created_at #{@sx_order}")
|
||
else
|
||
school_id = School.where("name like '%#{search}%'").map(&:id)
|
||
user_id = UserExtensions.where(:school_id => school_id).map(&:user_id)
|
||
@shixuns = Shixun.where(:user_id => user_id).where(:status => sx_status).order("created_at #{@sx_order}")
|
||
end
|
||
end
|
||
@edit_sx_num = Shixun.where(:status => 0).count
|
||
@audit_sx_num = Shixun.where(:status => 1).count
|
||
@publish_sx_num =Shixun.where(:status => 2).count
|
||
@close_sx_num = Shixun.where(:status => 3).count
|
||
@shixuns_count = @shixuns.count
|
||
limit = 20
|
||
@shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1
|
||
@offset ||= @shixuns_pages.offset
|
||
@shixuns = paginateHelper @shixuns, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
def update_shixun_hidden
|
||
@shixun = Shixun.find(params[:shixun_id])
|
||
@shixun.update_column(:hidden, !@shixun.hidden)
|
||
end
|
||
|
||
# 已发布的实训
|
||
def publish_shixuns
|
||
@menu_type = 3
|
||
@sub_type = 2
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序
|
||
search = params[:search] # 搜索字
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索
|
||
close = params[:close] # 关闭实训,参数是实训的Id
|
||
unless close.blank?
|
||
Shixun.find(close).update_attribute(:status, 3)
|
||
end
|
||
if "u_name" == keyword
|
||
# 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
|
||
if search.blank?
|
||
@shixuns = Shixun.where(:status => 2).order("created_at #{@sx_order}")
|
||
else
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@shixuns = Shixun.where(:user_id => user_id, :status => 2).order("created_at #{@sx_order}")
|
||
end
|
||
else
|
||
@shixuns = Shixun.where("name like '%#{search}%'").where(:status => 2).order("created_at #{@sx_order}")
|
||
end
|
||
if params[:homepage_show]
|
||
@shixuns = @shixuns.where(:homepage_show => params[:homepage_show].to_i)
|
||
end
|
||
@shixuns_count = @shixuns.count
|
||
limit = 20
|
||
@shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1
|
||
@offset ||= @shixuns_pages.offset
|
||
@shixuns = paginateHelper @shixuns, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
# 实训首页显示
|
||
def shixun_homepage_show
|
||
if params[:shixun_id]
|
||
shixun = Shixun.find params[:shixun_id]
|
||
shixun.update_attributes(:homepage_show => !shixun.homepage_show)
|
||
end
|
||
end
|
||
|
||
# 允许复制
|
||
def shixun_can_copy
|
||
if params[:shixun_id]
|
||
shixun = Shixun.find params[:shixun_id]
|
||
shixun.update_attributes(:can_copy => !shixun.can_copy)
|
||
end
|
||
end
|
||
|
||
# 已关闭的实训
|
||
def close_shixuns
|
||
@menu_type = 3
|
||
@sub_type = 3
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序
|
||
search = params[:search] # 搜索字
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索
|
||
reopen = params[:reopen] # 从新开启实训,参数是实训的Id
|
||
unless reopen.blank?
|
||
Shixun.find(reopen).update_attribute(:status, 2)
|
||
end
|
||
if "u_name" == keyword
|
||
# 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
|
||
if search.blank?
|
||
@shixuns = Shixun.where(:status => 3).order("updated_at #{@sx_order}")
|
||
else
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@shixuns = Shixun.where(:user_id => user_id, :status => 3).order("updated_at #{@sx_order}")
|
||
end
|
||
else
|
||
@shixuns = Shixun.where("name like '%#{search}%'").where(:status => 3).order("updated_at #{@sx_order}")
|
||
end
|
||
@shixuns_count = @shixuns.count
|
||
limit = 20
|
||
@shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1
|
||
@offset ||= @shixuns_pages.offset
|
||
@shixuns = paginateHelper @shixuns, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
def users_trial
|
||
@menu_type = 7
|
||
@sub_type = 2
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
@users = User.where(:status => 1).order("last_login_on #{@sx_order}").all
|
||
@users_count = @users.count
|
||
@limit = 20
|
||
@is_remote = true
|
||
@users_pages = Paginator.new @users_count, @limit, params['page'] || 1
|
||
@offset ||= @users_pages.offset
|
||
@users = paginateHelper @users, @limit
|
||
end
|
||
|
||
# 自动授权列表
|
||
def auto_users_trial
|
||
@menu_type = 7
|
||
@sub_type = 3
|
||
@apply_action = School.where(:auto_users_trial => 1).order('updated_at desc')
|
||
@auto_school_ids = @apply_action.empty? ? "(-1)" : "(" + @apply_action.map(&:id).join(",") + ")"
|
||
@apply_action_count = @apply_action.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@apply_action_pages = Paginator.new @apply_action_count, limit, params['page'] || 1
|
||
@offset ||= @apply_action_pages.offset
|
||
@apply_action = paginateHelper @apply_action, limit
|
||
respond_to do |format|
|
||
format.html
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 添加
|
||
def create_auto_users_trial
|
||
School.where(:id => params[:school]).update_all(:auto_users_trial => 1)
|
||
redirect_to auto_users_trial_managements_path
|
||
end
|
||
|
||
# 删除
|
||
def update_auto_users_trial
|
||
School.where(:id => params[:school]).update_all(:auto_users_trial => 0)
|
||
redirect_to auto_users_trial_managements_path
|
||
end
|
||
|
||
def search_user
|
||
|
||
=begin
|
||
auth = ApplyUserAuthentication.where(:status => params[:authentication])
|
||
auth_id = auth.blank? ? User.where(:status => 1).id : "(" + auth.map{|a| a.user_id }.join(",") + ")"
|
||
=end
|
||
|
||
if params[:member_ids] && params[:trial_whether] == "trial_agree"
|
||
aUser = User.where(:id => params[:member_ids])
|
||
aUser.update_all(:certification => 1)
|
||
apply_user = ApplyAction.where(:user_id => params[:member_ids])
|
||
apply_user.update_all(:status => 1) unless apply_user.blank?
|
||
elsif params[:member_ids] && params[:trial_whether] == "trial_cancel"
|
||
User.where(:id => params[:member_ids]).update_all(:certification => 0)
|
||
apply_user = ApplyAction.where(:user_id => params[:member_ids])
|
||
apply_user.update_all(:status => 2) unless apply_user.blank?
|
||
end
|
||
|
||
if params[:member_ids] && params[:occupation] == "occupation_agree"
|
||
User.where(:id => params[:member_ids]).update_all(:professional_certification => true)
|
||
apply_user = ApplyUserAuthentication.where(:user_id => params[:member_ids], :auth_type => 2)
|
||
unless apply_user.blank?
|
||
apply_user.update_all(:status => 1)
|
||
end
|
||
elsif params[:member_ids] && params[:realname] == "realname_agree"
|
||
User.where(:id => params[:member_ids]).update_all(:authentication => true)
|
||
apply_user = ApplyUserAuthentication.where(:user_id => params[:member_ids], :auth_type => 1)
|
||
unless apply_user.blank?
|
||
apply_user.update_all(:status => 1)
|
||
end
|
||
elsif params[:member_ids] && params[:occupation] == "occupation_cancel"
|
||
User.where(:id => params[:member_ids]).update_all(:professional_certification => false)
|
||
apply_user = ApplyUserAuthentication.where(:user_id => params[:member_ids], :auth_type => 2)
|
||
unless apply_user.blank?
|
||
apply_user.update_all(:status => 2)
|
||
end
|
||
elsif params[:member_ids] && params[:realname] == "realname_cancel"
|
||
User.where(:id => params[:member_ids]).update_all(:authentication => false)
|
||
apply_user = ApplyUserAuthentication.where(:user_id => params[:member_ids], :auth_type => 1)
|
||
unless apply_user.blank?
|
||
apply_user.update_all(:status => 2)
|
||
end
|
||
end
|
||
|
||
if params[:trial] == "-1"
|
||
apply = ApplyAction.where(:container_type => "TrialAuthorization")
|
||
apply_id = apply.blank? ? -1 : "(" + apply.map{|a| a.user_id}.join(",") + ")"
|
||
apply_user_id = User.where("id not in #{apply_id} and status = 1 and certification = 0").all
|
||
apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0]
|
||
elsif params[:trial] == "-2"
|
||
apply_user_id = User.where(:status => 1).all
|
||
apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0]
|
||
elsif params[:trial] == "0"
|
||
apply = ApplyAction.where(:status => 0)
|
||
apply_user_id = apply.blank? ? [-1] : apply.map{|a| a.user_id}.split(",")[0]
|
||
else
|
||
apply_user_id = User.where(:status => 1, :certification => params[:trial]).all
|
||
apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0]
|
||
end
|
||
|
||
if params[:school] == ""
|
||
s_user_id = User.where(:status => 1).all
|
||
s_user_id = s_user_id.blank? ? [-1] : s_user_id.map{|s| s.id}.split(",")[0]
|
||
else
|
||
school = School.where("name like '%#{params[:school]}%'")
|
||
school_id = school.blank? ? -1 : school.map{|s| s.id }.split(",")[0]
|
||
usr = UserExtensions.where(:school_id => school_id)
|
||
s_user_id = usr.blank? ? [-1] : usr.map{|u| u.user_id}.split(",")[0]
|
||
end
|
||
|
||
if params[:department] == ""
|
||
d_user_id = User.where(:status => 1).all
|
||
d_user_id = d_user_id.blank? ? [-1] : d_user_id.map{|d| d.id}.split(",")[0]
|
||
else
|
||
department = Department.where("name like '%#{params[:department]}%'").all
|
||
dep_id = department.blank? ? -1 : department.map{|d| d.id}.split(",")
|
||
usr = UserExtensions.where(:department_id => dep_id)
|
||
d_user_id = usr.blank? ? [-1] : usr.map{|u| u.user_id}.split(",")[0]
|
||
end
|
||
|
||
user_id = s_user_id & d_user_id & apply_user_id
|
||
|
||
if params[:research_condition] == "name"
|
||
@users = User.where(:id => user_id).where("concat(lastname, firstname) like '%#{params[:research_contents]}%'").order("last_login_on desc")
|
||
elsif params[:research_condition] == "email"
|
||
@users = User.where(:id => user_id).where("mail like '%#{params[:research_contents]}%'").order("last_login_on desc")
|
||
elsif params[:research_condition] == "phone"
|
||
@users = User.where(:id => user_id).where("phone like '%#{params[:research_contents]}%'").order("last_login_on desc")
|
||
elsif params[:research_condition] == "nickname"
|
||
if params[:research_contents].blank?
|
||
@users = User.where(:id => user_id).order("last_login_on desc")
|
||
else
|
||
@users = User.where(:id => user_id).where("nickname like '%#{params[:research_contents]}%'").order("last_login_on desc")
|
||
end
|
||
end
|
||
|
||
@users_count = @users.count
|
||
@limit = 20
|
||
@is_remote = true
|
||
@users_pages = Paginator.new @users_count, @limit, params['page'] || 1
|
||
@offset ||= @users_pages.offset
|
||
@users = paginateHelper @users, @limit
|
||
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def update_webssh
|
||
webssh = params[:status] == "true" ? true : false
|
||
@shixuns = Shixun.find(params[:shixun_id])
|
||
@shixuns.update_column(:webssh, webssh)
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def affirm_cancel_auth
|
||
user_id = params[:users]
|
||
end
|
||
|
||
|
||
def trial_authorization
|
||
@menu_type =10
|
||
@sub_type = 2
|
||
search = params[:search]
|
||
@status = trial_authorization_status(params[:status])
|
||
# @status = (params[:status].blank? || params[:status] == "0") ? 0 : [1,2]
|
||
if search.blank?
|
||
@authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status).includes(:user)
|
||
else
|
||
user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'")
|
||
@authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status, :user_id => user_id).includes(:user)
|
||
end
|
||
|
||
@autu_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1
|
||
@offset ||= @autu_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
|
||
end
|
||
|
||
# 批量授权
|
||
def batch_authorization
|
||
|
||
end
|
||
|
||
# params[:type] 1:拒绝 0:同意
|
||
# authentication 会有一个初始值,不同的值代表不同的权限
|
||
# REDO: 后面权限改了后,一并要改
|
||
def trial_authorization_operation
|
||
apply_action = ApplyAction.find(params[:apply_id])
|
||
type = params[:type]
|
||
search = params[:search]
|
||
if type == "0"
|
||
authentication_user = AuthenticationsUsers.where(:user_id => apply_action.user_id).first
|
||
if authentication_user.blank?
|
||
AuthenticationsUsers.create(:user_id => apply_action.user_id, :authentication_id => 1)
|
||
end
|
||
end
|
||
apply_action.update_attributes(:status => (params[:type] == "1" ? 2 : 1), :reason => params[:reject_reason], :dealer_id => User.current.id)
|
||
User.where(:id => apply_action.user_id).first.update_attributes(:certification => (params[:type] == "1" ? 2 : 1))
|
||
user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'")
|
||
@authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => 0, :user_id => user_id).includes(:user)
|
||
@autu_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1
|
||
@offset ||= @autu_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def index
|
||
|
||
end
|
||
|
||
# copy from admin
|
||
def identity_authentication
|
||
@menu_type = 10
|
||
@sub_type = 1
|
||
@type = trial_authorization_status(params[:type])
|
||
type = params[:type] || 0 # 存在type 就用type 没有就为 0
|
||
user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:name]}%'")
|
||
|
||
# @unapproved_user = ApplyUserAuthentication.where(:status => @type, :user_id => user_id, :auth_type => 1).find_by_sql("SELECT s.*, TIMESTAMPDIFF(SECOND, s.updated_at, now()) diff FROM `apply_user_authentications` s order by diff asc")
|
||
@unapproved_user = ApplyUserAuthentication.where(:status => @type, :user_id => user_id, :auth_type => 1).order("updated_at desc")
|
||
|
||
@unapproved_user_count = @unapproved_user.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@unapproved_user_pages = Paginator.new @unapproved_user_count, @limit, params['page'] || 1
|
||
@offset ||= @unapproved_user_pages.offset
|
||
@unapproved_user = paginateHelper @unapproved_user, @limit
|
||
respond_to do |format|
|
||
format.html
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def professional_authentication
|
||
@menu_type = 10
|
||
@sub_type = 7
|
||
@type = trial_authorization_status(params[:type])
|
||
type = params[:type] || 0 # 存在type 就用type 没有就为 0
|
||
user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:name]}%'")
|
||
# @unapproved_user = ApplyUserAuthentication.where(:status => @type, :user_id => user_id, :auth_type => 2).find_by_sql("SELECT s.*, TIMESTAMPDIFF(SECOND, s.updated_at, now()) diff FROM `apply_user_authentications` s order by diff asc")
|
||
@unapproved_user = ApplyUserAuthentication.where(:status => @type, :user_id => user_id, :auth_type => 2).order("updated_at desc")
|
||
|
||
@unapproved_user_count = @unapproved_user.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@unapproved_user_pages = Paginator.new @unapproved_user_count, @limit, params['page'] || 1
|
||
@offset ||= @unapproved_user_pages.offset
|
||
@unapproved_user = paginateHelper @unapproved_user, @limit
|
||
respond_to do |format|
|
||
format.html
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 拒绝身份认证
|
||
# copy from admin
|
||
def reject_authentication
|
||
apply_user = ApplyUserAuthentication.where(:id => params[:apply_id], :auth_type => 1).first
|
||
reason = apply_user.update_attributes(:status => 2, :remarks => params[:reject_reason])
|
||
render :json => {success: reason}
|
||
end
|
||
|
||
# 同意身份认证
|
||
# copy from admin
|
||
def agree_authentication
|
||
apply_user = ApplyUserAuthentication.where(:id => params[:apply_id], :auth_type => 1).first
|
||
user = User.find(apply_user.user_id)
|
||
apply_user.update_attribute(:status, 1)
|
||
user.update_attribute(:authentication, true)
|
||
|
||
@unapproved_user = ApplyUserAuthentication.where(:status => 0, :auth_type => 1).order("updated_at desc")
|
||
@unapproved_user_count = @unapproved_user.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@unapproved_user_pages = Paginator.new @unapproved_user_count, @limit, params['page'] || 1
|
||
@offset ||= @unapproved_user_pages.offset
|
||
@unapproved_user = paginateHelper @unapproved_user, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 拒绝职业认证
|
||
def reject_authentication_pro
|
||
apply_user = ApplyUserAuthentication.where(:id => params[:apply_id], :auth_type => 2).first
|
||
reason = apply_user.update_attributes(:status => 2, :remarks => params[:reject_reason])
|
||
render :json => {success: reason}
|
||
|
||
end
|
||
|
||
# 同意职业认证
|
||
def agree_authentication_pro
|
||
apply_user = ApplyUserAuthentication.where(:id => params[:apply_id], :auth_type => 2).first
|
||
user = User.find(apply_user.user_id)
|
||
apply_user.update_attribute(:status, 1)
|
||
user.update_attribute(:professional_certification, true)
|
||
@unapproved_user = ApplyUserAuthentication.where(:status => 0, :auth_type => 2).order("updated_at desc")
|
||
@unapproved_user_count = @unapproved_user.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@unapproved_user_pages = Paginator.new @unapproved_user_count, @limit, params['page'] || 1
|
||
@offset ||= @unapproved_user_pages.offset
|
||
@unapproved_user = paginateHelper @unapproved_user, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def subject_authorization
|
||
@menu_type = 10
|
||
@sub_type = 6
|
||
@type = trial_authorization_status params[:type]
|
||
@authorizations = ApplyAction.where(:container_type => "ApplySubject", :status => @type).order("created_at desc")
|
||
# @subject=Subject.all
|
||
|
||
@authorizations_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1
|
||
@offset ||= @authorizations_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
def shixun_authorization
|
||
@menu_type = 10
|
||
@sub_type = 5
|
||
@type = trial_authorization_status params[:type]
|
||
# sql = select * from apply_actions where dealer_id is null
|
||
@authorizations = ApplyAction.where(:container_type => "ApplyShixun", :status => @type).order("created_at desc")
|
||
search = params[:search]
|
||
unless search.blank?
|
||
@authorizations = @authorizations.where(:container_id => Shixun.where(:id => @authorizations.map(&:container_id)).where("name like '%#{search}%'").map(&:id)).order("created_at desc")
|
||
end
|
||
|
||
@authorizations_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1
|
||
@offset ||= @authorizations_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 课程实训发布审批
|
||
def deal_subject_authorization
|
||
apply_action = ApplyAction.find(params[:apply_id])
|
||
type = params[:type].to_i
|
||
subject = Subject.find apply_action.container_id
|
||
if type == 0 #拒绝
|
||
subject.update_column('status', 0)
|
||
apply_action.update_attributes(:status => 2, :reason => params[:reject_reason], :dealer_id => User.current.id)
|
||
notes = "您所在团队提交的课程实训发布申请:<a href='#{subject_path(subject)}'>#{subject.name}</a>,审核未通过。<br/>原因:#{params[:reject_reason]}"
|
||
JournalsForMessage.create(:jour_id => subject.user_id, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0)
|
||
else #同意
|
||
subject.update_column('status', 2)
|
||
apply_action.update_attributes(:status => 1, :dealer_id => User.current.id)
|
||
end
|
||
@authorizations = ApplyAction.where(:container_type => "ApplySubject", :status => 0)
|
||
@authorizations_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1
|
||
@offset ||= @authorizations_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 项目实训发布审批
|
||
def deal_shixun_authorization
|
||
apply_action = ApplyAction.find(params[:apply_id])
|
||
type = params[:type].to_i
|
||
shixun = Shixun.find apply_action.container_id
|
||
if type == 0 #拒绝
|
||
shixun.update_column('status', 0)
|
||
apply_action.update_attributes(:status => 2, :reason => params[:reject_reason], :dealer_id => User.current.id)
|
||
notes = "您所在团队提交的项目实训发布申请:<a href='#{shixun_path(shixun)}'>#{shixun.name}</a>,审核未通过。<br/>原因:#{params[:reject_reason]}"
|
||
shixun.shixun_members.each do |member|
|
||
JournalsForMessage.create(:jour_id => member.user_id, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0)
|
||
end
|
||
else #同意
|
||
shixun.update_column('status', 2)
|
||
apply_action.update_attributes(:status => 1, :dealer_id => User.current.id)
|
||
add_shixun_modify_status shixun, 1
|
||
# 实训发布后则不允许修改代码
|
||
# g = Gitlab.client
|
||
# shixun.shixun_members.each do |member|
|
||
# gid = User.find(member.user_id).try(:gid)
|
||
# g.edit_team_member(shixun.gpid, gid, 10) # 3代表角色master
|
||
# end
|
||
# # 加入超级管理员
|
||
# admin_gid = User.where(:admin => 1).first.try(:gid)
|
||
# g.add_team_member(shixun.gpid, admin_gid, 40) # 30代表角色master
|
||
end
|
||
@authorizations = ApplyAction.where(:container_type => "ApplyShixun", :status => 0)
|
||
@authorizations_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1
|
||
@offset ||= @authorizations_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 课程删除
|
||
before_filter :find_courselist, :only => [:destroy]
|
||
|
||
# 课程列表的删除
|
||
def destroy
|
||
if @courselist
|
||
CourseList.where(:id => @courselist.id).destroy_all
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
end
|
||
private
|
||
# Find courselist of id params[:id]
|
||
def find_courselist
|
||
@courselist = CourseList.find_by_id(params[:id])
|
||
render_404 if @courselist.nil?
|
||
rescue ActiveRecord::RecordNotFound
|
||
render_404
|
||
end
|
||
|
||
def course_list_xls courses
|
||
xls_report = StringIO.new
|
||
book = Spreadsheet::Workbook.new
|
||
sheet1 = book.create_worksheet :name => "course"
|
||
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
||
sheet1.row(0).default_format = blue
|
||
sheet1.row(0).concat(["ID","课堂名称","成员","资源","普通作业"," 实训作业","试卷","私有","状态","创建者单位","创建者","动态时间"])
|
||
count_row = 1
|
||
courses.each do |course|
|
||
school = course.teacher.try(:user_extensions).try(:school).try(:name).blank? ? "--" : course.teacher.school_name
|
||
teacher_name = course.teacher ? course.teacher.show_real_name : ""
|
||
sheet1[count_row,0] = course.id
|
||
sheet1[count_row,1] = course.name
|
||
sheet1[count_row,2] = course.members.count
|
||
sheet1[count_row,3] = course.attachments.count
|
||
sheet1[count_row,4] = course.homework_commons.where(:homework_type => 1).count
|
||
sheet1[count_row,5] = course.homework_commons.where(:homework_type => 4).count
|
||
sheet1[count_row,6] = course.exercises.count
|
||
sheet1[count_row,7] = course.is_public.to_i == 1 ? '否' : '是'
|
||
sheet1[count_row,8] = course.is_end ? "已结束" : "正在进行"
|
||
sheet1[count_row,9] = school
|
||
sheet1[count_row,10] = teacher_name
|
||
sheet1[count_row,11] = format_time(course.updatetime)
|
||
count_row += 1
|
||
end
|
||
book.write xls_report
|
||
xls_report.string
|
||
end
|
||
end
|