144 lines
3.6 KiB
Ruby
144 lines
3.6 KiB
Ruby
class MemberCounselorsController < CUserController
|
|
|
|
before_filter :is_user_authorized?, :only => ["show"]
|
|
|
|
def index
|
|
idx = 0
|
|
params = OrbitHelper.params
|
|
pcity = nil
|
|
page = Page.where(:page_id => params[:page_id]).first
|
|
cities = HpsCity.all.collect do |city|
|
|
total = city.hps_files.count
|
|
pcity = city if idx == 0
|
|
idx = idx + 1
|
|
{
|
|
"name" => city.name,
|
|
"total" => total,
|
|
"url" => "/" + I18n.locale.to_s + page.url + "?city_id=#{city.id.to_s}"
|
|
}
|
|
end
|
|
if params[:city_id].present?
|
|
pcity = HpsCity.find(params[:city_id])
|
|
end
|
|
total = 0
|
|
schools = pcity.hps_schools.collect do |school|
|
|
members = HpsMember.where(:hps_school_id => school.id.to_s).pluck(:id)
|
|
count = HpsFile.where(:hps_member_id.in => members).count
|
|
total = count + total
|
|
{
|
|
"name" => school.name,
|
|
"url_to_show" => OrbitHelper.url_to_show(school.to_param) + "?method=proposals",
|
|
"count" => count
|
|
}
|
|
end
|
|
{
|
|
"cities" => cities,
|
|
"schools" => schools,
|
|
"extras" => {"current_city_name" => pcity.name}
|
|
}
|
|
end
|
|
|
|
def proposals
|
|
params = OrbitHelper.params
|
|
school = HpsSchool.where(:uid => params[:uid]).first
|
|
members = HpsMember.where(:hps_school_id => school.id.to_s)
|
|
page = Page.where(:page_id => params[:page_id]).first
|
|
files = []
|
|
members.each do |member|
|
|
member.hps_files.desc(:created_at).each do |file|
|
|
files << {
|
|
"date" => file.created_at.strftime("%Y/%m/%d"),
|
|
"title" => file.title,
|
|
"download_count" => file.download_count,
|
|
"url" => "/cuser/download?file_id=#{file.id.to_s}"
|
|
}
|
|
end
|
|
end
|
|
{
|
|
"files" => files,
|
|
"data" => {
|
|
"back-url" => "/" + I18n.locale.to_s + page.url
|
|
}
|
|
}
|
|
end
|
|
|
|
def download
|
|
file_id = params[:file_id]
|
|
file = HpsFile.find(file_id) rescue nil
|
|
if !file.nil?
|
|
file.download_count = file.download_count + 1
|
|
file.save
|
|
redirect_to file.file.url and return
|
|
end
|
|
render :nothing => true
|
|
end
|
|
|
|
def login
|
|
if !current_counselor_user.nil?
|
|
redirect_to member_dash_path(current_counselor_user.account)
|
|
end
|
|
end
|
|
|
|
def logoutuser
|
|
destroy_cpanel_session
|
|
redirect_to member_login_path
|
|
end
|
|
|
|
def loginuser
|
|
user = HpsMember.where(:account => params[:username]).first rescue nil
|
|
if user.nil?
|
|
redirect_to member_login_path(:error=>"invld")
|
|
else
|
|
if user.enabled
|
|
if user.authenticate(params[:password])
|
|
create_cuser_session(user)
|
|
redirect_to member_dash_path(user.account)
|
|
else
|
|
redirect_to member_login_path(:error=>"invld")
|
|
end
|
|
else
|
|
redirect_to member_login_path(:error=>"dsbld")
|
|
end
|
|
end
|
|
end
|
|
|
|
def fileupload
|
|
@hpsfile = HpsFile.new
|
|
end
|
|
|
|
def editfileupload
|
|
@hpsfile = HpsFile.find(params[:id])
|
|
end
|
|
|
|
def file_upload
|
|
hpsfile = HpsFile.new(hps_file_params)
|
|
hpsfile.hps_member = current_counselor_user
|
|
city = HpsCity.find(current_counselor_user.hps_city_id)
|
|
hpsfile.hps_city = city
|
|
hpsfile.save
|
|
redirect_to member_dash_path(current_counselor_user.account)
|
|
end
|
|
|
|
def update_file_upload
|
|
hpsfile = HpsFile.find(params[:id])
|
|
hpsfile.update_attributes(hps_file_params)
|
|
redirect_to member_dash_path(current_counselor_user.account)
|
|
end
|
|
|
|
def deletefileupload
|
|
hpsfile = HpsFile.find(params[:id])
|
|
hpsfile.destroy
|
|
redirect_to member_dash_path(current_counselor_user.account)
|
|
end
|
|
|
|
def show
|
|
@files = current_counselor_user.hps_files
|
|
end
|
|
|
|
private
|
|
|
|
def hps_file_params
|
|
params.require(:hps_file).permit!
|
|
end
|
|
|
|
end |