module Admin::AnnouncementsHelper def page_for_bulletin(bulletin) ann_page = nil pages = Page.where(:module=>'announcement') pages.each do |page| if page.categories.count ==1 if page.categories.include?(bulletin.category.id.to_s) ann_page = page end end break if !ann_page.nil? end if ann_page.nil? pages.each do |page| if page.categories.include?(bulletin.category.id.to_s) ann_page = page end break if !ann_page.nil? end end if Page.where(:module=>'announcement',:url => "/announcement").count ==1 ann_page = '/announcement' else ann_page = pages.first.url if ann_page.nil? end request.protocol+(request.host_with_port+'/'+ann_page+'/'+'/'+bulletin.to_param).gsub('//','/') rescue "/" end def send_rejection_email(announcement) user = User.find(announcement.create_user_id) rescue nil if !user.nil? email = user.member_profile.email if !email.nil? && email != "" url = page_for_bulletin(announcement) mail = Email.new(:mail_to => email, :mail_subject => "Announcement rejected : #{announcement.title}.", :template => "email/rejection_email.html.erb", :template_data => {"url" => url, "rejector" => current_user.name, "name" => user.name, "reason" => announcement.rejection_reason}) mail.deliver end end end def send_notification_mail_to_managers(announcement, type) authorizations = Authorization.where(:module_app_id => @module_app.id) users = authorizations.collect do |auth| auth.user end users.each do |user| email = user.member_profile.email if !email.nil? && email != "" send_email(user.name, email, announcement, type) sleep(2) end end end def send_email(name, useremail, announcement, type) url = page_for_bulletin(announcement) template = (type == "approval" ? "email/new_announcement_email.html.erb" : "email/reapproval_announcement_email.html.erb") email = Email.new(:mail_to => useremail, :mail_subject => "New announcement : #{announcement.title}.", :template => template, :template_data => {"url" => url, "submitter" => current_user.name, "name" => name}) email.deliver end def load_access_level if current_user.is_admin? @access_level = "admin" elsif current_user.is_manager?(@module_app) @access_level = "manager" end end def user_can_approve? case @access_level when "admin" return true when "manager" return true else return false end end end